jltitus
jltitus

Reputation: 21

Uncaught SyntaxError: Unexpected token < google-analytics google tag manager

I copied the following code right below the body tag for my site. However I get a "Uncaught SyntaxError: Unexpected token :" error. When I check in Firebug I get "SyntaxError: missing ; before statement" but I am not seeign where the error is. Any help is appreciated.

<!-- Google Tag Manager --> <noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-KDKSB8" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-KDKSB8');</script>
 <!-- End Google Tag Manager --> 

Upvotes: 2

Views: 5662

Answers (2)

Pete Mitchell
Pete Mitchell

Reputation: 1

Yep, as Joe says, it's to do with the curly braces that smarty templates use. I got around it by putting the google analytics code into a separate js file and just referenced that js file from the template.

Upvotes: 0

joeshmoe301
joeshmoe301

Reputation: 1418

I had this issue as well in a php / smarty template environment. The issue was that { and } are reserved characters with smarty templates and interprets them as indicators of php code. In case anyone comes across this response and is using smarty, place your code in {literal} and {/literal}.

This may not be your exact situation, but maybe your environment (sharepoint) is interpreting some of the javascript characters as reserved characters. There might be an escape character to solve your problem.

Upvotes: 1

Related Questions