Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Installing Facebook Pixel

  • ViewBeyond
  • ViewBeyond's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 2 months ago #162846 by ViewBeyond
Installing Facebook Pixel was created by ViewBeyond
Hi. I'm trying to insert my Facebook Pixel in the head of a survey page. Here is the code:

<!-- 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',
' connect.facebook.net/en_US/fbevents.js ');
fbq('init', 'ACCOUNT NUMBER');
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none"
src=" www.facebook.com/tr?id=ACCOUNT NUMBER&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->

I insert this, as with non-LimeSurvey pages, just before the </head> tag.

However, this throws a javascript error every time: "Uncaught SyntaxError: Unexpected token <"

But, from the source code, it looks like LimeSurvey is trying to render the "if" function in the code rather than process it (see attached)

I did try inserting the script via template.js as well - same error.

Any ideas?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 2 months ago #162851 by tpartner
Replied by tpartner on topic Installing Facebook Pixel
When inserting JavaScript, you need to leave a space or line-break after every opening curly brace and before every closing curly brace - manual.limesurvey.org/Workarounds:_Manip...of_usage_of_brackets

Try this:

Code:
<!-- 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',
' connect.facebook.net/en_US/fbevents.js ');
fbq('init', 'ACCOUNT NUMBER');
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none"
src=" www.facebook.com/tr?id=ACCOUNT NUMBER&amp;ev=PageView&amp;noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • ViewBeyond
  • ViewBeyond's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 2 months ago #162858 by ViewBeyond
Replied by ViewBeyond on topic Installing Facebook Pixel
Worked like a charm.

The codes is as copied pasted direct from Facebook, so hopefully this thread will help others running into the issue.

Thanks so much Tony!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose