I want to use Facebook's pixel tracking to track exits from my site, not entrances to my site. I just want to hit it on the way out.
Their code looks like this:
<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src = '//connect.facebook.net/en_US/fbds.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(fbds, s);
_fbq.loaded = true;
}
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', 'MY_ID_NUMBER', {'value':'0.00','currency':'USD'}]);
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=MY_ID_NUMBER&cd[value]=0.00&cd[currency]=USD&noscript=1" /></noscript>
I want to do something like this:
<script type="text/javascript">
document.addEventListener('click', function(e) {
var tre = e.target.href || '';
if( tre.indexOf("link.php") > -1) {
[SOMETHING HERE THAT USES THEIR CODE]
}
}, false);
</script>
The problem is that I don't know what their code is doing so i don't know how to do this. Where should I start? Can I just append their image that they have in the "noscript" tag?
It appears you could move window._fbq.push
to inside your click
event.
document.addEventListener('click', function(e) {
var tre = e.target.href || '';
if( tre.indexOf("link.php") > -1) {
window._fbq.push(['track', 'MY_ID_NUMBER', {'value':'0.00','currency':'USD'}]);
}
}, false);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.