Making Google Tag Manager Work Together with On-Page Tracking

/

blog-onpage-tracking

Transitioning to Google Tag Manager, but still have a lot of hard-coded tracking on your website? Many of our clients find themselves in this very situation.

Or you may have the opposite problem, where you’ve been tracking pageviews through code on your site, and now you want to add PDF tracking through GTM.

With the robust and customizable applications of GTM, it is clear why so many companies make the switch; but if your website already contains a large amount of hard-coded tracking, such as event tracking or custom dimensions/variables, recreating those new tags in GTM might take some time – leaving your website in a limbo of utilizing both GTM and on-page scripts.

This is okay, and for many, a necessary step in the process of completely transitioning to GTM. It is crucial, however, to understand the impact and functionality of GTM tracker names in order to continue to receive quality data during this period.

What Could Go Wrong

When you have only on-page tracking code, loading JavaScript on your page creates a Google Analytics object that is used by all of the tracking on the page. As you transition to GTM, whether you are adding pageviews or events, Tag Manager will add and use its own Google Analytics object.

By default, your on-site tracking and the tracking you set in GTM will not communicate with each other. This is because GTM automatically sets unique tracker names for its tags, which will not match the tracker name of your on-page analytics object.

Sometimes, this doesn’t cause any issues. But this CAN cause issues if your cookie domains don’t match, or you have other custom settings that you want to apply to all of your hits.

If you’re having issues where your events and pageviews are using different settings, you may end up creating multiple sessions/users. An easy way to check is to look for “(not set)” in your Landing Pages report or add this custom report.

This commonly happens when an event is fired at the start of a new sessions or broken session.

not set example

Different Tracker Names

Let’s take a look at how tracker names work. When Google Analytics is loaded, a tracker name is created by default. Usually this is blank for Classic or referred to as “t0” in Universal Analytics.

You can also manually specify a tracker name, which allows you to send data to more than one property from the same page.

You can customize each tracker with information about which GA property to use, turn on or off different options, and crucially, where to save your cookies.

An important note, Classic trackers and Universal trackers will never talk to each other, they are completely separate.

How Tracker Names Work in GTM

Each tag created in GTM is automatically assigned a unique tracker name that looks like “gtm1234567891234.” Tracker names are made up of a random set of numbers based on the current timestamp in order to prevent them from interfering with anything else on a given page.

Because each tag has its own configuration settings, it’s important to make sure these settings are consistent across pageviews, events, transactions, etc.

To see the tracker names on a given page, check out the Google Developers documentation for tracker objects or try pasting the following code in your JavaScript console:



The tracker names will appear in your console like this:

Universal #1: t0 – UA-12345-1
Universal #2: gtm1421841781746 – UA-12345-1

In this example, we found a Universal Analytics tracker with the default name and a Universal Analytics tracker with a default GTM name that are both sending data to the same property. This could pose a problem!

Working Together

If you need to get the GTM tracker names to play nice with hard-coded tracking, an update must be made within the GTM tags on your website. We need to tell GTM not to assign its own unique tracker names – and to essentially leave them unnamed or default to the on-page tracker name.

In your GTM pageview tag, navigate to More Settings > Advanced Configuration. Check the “Tracker Name” checkbox, but leave the field blank.

tracker name checked2

The following warning will appear:

Tracker Name: Allows you to name the tracker object yourself. Note: Naming the tracker object yourself is discouraged. If you inadvertently reuse an existing tracker object name, your data may become corrupted. Although providing a name for the tracker can allow you to share state between Google Tag Manager-created trackers and your pre-existing Google Analytics code, you should instead update the code on your site to use the Google Tag Manager dataLayer syntax. Otherwise you will be unable to configure your tracking via Google Tag Manager.

This warning essentially states that because you are using GTM, existing on-page tracking should also be set up entirely within GTM – but for now just ignore this.

Pros and Cons

Pros: This is a helpful, temporary solution for websites transitioning to GTM that still have hard-code tracking metrics on their website. It enables you to force GTM and on-page tracking metrics to work together nicely.

Cons: Just like before the switch to GTM, anyone on your team can add tracking metrics anywhere on the site, which can be dangerous to your data if set up improperly. For example, if someone sets up an interaction event that fires on an automatically scrolling gallery, that event would cause the bounce rate for that page to tank – even though no user interaction has taken place. Also, there are some third-party plugins that don’t respect named trackers. Just make sure you test everything!

