New google analytics tracking code

New style tracking code

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'TRACKING_CODE']);
  _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>
Status: 
Active

Comments

Where the TRACKING_CODE is the Web Property ID

The code to use this new javascript has been written, and we plan to release a new version of the virtualmin-google-analytics plugin that will include it this week ..

Joe's picture
Submitted by Joe on Tue, 02/08/2011 - 16:00 Pro Licensee

Should be out tonight, actually, assuming my Internet keeps working reasonably well.

Hmm I'm not seeing the new tracking code after i did the upgrade

Hmm you stuck the code in a new place.... before the </head> tag... shouldn't be before the </body> tag ?

I just checked the page on analytics.google.com where they tell you the javascript to use, and it says :

Copy the following code, then paste it onto every page you want to track immediately before the closing </head> tag.

You are correct... they really changed the code.

Copy the following code, then paste it onto every page you want to track immediately before the closing </head> tag

I suspect it would work either way, as the script is executed regardless of where it is on the page.

Yes, it should work, but the script would be executed "late" and google analytics wouldn't be able to catch users etc that leave the site before the google code is executed (probably especially for slower site :-)

I think this was also the reason why google rewrote the script in the first place.

Automatically closed -- issue fixed for 2 weeks with no activity.

Code has changed again:

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', '$account']);
  _gaq.push(['_setDomainName', '.DOMAIN.COM']);
  _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);
  })();

If there was an addition so that we could change this on our own that would be the best fit, like setting custom httpd.conf entries in the templates file.

So they added

  _gaq.push(['_setDomainName', '.DOMAIN.COM']);

Also when you post code here you need to use the <code> tags

You can't use the http.conf to add java but maybe they can add a text box to edit the current analytics code.

Yes that is all they added, and sorry about the formatting

I don't understand why they need the domain string when it's already assigned when you add a new site. Seems to be a stupid thing to do.

Trust me, I am not understanding it either. Like I stated, if a text box could be added to allow for end users to change the code, that would be great.

I do plan to add an option to allow entering of arbitrary javascript in the next release of the analytics plugin..

I just looked at the code and I don't see this change... its still the original code. Where are you finding this new one at ? URL please.

When I check the settings to see what code to use for one of my sites I still see the new code I posted...

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXX-X']);
  _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);
  })();

I just posted this on another page. The code that Jamie wrote originally is correct, if you have a single site. The above I sent is for multiple subdomains. Below is the code if you have multiple top level domains:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', '$account']);
  _gaq.push(['_setDomainName', 'none']);
  _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>

Do you have a pointer to some documentation by Google on this?

My understanding was that the domain name could be worked out automatically, since the javascript is on the page that is served from your domain..

Umm if I am not mistaken the way the plugin works its using single domain tracking which is the default.

What you are posting is the custom tracking which isn't going to work in the state the plugin is coded.

Since we already have the domain to track custom tracking isn't going to work unless you edit the webpages themselves.

So the code has not changed and what you should be asking for is a feature request. I doubt that would be added as that becomes a very complex plugin using sub.domains....

Frankly its a moot point when google already determines the domain when you add the site.