Installing Facebook Pixel

More
10 months 3 weeks ago #162846 by ViewBeyond
ViewBeyond created the topic: Installing Facebook Pixel
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?
Attachments:

Please Log in or Create an account to join the conversation.

More
10 months 2 weeks ago #162851 by tpartner
tpartner replied the 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:

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

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in or Create an account to join the conversation.

More
10 months 2 weeks ago #162858 by ViewBeyond
ViewBeyond replied the 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 following user(s) said Thank You: LouisGac

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!