Google Analytics module provides an advanced textarea on the settings page for including additional JavaScript to every page.
The official documentation about Google Analytics Tracking Code should be read first to understand how Google tracking works in general. On the Google Analytics Tracking API page you will find all available methods that can be used in this textarea. Also, you'll find JavaScript snippets dotted around in the Google Analytics Help Center.
6.x-3.x and 7.x-1.x
Don't forget to prefix all used methods in the latest (asynchronous) version with _gaq.
. See Upgrading from 2.x to 3.x of Google Analytics module for the differences between the tracker customizations. Google's Asynchronous Migration Examples page has more details.
5.x-1.x and 6.x-2.x
Don't forget to prefix all used methods in the traditional (ga.js) version with pageTracker.
Add your Google Analytics advanced JavaScript snippets as comments to this page.
Comments
Tracking across multiple subdomains
GA allows for tracking across multiple subdomains using a single line of script.
pageTracker._setDomainName("example.com");
See Further information for details.
--
Ixis (UK): Drupal support, Drupal hosting.
no, it's
no, it's this:
you missed the first period before the domain name.
Identify additional search engines in the Referral reports
By default, Google Analytics tracks referrals from a growing list of search engines. You can also configure Analytics to identify referrals from additional search engines by adding the following line to your tracking code:
pageTracker._addOrganic("name_of_searchengine","q_var");
See here for more information.
Trick for getting the real bounce rate
setTimeout('_gaq.push([\'_trackEvent\', \'NoBounce\', \'Over 10 seconds\'])',10000);
http://padicode.com/blog/analytics/the-real-bounce-rate/
Tracking Page Load Times
The new version of Google Analytics allows you to track page load times, but it's disabled by default. To enable it, add this snippet in the 'after' code box in the Google Analytics module's settings page:
Tracking external links as goals
Currently I have the Google Analytics Drupal module set to record outbound links as events. For goal tracking, I'd like to record just a small handful of outbound links as fake goal URLs. For example, a user clicks on a link to example.com/join and I want to record it as a page hit to mysite.com/goals/join.
The easiest solution, if you can use a text input mode like PHP and make use of the onClick link attribute, is to write:
However, I also wanted this to work for users who a) aren't familiar with JavaScript and b) can't use the onClick attribute. So I have them write:
and in my theme's .info file I say:
and finally in the script.js file, I have some jQuery which sets the onClick behavior using the data-ga-page attribute as the page name variable:
Note the javascript examples are using the Google Analytics asynchronous syntax. For the older syntax, check out this similar code:
http://sealedabstract.com/code/tracking-an-outbound-link-as-a-goal-with-...