Implementing Facebook Pixel | XM Community
Solved

Implementing Facebook Pixel

  • 23 March 2018
  • 9 replies
  • 558 views

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!
icon

Best answer by mattyb513 6 April 2018, 21:33

View original

9 replies

Userlevel 6
Badge +6
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!
Userlevel 6
Badge +6
> @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.
Badge
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

Leave a Reply