Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome / Google Analytics - ga.js:1 Uncaught SyntaxError: Unexpected token ILLEGAL

I looked at many similiar post here, but haven't found a solution for my problem. It's most likely something totally simple, but I just can't get it.

Problem I have sevaral domains and use one Account in Google Analytics to track them. THey have cross links (basically between different languages). When I try to click a link to another of my domains nothing happens (unless I view it on the Chrom consol). Other browser work fine...

Some code a) The snipplet provided by GA

<script type="text/javascript">
 var _gaq = _gaq || [];
 _gaq.push(['_setAccount', 'UA-XXXXXXX-1']);
 _gaq.push(['_setDomainName', 'site1.de']);
 _gaq.push(['_setAllowHash', false]);
 _gaq.push(['_setAllowLinker', true]);
 _gaq.push(['_trackPageview']);
 (function() {
   var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
   ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
   var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
 })();
</script>

b) Then in the BODY I have following link:

<A HREF="http://www.site2.com/" onclick="_gaq.push(['_link', 'http://www.site2.com/']); return false;">English</A>

As said, clicking on that link is fine in eg IE, FF. But in Chrome nothing seems to happen. If I open the console I see an error:

ga.js:1 Uncaught SyntaxError: Unexpected token ILLEGAL

I also see a lot of 'chinese chracters' in information window.

Now if I either activate the GA Debug or use the ga_debug.js the code works fine. I have tried to save the html file in different encodings (UTF-8, ANSI...) but that didn't do the trick.

Any ideas?

like image 320
Neil Avatar asked Nov 04 '22 14:11

Neil


1 Answers

Use ctrl + shift + n to open a tab in safe mode, then load your URL there to verify whether an extension is causing the issue. If the error disappears, this is the root cause. Otherwise, use a data URI to check whether it's a corrupted font issue:

data:text/html,Helvetica<br><font face="Helvetica" size="25">abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</font><br>
Helvetica Neue<br><font face="Helvetica Neue" size="25">abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</font>

Replace Helvetica Neue with the font-face used by the web page.

References

  • Fixing Google Analytics for Ghostery
like image 151
Paul Sweatte Avatar answered Nov 09 '22 06:11

Paul Sweatte