I’m sending people to a blank landing page in order to make sure the lead is tracked by our Facebook pixel. I can’t do it on the main site as we do not have control of it (so can’t add the pixel there).
I currently have the FB pixel in the body, and then under it I do my redirect in Javascript after a 1 second timeout:
<html>
<body>
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', '[pixel_id]');
fbq('track', 'PageView');
fbq('track', 'Lead');
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=[pixel_id]&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
<script>
function sendOn () {
window.location.replace("[redirect_url]");
}
setTimeout(sendOn, 1000);
</script>
</body>
</html>
This seems to have missed some visits though. What’s the best way for me to make sure the pixel has fired before the redirect? Should I put the pixel tracking in the HEAD - is that enough? Or is there a better JS event I can use than just timeout?
Thanks for your help!