Implementing Facebook Pixel | XM Community
Skip to main content
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:



<!-- 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', 'ID');

fbq('track', 'PageView');

</script>

<noscript><img height="1" width="1" style="display:none"

src="https://www.facebook.com/tr?id=ID&ev=PageView&noscript=1"

/></noscript>

<!-- End Facebook Pixel Code -->



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!
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');

```
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 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.
So, has anyone managed to implement Facebook Pixel in this way? I haven't seen yet any success stories.
Hi, yes we implemented the pixel using this way.



Under 'Look & Feel' open the Header section and go to the HTML editor.



I dropped the standard pixel code Facebook supplied and, according to the Pixel Helper extension for Chrome, it's all firing fine.

https://www.qualtrics.com/community/discussion/comment/18720#Comment_18720Hi Marty,
Is everything still working for you? I tried to drop the FB pixel into the header under look and feel and I get an error in the chrome extension:
"We detected event code but the pixel has not activated for this event, so no information was sent to Facebook. This could be due to an error in the code, but could also occur if the pixel fires on a dynamic event such as a button click."
has anyone else encountered this problem?


Problem has been solved and it is the classic case of curly braces:





you need to remove the curly braces around {your-pixel-id-goes-here} - so it should be just your id surrounded by quotes - and remember to do that in the script tag as well as the image url


Hi,
I have added the Facebook pixel code in the header section but still doesn't seem to be displaying. This is the code - any suggestions (I am not code-literate)?
Thank you





Hi,

We had no issue for a long time with implementing the pixel onto Qualtrics. As most people recommended, we put it into the "source" button in Look & Feel - Header.

The code does not show up as text, which is good new. And when we sign out and sign back in we are still able to find the code.

The issue now is that whenever we try to set up events and put in the website URL, we receive the message shown in the attached screenshot.
Screen Shot 2021-08-10 at 3.37.18 PM.pngThanks,

Dana


Hi,

Firstly, thank you to the contributors in this thread. Adding the code to the header works to link Facebook ads with Qualtrics, and Facebook is able to track visits to the first page. However, I also want to ensure that Facebook ads mostly appear to people who are more likely to complete the survey. Therefore, I tried to add a JavaScript code to the last page of the survey. It did not work; Facebook cannot find the pixel, as Dana reported above. How can we reconfigure Facebook ads better to detect a pixel aimed at understanding if a participant sees the last page of the survey? Research completion is the best measurement of conversion for the researchers.


Leave a Reply