Existing Google Analytics events and Google Tag Manager
Asked Answered
S

4

30

I have implemented Google Analytics (GA) on my site and I send several custom events through ga("send", "event", ...); function and it works well.

I am experimenting with Google Tag Manager (GTM). I have removed original GA snippet, and now I use GTM to inject GA tag on my site and pageviews are tracked correctly. What does not work well are my custom events sent by ga() function.

I have noticed that GA create has tracker name variable like

ga("create", "UA-12345678-1", {name: "gtm0123456789", allowLinker: false});

and Google Analytics Debugger extension for Google Chrome reports Command ignored. Unknown target: undefined.

I found out that send event call should include tracker name so it should look like ga("gtm0123456789.send", "event", ...);, but I don't want to change all my existing GA send event calls.

I quickfixed it by setting tracker name to empty string in GTM settings (Edit Tag -> More Settings -> Advanced Configuration -> ☑ Tracker Name, leaving the textbox blank) and now it works, but I do not think it is such great solution.

Is there any other options to have my existing GA send event calls and using also event tracking through GTM?

Silver answered 27/2, 2015 at 13:3 Comment(2)
You can leave the GA snippet in but make sure you are not duplicating any hits like pageviews or other events.Galluses
had this same issue, setting a blank Tracker name in Tag Manager felt ridiculous, but it worked like a charm.Folger
B
3

There is a way - you can rename the ga function in the tag manager (advanced configuration, global function name), e.g. to "real_ga" . Then you create a custom ga function in your own page that takes the parameters from your event tracking calls and passes them to the real_ga-function (so you need to change the tracker name only in one place), or better pushes them to the dataLayer (and then you can use the dataLayer values for event tracking in GTM).

But why would you want to do that ? You do not actually have a problem, your simply feel bad about your workaround. The proper answer to this is, as long as it works don't feel bad.

Bookbinder answered 2/3, 2015 at 13:25 Comment(0)
M
61

I had the similar configuration (Universal Analytics tag in Google Tag Manager) and I wanted to fire events from button on click.

I used petriq's comments to solve my problem and therefore want to add my notes.

Universal Analytics default event code is in this format:

ga("send", "event", ...);

You can fire Universal Analytics events from your code with the tracker name:

ga("gtmXXXXXXXXXX.send", "event", ...);

However the tracker name changes in every gtm load so I changed the code like this:

var trackerName = ga.getAll()[0].get('name');
ga(trackerName + '.send', 'event', { eventCategory: 'category1', eventAction: 'action1', eventValue: 0 });
Muscolo answered 3/4, 2015 at 14:55 Comment(7)
This is a great solution especially for the following scenario: You had a working GA account that was updated to use Google Tag Manager, especially in a single page app where it is difficult to attach id's to things other than buttons and links.Depopulate
how will you ensure that 0th index tracker has 'name' field set. What if, its not then it will give an error.Bertabertasi
@Bertabertasi ga contains at least one trackerMuscolo
i agree... here getAll() will return the array of tracker.. now you're finding the name field of first tracker.. what if this tracker has no name set..Bertabertasi
Also getAll() will process complete DOM to collect all tracker.. this might be not good way to send tracker.. so what i did was to send it through dataLayer to GTM.Bertabertasi
What is Normal Universal Analytics vs Universal Analytics?Hexameter
@Hexameter It was a typo, I've changed it to "default".Muscolo
P
4

http://www.lunametrics.com/blog/2015/01/21/gtm-existing-tracking/

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

Polyadelphous answered 22/4, 2015 at 17:29 Comment(1)
Please put some explanation to understand your answerFleabane
B
3

There is a way - you can rename the ga function in the tag manager (advanced configuration, global function name), e.g. to "real_ga" . Then you create a custom ga function in your own page that takes the parameters from your event tracking calls and passes them to the real_ga-function (so you need to change the tracker name only in one place), or better pushes them to the dataLayer (and then you can use the dataLayer values for event tracking in GTM).

But why would you want to do that ? You do not actually have a problem, your simply feel bad about your workaround. The proper answer to this is, as long as it works don't feel bad.

Bookbinder answered 2/3, 2015 at 13:25 Comment(0)
M
-3

Best way is to implement all tracking using GTM. It'll give you more control over your tracking codes and more flexibility in deployment of new tags.

Municipalize answered 28/2, 2015 at 19:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.