Custom Dimensions and Metrics 7


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.

 CustomDimensionMetric1

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.

CustomDimensionMetric2

 

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.

CustomDimensionMetric4

 

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 "";
}

?>

About Linda Lawton

My name is Linda Lawton I have more than 20 years experience working as an application developer and a database expert. I have also been working with Google APIs since 2012 and I have been contributing to the Google .Net client library since 2013. In 2013 I became a a Google Developer Experts for Google Analytics.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

7 thoughts on “Custom Dimensions and Metrics

  • Les

    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?

  • Linda Lawton

    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.

  • Prafulla Kumar Sahu

    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 .