AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
2.5K members online now
2.5K 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

Passing Custom Dimensions in Pageviews and Events

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Greetings everyone!

I seem to be having a bit of difficulty passing custom dimensions with my pageviews and events. I would like to be able to pass parameters that were used in a chart build by setting them equal to a variable and sending that variable using a dimension. 

 

I'm using the following... 

ga('send', {
     hitType: 'event',
     eventCategory: 'Comparison',
     eventAction: 'Compare Bottom Chart Update',
     eventLabel: 'Vehicle Model',
     title: 'Comparison', {
          'dimension2': dimensionValueBottom
     }
});

... to track when a new chart has been loaded into my bottom comparison panel as well as the parameters passed to the chart, loaded into dimension2. I ran the .js file that contains this code through JSLint and it threw an error after the title definition at the " { ". I'm inclined to agree that the formatting on this is not correct.

 

 Does the correct format look like this?

ga('send', {
     hitType: 'event',
     eventCategory: 'Comparison',
     eventAction: 'Compare Bottom Chart Update',
     eventLabel: 'Vehicle Model',
     title: 'Comparison', 
     'dimension2': dimensionValueBottom
});

...or is there another way that I have to set this up to pass dimensions?

 

Thank you in advance for your help.

 

Cheers!

1 Expert replyverified_user

Re: Passing Custom Dimensions in Pageviews and Events

Top Contributor
# 2
Top Contributor

Hi, SA D,

 

A better way to send your data would be the following:

 

ga('send', 'event', 'Comparison', 'Compare Bottom Chart Update', 'Vehicle Model', {'dimension2': dimensionValueBottom}
});

This uses the "shorthand" event notation. The "title" parameter that you had is incorrect. 

 

You can read these for reference: https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets and https://developers.google.com/analytics/devguides/collection/analyticsjs/events

Nicky Yuen, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.
Find me on: Google+ | LinkedIn

Re: Passing Custom Dimensions in Pageviews and Events

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Does the correct longhand code look like this: 

ga('send', {     
hitType: 'event',
eventCategory: 'Comparison',
eventAction: 'Compare Bottom Chart Update',
eventLabel: 'Vehicle Model',
'dimension2': dimensionValueBottom
});

 

Thank you. 

Passing Custom Dimensions in Pageviews and Events

Top Contributor
# 4
Top Contributor

Hi, SA D,

 

That looks good. One super easy way to test this is to copy that code out, paste it into your dev console (change the "dimensionValueBottom" value so it's some test value), and hit enter. You should see the collect hit with the event parameters. Alternatively, you could install GA Tag Assistant and do the same thing and you'll see some GA info displayed in the console which will tell you if everything is good! Also, checking with Real Time works, too, but then you'd be sending in "dirty" data into your property.

 

Hope this helps.

Nicky Yuen, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.
Find me on: Google+ | LinkedIn