Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Existing Google Analytics events and Google Tag Manager

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?

like image 909
petriq Avatar asked Feb 27 '15 13:02

petriq


People also ask

Can Google Analytics and Google Tag Manager on same page?

Yes You Can… [Short answer]: Yes you can – just don't fire a Page View tag via Google Tag Manager.

How do Google Analytics and Google Tag Manager work together?

Google Analytics is the tracking tool, while Google Tag Manager is the mediator between your website and the tracking tool. In other words, Google Analytics collects, stores, and analyzes data. Google Tag Manager sends the data from your website to Google Analytics (or other tools) in the form of Tags.

Is Google Tag Manager separate from Google Analytics?

Google Tag Manager and Google Analytics are two completely separate tools, and can live independently of one another: You can use Google Analytics on your site by itself, just as much as you can use Google Tag Manager on your site by itself.


2 Answers

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 }); 
like image 193
Mert Can Ilis Avatar answered Sep 23 '22 22:09

Mert Can Ilis


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.

like image 34
Mouse Avatar answered Sep 19 '22 22:09

Mouse