Summary: Talk page for GoogleAnalytics.
Maintainer: Petko
Users: (View? / Edit)

This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.


Thanks for the recipe. I guess this would be helpful to solve 00767. But sometimes the script needs to be inserted at the end, preferably.
To have the analytics code at the end of the page instead of the beginning, use $HTMLFooterFmt instead of $HTMLHeaderFmt. -- Pm
Trouble is you need a way to automatically make external links (and links to attachments) include a short javascript function call, with a meaningful name. If such a link is present, then the code above goes in the body (anywhere before the link)... if not then it must go in the header. The individual link code can probably go into $UrlLinkFmt or $IMapLinkFmt's, but I have no idea how to turn the link title/url into a useful name or how to move the code from header to body automatically if such a link is present. Here's an example of an outbound link, from Googles help system:
<a href="" onClick="javascript:urchinTracker('/outgoing/example_com');">
-- pjv
See this post on the mailing list. --Petko February 18, 2008, at 05:59 PM
Since D├ęcember 2007, the code has changed, some quotes must be escaped
$HTMLFooterFmt['google'] = '<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src=\'" + gaJsHost + "\' type=\'text/javascript\'%3E%3C/script%3E"));
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-CODE-1");
-- Thomas

As of August, 2010, there is at least one other (or only one, as of now?) format:

$HTMLFooterFmt['google'] = '<script type="text/javascript">

 var _gaq = _gaq || [];
 _gaq.push(["_setAccount", "UA-CODE-1"]);

 (function() {
   var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true;
   ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + "";
   var s = document.getElementsByTagName("script")[0];
   s.parentNode.insertBefore(ga, s);

OtherMichael August 05, 2010, at 08:48 PM

Talk page for the GoogleAnalytics recipe (users?).