Facebook Pixel

Hello,

I'm trying to add the Facebook Pixel to our Knack database as we will be running some FB Ads that lead to a Knack page. But every time I save the JavaScript code, the site goes down (none of the content loads, but there's no error message - just a blank page).

Does anyone know if there's a fix for this?

Normally I would use a proper landing page, but that's not an option in this case.

Thanks!

OMG, 369481659772 you are my new favourite person! I can't believe I didn't figure that out. Thank you soooo much for your help! It is GREATLY appreciated.

Its not loading because you are adding script tags in the javascript you just need to make some small changes to your facebook pixel code to make it work. Add the code like this https://www.knack.com/developer-documentation/#how-to-add-custom-code

Then modify your Facebook pixel code so it doesn't have the script tags and no script tags so remove all these elements from your facebook pixel code

<script>


</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=xxxxxxxxxxxxxxx&ev=PageView&noscript=1"
/></noscript>

You will be left with something like this:


<!-- Facebook Pixel Code -->

!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', 'XXXXXXXXXXXX');
fbq('track', 'PageView');

You are removing these tags because you are already inside of a <script> tag and <noscript> is not needed anymore.

-Tony

I'm still struggling with this, and I'm wondering if loading the JavaScript externally would solve the issue:

https://www.knack.com/developer-documentation/#code-from-outside-of-builder

I'm not all that great with JavaScript, so I'm not 100% sure I can make this work. Does anyone know if this would be worth pursuing? I'd hate to go down this path only to learn it was never even possible to begin with.

Thanks!