In this post we will be taking a quick look at custom dimensions in Google Universal Analytics. Before Universal Analtyics we used to create custom variables to track extra information. As an example we are going to use the Catagories and Tags here on my website. I wanted to be able to log what category and tags where most viewed here on the site, so that i could make sure to add posts that you would find most useful.
Before I continue I want to be sure that we are clear on the difference between a Dimension and a Metric.
A dimension is an descriptive attribute or characteristic of an object that can be given different values. For example, a geographic location could have dimensions called Latitude, Longitude, or City Name. Values for the City Name dimension could be San Francisco, Berlin, or Singapore.
Metrics are individual elements of a dimension that can be measured as a sum or a ratio. For example, the dimension City can be associated with a metric like Population, which would have a sum value of all the residents of the specific city. Screenviews, Page per Visit, and Average Visit Duration are examples of metrics in Google Analytics.
Make sure that you are creating a custom object for the right thing 🙂
Creating a Custom Dimension
The first thing you need to do is create the Custom Dimension in the Google Analtyics Website. Go to the Admin section and look under Property you will find Custom dimensions and metrics check the picture below.
Now the new screen loads click on the New Custom Dimension button, notice to the right that there is a quota. The quota means that you can Max have 20 custom dimensions. Not very nice of them to limit it but as yet i haven’t used all 20 so I’m not to worried. But it does mean that you need to be more careful with randomly creating Custom Dimensions and metrics that you don’t really need.
When you create your new custom Dimension you will need to give it a name, you can also decided if you want it to be active at the time of creation or you can activate it later. You also have the option of deciding the scope for your custom dimension.
- Hit – value is applied to the single hit for which it has been set.
- Session – value is applied to all hits in a single session.
- User – value is applied to all hits in current and future sessions, until value changes or custom dimension is made inactive.
I just leave it at Hit, but you can change it depending upon what you are looking to track.
Now each of your custom dimensions has a index number it is this number that you send along with your js tracking code. If you click on the dimension name it will take you to another screen and show you the tracking code you will need to use.
Tracking Code
Universal Analytics does not use the .push
syntax. Instead, it has a function ga().
ga('set','dimension1','Blog');
I don’t send Category to the tracker i send dimension1 it knows what dimension i mean because of the index 1.
Conclusion
I hope that this short post helps you understand how to us custom dimensions in Universal Analytics.
WordPress
For anyone running wordPress I have been unable to find a Universal Analytics plugin that lets me add Custom dimensions and metrics so I did some code hacking and came up with this. Add the following code to post-formats.php for the theme you are running. I will be creating my own Google Analtyics WordPress plugin soon I’m tired of the limitations of the ones out there.
"; foreach($categories as $category) { echo "ga('set','dimension1','".$category->name."');\r\n"; } echo "\r\n"; } $posttags = get_the_tags(); if ($posttags) { echo ""; } ?>
Hi Linda,
Your WP code just sets the dimension name … it doesn’t send values to it, right? 🙂
actually it does. View the code on this page. Its sending ga(‘set’,’dimension1′,’Google Analtyics’); and ga(‘set’,’dimension2′,’Tutorial’);
Thanks for this tut Linda. Just wondering how you are progressing with that plugin. Also… wouldn’t it be more practical to implement this solution via GTM and the data layer?
I haven’t had the time to sit down and look into GTM. I’m sorry I have to come clean I have no idea what you can and can’t do with GTM. The plug in is also on hold until I am done with the overhaul of the GA tutorials.
This is a great post, thanks for this. Very interested in the plugin as well.
Is there any way to set a custom dimension using PHP ?
I want to get something like this :-
ga(‘set’,’ga:serverResponseCode’,http_response_code());
ga:serverResponseCode
return $analytics->data_ga->get(
‘ga:’ . $profileId,
$start_date,
$end_date,
‘ga:pageviews,ga:uniquePageviews,ga:avgTimeOnPage,ga:bounceRate,ga:exitRate’,
array(‘dimensions’ => ‘ga:PagePath, ga:serverResponseCode’, ‘filters’ => $filter ) );
Please help me .
Sending data to Google Analytics is done though the measurement protocol. It is done using pure HTTP Post or Get so you can do it with PHP. Check Custom Dimensions / metrics