Created
August 8, 2017 09:10
-
-
Save virusvn/73c47709b6c943eb497d8cb716701cdb to your computer and use it in GitHub Desktop.
Execute a function to track (Facebook & Line...) iFrame's click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
@Author: Nhan Nguyen | |
@Description: The library iframetracker is good, but because the script to generate iframe is asynchronous, | |
so we can't setup $(document).ready() work properly. | |
The solution is combined: | |
- Track by tagName is IFRAME for the first click | |
- Then, track by iframeTracker for nth times click | |
--> | |
<!-- https://github.com/vincepare/iframeTracker-jquery --> | |
<script src="/js/jquery.iframetracker.js"></script> | |
<script> | |
/* Start SNS Tracking */ | |
$(document).ready(function(){ | |
var fbTrackCode = '(share)something_to_identify_your_product_fb'; | |
var lineTrackCode = '(share)something_to_identify_your_product_line'; | |
//Traking first time click | |
var monitor = setInterval(function(){ | |
var elem = document.activeElement; | |
if(elem && elem.tagName == 'IFRAME'){ | |
//Iframe is Facebook | |
if(elem.src && elem.src.indexOf('facebook') !== -1){ | |
s.trackButton(this,fbTrackCode); // Change to your code | |
} | |
//Iframe is Line | |
else if(elem.src && elem.src.indexOf('line') !== -1){ | |
s.trackButton(this,lineTrackCode); // Change to your code | |
} | |
clearInterval(monitor); | |
//Line: Traking nth times click with iframeTracker solution | |
$('.line iframe').iframeTracker({ | |
blurCallback: function(){ | |
s.trackButton(this,lineTrackCode); // Change to your code | |
} | |
}); | |
//Facebook: Traking nth times click with iframeTracker solution | |
$('.facebook iframe').iframeTracker({ | |
blurCallback: function(){ | |
s.trackButton(this,fbTrackCode);// Change to your code | |
} | |
}); | |
} | |
}, 100); | |
}) | |
/* End SNS Tracking */ | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment