Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set custom variables through the new analytics.js of GA

See the Guide https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets

I cant find any way to track Custom Variables like the old tracking js "ga.js": https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables

_setCustomVar(index, name, value, opt_scope) 

Anyone can help?

thanks!

like image 437
Eric Dum Avatar asked May 08 '13 12:05

Eric Dum


People also ask

Where are custom dimensions in Google Analytics?

To get started, you can log into Google Analytics, and select the website in which you'd like to set up custom dimensions. Now, click on the Admin tab in the left panel. On the Admin page in the middle column, click Custom Definitions and then Custom Dimensions.

What is the difference between Analytics js and GTAG js?

js uses trackers to send events to Google Analytics. A tracker has the tracking ID of a Google Analytics property. By contrast, gtag. js sends events to a Google Analytics property identified by the TAG_ID specified in a config command.


1 Answers

Custom Variables don't exist any more in analytics.js (aka Universal Analytics). It has been replace with Custom Dimensions and Metrics that are more flexible and powerful.

Advantages of Custom Metrics and dimensions:

  • They can be used in filters
  • They are first class citizens in the interface, so you will see the custom variable name in the interface (instead of the generic "Custom Variable 5")
  • Configured in the interface
  • Metrics that are aggregated (not possible with custom vars)
  • 20 custom dimensions + 20 custom metrics available, instead of only 5 custom variables

In order to use Custom Dimensions/Metrics, you need to configure them on the interface. Go into admin, drill down into your web property and then there is a tab for "custom definitions".

Then when you track it, you just need to track the value and the id of the custom property eg:

ga('send', 'pageview', {   'dimension15':  'My Custom Dimension' }); 

This will send a pageview with the custom dimension attached to it.

You can also set one on the page that will be applied to any pageviews or events that happened on the page.

ga('set', 'dimension5', 'custom data'); 

Note that only setting it won't send to GA, so if you decide to use set make sure you call a send afterwards at least once on the page to actually send that data to GA.

More Info: Developer Docs

like image 111
Eduardo Avatar answered Sep 28 '22 07:09

Eduardo