Highlighted

How to activate multiple Google analytics accounts on the same page?

I want to activate 2 Google analytics accounts on the same page that will handle 2 different groups of events. The 2 accounts should be activated on page load thus they should have exactly the same pageviews BUT each one should track a group of events that the other account should ignore.
3 REPLIES 3
Highlighted

How to activate multiple Google analytics accounts on the same page?

Employee Emeritus

This is easy to do in Tealium. You just need to create 2 instances of the Google Analytics tag.

Apart from the account id, where you enter your UA-1234-1 account number, there are two other important settings. First, make sure that in the "script source" setting, you choose Google (external). This prevents you loading the whole library twice.

Secondly, give each of the trackers a distinct name. For example if you have an account for the site and a roll-up account to collect data from multiple sites, you could call them "global" and "local".

The two trackers will now collect the same page view data.

If you want to collect different event data, there are two ways that you can achieve this, but they both involve using a custom JavaScript code extension. One method is to create an extension scoped to the tag instance which checks for relevant events and returns false if it's not going to record the data. You can insert your own condition here:

// a is event type, "link" is an event
// b is the data object
if (a === "link" && b.local_event === false) {
  return false; // do not collect this event
}

The other alternative is to create the events explicitly in GA style:

jQuery("button#add-to-basket").on("click", function () {
  ga("local.send", "event", "add-to-cart", "clicked");
});

In the second example, the prefix before the send is the name of the tracker.

Highlighted

How to activate multiple Google analytics accounts on the same page?

Employee Emeritus

Hi Alicia,

Thanks for reaching out. Sure - this is easy. You need to use a different tracker name for each account which you can configure in the tag (or map it if you like):

http://note.io/1rn9oYC

You can give them any name you want (within reason! e.g. 'a' and 'b' perhaps) and they'll fire data to each tracker differently.

If you then wanted an event to fire for one GA tag but not another then you could write a 'javascript' extension which would stop the tag from firing based on conditions.

For example, let's say that you set the following 'event_action', 'event_category' and 'event_label' data sources which are mapped to both tags:

event_action = 'facebook like'
event_category = 'social'
event_label = 'facebook'

Let's now say that we only want this event to fire in tag A and not tag B - we can create the following javascript extension which will stop tag B from firing when this event gets triggered:

extension : http://note.io/ZCGc9A
code : http://jsfiddle.net/tuy0eme4/

When a user performs the action you want tracking in GA A only (not GA B), although both tags will be called this code will kill the call in tag B when Tealium hits it (you must scope this extension to tag B for this to work).

I hope this makes sense. Feel free to reach out to your local account manager if you need a hand with this.

Highlighted

How to activate multiple Google analytics accounts on the same page?

Employee Emeritus
Another idea to use instead of manual JS is to create a different set of mappings for each Google Analytics tag. Let's say you have 'global' and 'local' as in Fiann's example. You could have one set of mappings that use global_event_action and global_event_category, and the other that use local_event_action and local_event_category. That each one will only respond to one set of event mappings.