Locating legacy hardcoded events and pageviews using Google Tag Manager

If you’re migrating from classic Google Analytics (_gaq object) to Universal Analytics, or planning to migrate your old hardcoded events to use Google Tag Manager you may have run in the case that not all old tracked was really removed from the site by the client. And it’s really hard to find it out.

We’ll learn today how to track this situation natively using just in-built Google Tag Manager features and allowing us to track all those all coded tracked within our Google Analytics data using events, so we can fix them and without the need of crawling your website.

We’re going to use Google Tag Manager CSS Selectors to find out those old tags and then firing an events to help us to easily view in GA where are those old codes hidden without needing to deep-crawl the sites and  helping us having a clean migration.

We’ll need to create a new variable in Google Tag Manager, as it’s shown in the screenshot below:

hardcoded_events_tracking_01

This variable will look for all onclick attributes available in the current page, containing  the “_gaq” string. If there’s any onclick containing a _gaq push, the whole value of the onclick attribute will be returned, if not the value for this variable will be “null”. Knowing this let’s configure our trigger that is going to be fired when there’s a match.

hardcoded_events_tracking_02

Now we only need to setup an Event to record the pages where the old hardcoded tracking is present.

We’ll record the current page path, along with the full push that was found.

hardcoded_events_tracking_03


Note: We’ll need to set the event Non-Interaction switch to true, to avoid messing the bounce rate. After this an event will be fired is any old _gaq push is found within all the onclick attributes in the current page.

hardcoded_events_tracking_04

Comments

2 responses to “Locating legacy hardcoded events and pageviews using Google Tag Manager”

  1. Shuki Mann Avatar
    Shuki Mann

    Cool hack David 🙂
    Thank you

  2. Nate Avatar
    Nate

    Any way to identify UA codes with this as well?

    Could I substitute out “_gaq” string with another string?

    Thanks,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.