Advertising sustains the DA. Ads are hidden for members. Join today

Third-party Integration Modules

Upgrading from 2.x to 3.x of Google Analytics module

Last updated on
30 April 2025

If you upgrade from the 2.x to the 3.x version of the Google Analytics module, and you use custom Javascript, you will have to manually upgrade it.

Google's documentation shows the overall migration steps, and how the ._gaq object, used in the asynchronous code, works.

Here's an example of how to change the "after" code if you want to track a second account:

// Traditional (ga.js) Snippet, 2.x
var secondTracker = _gat._getTracker("UA-XXXXX-X");
secondTracker._trackPageview();

// Async Snippet, 3.x
_gaq.push(['b._setAccount', 'UA-XXXXX-X']);
_gaq.push(['b._trackPageview']);

Here's an example of the new event tracking code, which you would add either in page markup or via hook_form_alter by setting the onclick attribute of a link or button:

<a href="#" onClick="_gaq.push(['_trackEvent', 'Videos', 'Play', 'Baby\'s First Birthday']);">Play</a>

Help improve this page

Page status: Not set

You can: