Google Analytics – Solution to Object Expected Error

Recently I went through some troubles trying to fix the new Google Analytics code placed into template of my phpbb forum.
Google Analytics javascript code was throwing an error in the bottom left hand corner of IE (yellow warning triangle) and in the details it gave me an error: Expected ‘}’.
Here is how I’ve fixed it:

I’ve replaced original Analytics code from Google:
<script type=”text/javascript”>
var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(“%3Cscript src='” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));
</script>
<script type=”text/javascript”>
try {
var pageTracker = _gat._getTracker(“UA-xx-x”);
pageTracker._trackPageview();
} catch(err) {}</script>

With this one:
<script type=”text/javascript”>
var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(“%3Cscript src='” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));
</script>
<script type=”text/javascript”>
var pageTracker = _gat._getTracker(“UA-xx-x”);
pageTracker._initData();
pageTracker._trackPageview();
</script>

Of course, if you’d do the samething, make sure ‘UA-xx-x’ in the code above is replaced by your own Google Analytics tracking number.
Anyways, this worked for me and it’s something to try if you’re having the same issues.

Facebook Comments