- Posts: 7
- Thank you received: 2
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Installing Facebook Pixel
- ViewBeyond
- Topic Author
- Offline
- New Member
Less
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?
<!-- 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:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
6 years 2 months ago #162851
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
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:
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&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.
The topic has been locked.
- ViewBeyond
- Topic Author
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 2
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 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.