Analytics
1.8K members online now
1.8K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Multiple Analytics code with grouping. How?

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I wan to use multiple analytics codes, 2 codes, with one of them using grouping feature.

 

For example I want to group men's clothing vs women's clothing by putting different code between two of them. Group name is clothing.

 

For men's clothing url the code will be

 

 

ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');


ga('create', 'UA-XXXXX-Z', 'auto', 'NewTracker');
ga('NewTracker.set', 'Men', 'Clothing');
ga('NewTracker.send', 'pageview');

 

 

And for women's clothing the url will be

 

ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');


ga('create', 'UA-XXXXX-Z', 'auto', 'NewTracker');
ga('NewTracker.set', 'Women', 'Clothing');
ga('NewTracker.send', 'pageview');

Am I doing it right? Will this work? Thanks!

1 Expert replyverified_user

Re: Multiple Analytics code with grouping. How?

Top Contributor
# 2
Top Contributor

Hi Abdul, you seem to be taking the (very) hard (and incorrect) route here.


Unless you have specific reporting requirements, you might be better off using custom dimensions:

ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview',{
'dimension1': 'Mens', // top category,
'dimension2': 'Clothing' // sub-category
});


Alternatively you can use content grouping

ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview',{
'contentGroup1': 'Mens - Clothing'
});

 

Either way you'll need to adjust your reporting to view a hierarchical view of your content.

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

Re: Multiple Analytics code with grouping. How?

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Interesting. I just checked about custom dimensions, both of them can serve my purpose. But now I will try to use content grouping first as I already learned some about it.

 

According this page https://support.google.com/analytics/answer/2853546?hl=en the format will be

 

 

ga('create', 'UA-XXXXXXXX-Y', 'example.com');
ga('set', 'contentGroup5', '<Group Name>');
ga('send', 'pageview');

 

 

At first I thought I can change "contentGroup5" for sub category and "<Group Name>" for top category

 

My top category is clothing and the subs are men's and women's

 

So according to your example and the Google support page above it will be 

 

 

ga('create', 'UA-XXXXXXXX-Y', 'auto');
ga('set', 'contentGroup1', 'Clothing - Mens');
ga('send', 'pageview');

 

 

Now we go further, since my intention is to use 2 tracking IDs, so it will be

 

 

ga('create', 'UA-XXXXXXXX-Y', 'auto');
ga('send', 'pageview');


ga('create', 'UA-XXXXXXXX-Z', 'auto', 'NewTracker');
ga('NewTracker.set', 'contentGroup1', 'Clothing - Mens');
ga('NewTracker.send', 'pageview');

 

 

Please note 2 different IDs above.

 

Here's my reference for multiple IDs

https://developers.google.com/analytics/devguides/collection/analyticsjs/creating-trackers#working_w...

http://stackoverflow.com/questions/18997966/how-to-track-multiple-accounts-using-new-analytics-js

http://www.tjkelly.com/blog/google-analytics-two-tracking-codes-on-same-page-2014/

 

What do you think?

Re: Multiple Analytics code with grouping. How?

Top Contributor
# 4
Top Contributor

I'm a fan of elegant code so i'd go with:

ga('create', 'UA-XXXXXXXX-Y', 'auto');
ga('send', 'pageview',{
  'contentGroup1', 'Clothing - Mens' 
});

ga('create', 'UA-XXXXXXXX-Z', 'auto', 'NewTracker');
ga('NewTracker.send', 'pageview,{
  'contentGroup1', 'Clothing - Mens' 
});

(assuming you want to apply content grouping to both properties)

 

You could also use Google Tag Manager to simplify deployment.

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

Re: Multiple Analytics code with grouping. How?

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭
I see, didn't know if your code works the same as Google support's example Smiley Tongue I'm not coding handy Smiley Happy

Thanks for the help!