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.

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

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 objectif (a === "link" && b.local_event === false) {
returnfalse; // do not collect this event
}

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.

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

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.