Implementing Facebook Pixel

kiezersonderzoekkiezersonderzoek Community Member Qubie ✭

Implementing Facebook Pixel

Dear all,

we are advertising a survey on Facebook and would therefore like to implement a Facebook Pixel in Qualtrics at a certain point.

The code provided by Facebook looks like this:

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


If we try to add it via "Add Javascript" we always get the following error message:

SiteWide.Alert

Invalid JavaScript! You cannot save until you fix all errors: Unexpected token <

What can we do to make this work?
Thank you!

Best Answer

  • mattyb513mattyb513 Washington DC Superuser ✭✭✭✭
    Accepted Answer

    If I were you I would take the initial function and drop it in the header between html script tags like so:

    <script>
    !function ....
    all the way until 
    fbq('init', 'ID');
    </script>
    

    I would then put the pageView tracker or any other custom conversions you want in the Add Javascript section, like so

    /* Add JavaScript Below This Line */
    fbq('track', 'PageView');
    

Answers

  • SfrazerSfrazer Community Member Qubie ✭

    Hi! I'm wondering if anyone has successfully embedded a pixel in this way. I've been trying (including variations on the suggestion above) and I'm still getting the sam error (Invalid JavaScript! You cannot save until you fix all errors: Unexpected token < ). I've been putting it in the first question on the survey, although facebook says to put it in a header, because when I try to put it in the header, the javascript shows up as though I had just typed in a header (so when someone takes the survey, they see the code!) I'm not a developer, we're just a small research company so I'm trying to troubleshoot this on my own. If anyone knows how to do this, I'd love to learn!

  • mattyb513mattyb513 Washington DCCommunity Member Superuser ✭✭✭✭

    @Sfrazer said:
    Hi! I'm wondering if anyone has successfully embedded a pixel in this way. I've been trying (including variations on the suggestion above) and I'm still getting the sam error (Invalid JavaScript! You cannot save until you fix all errors: Unexpected token < ). I've been putting it in the first question on the survey, although facebook says to put it in a header, because when I try to put it in the header, the javascript shows up as though I had just typed in a header (so when someone takes the survey, they see the code!) I'm not a developer, we're just a small research company so I'm trying to troubleshoot this on my own. If anyone knows how to do this, I'd love to learn!

    @Sfrazer

    You can't add HTML to the JavaScript editor, which is probably why you are getting that error.

    You can either remove the script tags <script> and </script> or add all that to the Header section of the Look and Feel.

  • StephanStephan SwitzerlandCommunity Member Qubie ✭

    So, has anyone managed to implement Facebook Pixel in this way? I haven't seen yet any success stories.

Sign In to Comment