1

Hi,

Anyone been able to include Google Analytics Javascript code with BugMonkey?

I used to put the Google Analytics Javascript code in pageComposition.ASP in 6.0 and it worked fine but now I moved it to BugMonkey javascript section and it doesn't work at all. Perhaps cause it is not showing up where google expects it?

    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-12345678-1");
pageTracker._trackPageview();
} catch(err) {}
flag

2 Answers

1

Well, the

</script>
<script type="text/javascript">

certainly can't be a good thing.

Looking at the google analytics site, the way that they recommend including their tracker is like this:

  window._gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-12345678-2']);
  _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);
  })();

This should be more compatible with bugmonkey.

Update:

There was a change to BugMonkey, which wraps everything with a (function(){ ... })() to keep you from accidentally polluting the global namespace. However, the Google script expects that the _gaq variable to be in the global namespace.

To fix this, we changed:

var _gaq

to:

window._gaq

(As edited above)

link|flag
Thanks that worked! I had also missed the </script><script> inside the code. I only stripped the leading <script> and trailing </script> but never noticed there were some inside. Duh. – Sylvain May 18 2010 at 18:31
0

Javascript injected by a plugin is contained in a separate file which is pulled in via a <script type="text/javascript" src="js-file-url-here"> tag. Google requires that the <script> tag appears right at the end of the page before the </body> tag.

link|flag
Google wants you to paste the tracking code into the bottom of your content, immediately before the </body> tag. – Rob Sobers May 17 2010 at 18:55
thanks :) – adambox May 18 2010 at 14:47

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.