Google Analytics can take around 24-48 hours to display its first lot of statistics about your site, so do not be alarmed that you don't see anything for a while.

Theme compatibility (7.x)

If you're not seeing the JavaScript code appearing in the top/bottom of your sites HTML please ensure your theme includes the standard PHP code:

<?php print $page_bottom; ?>

at the bottom of your html.tpl.php. If your theme does not have this file, a core html.tpl.php is used and this one has this variable.

Theme compatibility (5.x, 6.x)

If you're not seeing the JavaScript code appearing in the bottom of your site's HTML, please ensure your theme includes the standard PHP code:

<?php print $closure; ?>

at the bottom of your page.tpl.php (see Garland's page.tpl.php for an example placement).

Privacy - tracking opt-out

If you're not seeing the JavaScript code appearing in the source code of your page, it might be due to privacy/opt-out options.

To test, do one of these things:

After doing one of these things, reload the page. You should now see the tracking code in the source of your page.

Once you've confirmed that the tracking code is loading, remember to undo your temporary change - restore your browser's opt-out settings or re-enable Universal web tracking opt-out on the module's configuration page.

Validation Errors

If Google Analytics reports "Tracking not installed", and you have already followed the advice above and cleared your cache, try setting the Javascript scope to "Footer" in the Advanced Settings section of the googleanalytics module's admin settings page. Do not do this unless you are having problems, as the documented location for the Javascript is "Header", not "Footer". This is an issue with the Google Analytics validator; see #1788586: Google analytics Javascript is not always added at the very end of the head section.

If stats not showing after a module upgrade

If the tracking code is not working properly after a version upgrade, you may need to clear all caches again, just as a precaution.

If you are using custom code, and you have just switched to the asynchronous JS (i.e., have upgraded to a 6.x-3.x version from a 6.x-2.x), you will need to manually rewrite the code that you were adding in the "after" section. See the 6.x-2.x->6.x-3.x upgrade guide for more details.

Debugging tracker responses using ga_debug.js

Google provides a Chrome extension for debugging Google Analytics called ga_debug.js. It is helpful in debugging, since it will show what is being sent to Google in Chrome's Javascript console.

Note that, according to #921308-14: Document that module using asynchronous javascript but not able to correctly load code in header, the ga_debug.js may report that the asynchronous snippet is not being used, even if local caching of ga.js is disabled in admin/settings/googleanalytics.

Validation in Google Webmaster Tools

According to #921308-20: Document that module using asynchronous javascript but not able to correctly load code in header, Google Webmaster Tools validation of website ownership may fail if you try the Google Analytics method. This is because hook_footer(), which this module uses to add the Analytics Javascript cannot be used to add the Analytics code to the header, where Google expects it to be.

This should not affect site ownership validation in Google Analytics itself, however.

Ubercart Compatibility

Note that the 6.x-3.x (asynchronous) branch of the Google Analytics module is only compatible with Ubercart 6.x-2.5 or later. If you do not wish to run a dev version of Ubercart, you can patch the Ubercart Google Analytics module with the patch from #922230-16: Asynchronous tracking for Google Analytics.

Staying on the 6.x-2.x branch of Google Analytics is not recommended since Google has deprecated various parts of the non-asynchronous tracking API.

Comments

Jim Bacon’s picture

Google Analytics 6.x-4.0 creates JavaScript for insertion in a preprocess function which works if you are using a templated theme but not with one like the core theme, Chameleon.

My workaround was to add the following at the very start of the function chameleon_page() in the chameleon.theme file. I also copied the entire theme to sites/all/themes to prevent the change being overwritten by core updates.

  $dummy = null;
  googleanalytics_add_js($dummy, $dummy);

There may well be better ways to solve this problem.

I also observe that Google Analytics 6.x-4.0 inserts JavaScript in to the head, not the foot, of the page so I wonder if the print $closure tip is out of date.

littleneo’s picture

(drupal 6)
googleanalytics.js wont be loaded if the cache is disabled.. (3 hours wasted)

mralexho’s picture

Added to documentation

sp_key’s picture

The only php file my theme has, is the template.php.
Is this where we're expecting to find the print $page_bottom; code?

Can you please kindly provide more information?

Cheers