0

I'm using this solution to count clicks (on e.g facebook, twitter, ect. iframes).

Basically what it does is keep track of what iFrame people are hovering. Then if the window blurs that most likely means the user clicked the iframe banner.

If I click on another element inside the iframe, after I already clicked one, it won't count. I need to click somwhere on the website and back on the iframe to get click counted.

(e.g I click on facebook button, facebook window pops up, my click is counted. I close pop-up window, click on twitter button, my click is not counted unless I click somewhere on the page and the twitter button again)

I need to set focus back to main window somehow.

    jQuery(document).ready(function() {
        var overiFrame = -1;
        jQuery('iframe#fb').hover(function() {
        overiFrame = jQuery(this).closest();
    }, function() {
        overiFrame = -1
    });
    jQuery(window).blur(function() {
        if(overiFrame != -1 ){
           //do something
    });
Community
  • 1
  • 1
  • What is the actual metric which you are trying to record in Google Analytics? Counting clicks on the iframe sounds a bit strange to me. Are you trying to work out who canceled a Facebook / Twitter share or something? – madebydavid Jan 15 '14 at 11:52
  • I want to track social engagement as an event in Google Analytics. I want to count clicks on facebook, twitter etc. inside iframe. The website iframes running on other domains. It is impossible to access information inside. This solution solves a part of the problem and I can count every click in the iframe (without knowing which button was clicked, at least that, but I want to make it a little bit better). – user3197255 Jan 15 '14 at 13:16
  • Are you using a Facebook like button or share button? The FB sdk provides events for when a like button is clicked (event is triggered in parent page by the like button iframe- https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/). Twitter's button also has events - https://dev.twitter.com/docs/intents/events – madebydavid Jan 15 '14 at 14:29
  • @madebydavid I would like to collect information with Google Analytics about any clicks on social sharing bar. Here is [sharebar example](http://www.recipe.com/revelatory-caramel-cake/) it differs between websites. Here we have facebook, pinit, google plus. It's tricky because of iframes runned on other domains as in this example. – user3197255 Jan 15 '14 at 22:17
  • I think I understand what you are doing - you should be able to call the Google Analytics _trackEvent function in the callback events for the FB like button or Twitter button. https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide – madebydavid Jan 15 '14 at 22:24
  • @madebydavid you are right. But I have access only to Google tag manager and have no rights to change content. I've changed code in my post to abstract from Google Analytics. – user3197255 Jan 16 '14 at 07:44

0 Answers0