The bottom line is, if using GTM, all on-page tracking should be transitioned into GTM as well. This is a handy temporary solution until that is complete. Remember, once you have completed the transition, the named tracker box can be unchecked on all your GTM tags, and team members will need to talk to your analytics expert to set up future events.

Amanda Schroeder is an Analytics Engineer and comes from the marketing industry where she found a need for accurate, insightful data that could aid in making results-driven decisions. Amanda’s passion for building solid measurement strategies and connecting all the pieces of integrated digital and traditional marketing campaigns has led her to her current role at LunaMetrics.

  • Brian

    Great article. Can you help clarify something – what if I have a large website on the same domain with multiple applications – could I migrate part to gtm on the same version of analytics and once all using gtm upgrade to universal ?

    • Amanda Schroeder

      Hi Brian,

      Yes, you can do that – you would just need to be careful not to use both Universal Analytics and Classic Analytics tracking at the same time if you are sending all of the data into the same Analytics property (so that your sessions do not break). If you have not yet updated to Universal Analytics, use Classic on-page tracking and Classic within GTM. Select the tracker name checkbox in your GTM tags and leave the field blank in case there is any kind of event tracking code still located on your pages that are using GTM. Also – make sure your cookie domain settings are set exactly the same in GTM as they are on the pages not using GTM. Hope that helps!

  • udi

    Hello,

    i am not sure i totally understand how a single page can show multiple GTM trackers. I tried the above and found three GTMs all reporting to the same property.

  • udi

    nevermind. i just re-read the post and realized that the issue is not having multiple trackers, but rather having multiple trackers with different names.

  • brian

    Thanks for the response below. Can you clarify the cookie piece? Thanks

    • Amanda Schroeder

      Brian,

      The cookie domain that is set within GTM should match the cookie domain set in the on-page tracking code. If the two are different, you risk causing your sessions to break because new cookies could be created for the same user as they navigate your website. So one person may appear as multiple users in your GA property.

  • brian

    One last very final question – you mention this is a temporary option (link tracker unchecked). What does that mean?? a day, week, month?

    • Amanda Schroeder

      There is no specific time frame for how long this solution should be used – it all depends on your organization. If you have a large website with a lot of on-page event tracking and custom dimensions, for example, and you want to transition to using GTM completely, it may take you longer to recreate each of those within GTM compared to someone with fewer on-page tracking elements.

  • Justin

    Hi Amanda,

    I am trying to run a GA content experiment on a site that uses GTM on all pages. I believe that it is not possible to run an experiment with only GTM container as hard-coded tracking is needed. In this case would you recommend running both and setting up a blocking tag in GTM, using the above method or temporarily replacing the GTM container with the hard-code version?

    Thank you!

  • http://twitter.com/tonyfelice tonyfelice

    Not sure this works anymore. I’ve got a situation where I absolutely have to fire an event with a custom html tag, and all I’m getting is “ga is not defined.” Well, it most certainly is somewhere, because analytics_debug.js is coughing up all kinds of “Running command: ga(…)” in the console. I’ve tried the console sniffer here, which returned “undefined.”

    The only objects in the DOM beginning with ga are “gaObject” and “gaplugins,” neither of which hint at what the tracker name might be, or where it might be hiding.

    • Amanda Schroeder

      Hi Tony,

      I’d guess there’s something interesting going on with your site. The analytics code sending GA hits threw the console could be loaded in an iframe, or something similar. Your pageview tracking should come before the event tracking, and you should know where that’s coming from. Is that on the page or being delivered through GTM?

      Feel free to share a website if you wish!

    • John

      I just tried this and it worked without issue. I removed the Google Analytics JS and added the Tag Manager code, enabled Named Tracker with a blank name and events show up in the Real-Time report on the correct Analytics property.

  • http://www.phil-duncan.com/ Phil Duncan

    This just worked a charm for us, many thanks for the post!

Contact Us.

LunaMetrics

24 S. 18th Street, Suite 100,
Pittsburgh, PA 15203

Follow Us

1.877.220.LUNA

1.412.381.5500

getinfo@lunametrics.com

Questions?
We'll get back to you
in ONE business day.