Last active
March 30, 2017 00:49
-
-
Save acoyfellow/ed8d4bb18e57c0542792 to your computer and use it in GitHub Desktop.
How to fire a Facebook Custom Audience pixel after 30 seconds with Javascript
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
/* | |
****** A normal Facebook retargeting pixel 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; | |
} | |
_fbq.push(['addPixelId', '****']); | |
})(); | |
window._fbq = window._fbq || []; | |
window._fbq.push(['track', 'PixelInitialized', {}]); | |
</script> | |
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?id=****&ev=PixelInitialized" /></noscript> | |
__________________________________________________________________________ | |
__________________________________________________________________________ | |
****** To make it fire after 30 seconds, use this code instead: | |
__________________________________________________________________________ | |
__________________________________________________________________________ | |
<script> | |
setTimeout(function(){ // The setTimeout javascript function will help you fire the JS code after a set amount of time | |
(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; | |
} | |
_fbq.push(['addPixelId', '****']); | |
})(); | |
window._fbq = window._fbq || []; | |
window._fbq.push(['track', 'PixelInitialized', {}]); | |
}, 30000); // 30000 = 30 seconds | |
</script> | |
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?id=****&ev=PixelInitialized" /></noscript> | |
__________________________________________________________________________ | |
__________________________________________________________________________ | |
Be sure to replace "****" with your ID | |
** Need help? Contact fb.com/coeyman || [email protected] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment