title: Making sure FB pixel has tracked before redirecting?
body: <p>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).</p>
  
  <p>I currently have the FB pixel in the body, and then under it I do my redirect in Javascript after a 1 second timeout:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;!-- Facebook Pixel Code --&gt;
  &lt;script&gt;
  !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');
  &lt;/script&gt;
  &lt;noscript&gt;&lt;img height="1" width="1" style="display:none"
  src="https://www.facebook.com/tr?id=[pixel_id]&amp;ev=PageView&amp;noscript=1"
  /&gt;&lt;/noscript&gt;
  &lt;!-- End Facebook Pixel Code --&gt;
  &lt;script&gt;
  function sendOn () {
    window.location.replace("[redirect_url]");
  }
  setTimeout(sendOn, 1000);
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>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?</p>
  
  <p>Thanks for your help!</p>