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:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion