Search code examples
facebookzapierfacebook-pixel

How to send custom events to Facebook Pixel using Zapier


I would like to send custom event data into my Facebook pixel whenever a lead is processed through one of my zaps.

Since some of my leads come through messages there isn't a good way to track this information in the pixel.

I was hoping to use the code by Zapier tool to trigger the Facebook pixel script along with event tracking parameters. When I go to set this up though it doesn't work. Can you provide me any help on how I can get a zap to ping the FB pixel?

All I've tried so far is just pasting the pixel and event parameters into the code block. My expertise does not go beyond this lol. I have removed my pixel ID from the code below.

<!-- 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');
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=PIXEL&ev=PageView&noscript=1"
/></noscript>

<script> fbq('track', 'CompleteRegistration'); </script>


Solution

  • David here, from the Zapier Platform team.

    First off, just dropping that code block into a Code step won't work since it is html code (that runs JS in the browser window). Code steps are Node.js, which is mostly similar but different enough that this isn't going to work.

    You'll have less control, but I think what will work is doing a GET request (using a webhooks action) to https://www.facebook.com/tr?id=PIXEL&ev=PageView&noscript=1, which is what happens when javascript has been disabled. I'm not sure what exactly gets tracked, but it'll be better than nothing.

    That said, this seems like a great use case and it's probably worth writing into contact @ zapier . com to request this as a feature. It's likely others have also wanted this and/or there's a workaround I'm not aware of.