Google Analytics Custom Dimensions and Custom Metrics

How To Add Custom Dimensions and Custom Metrics In Google Analytics?

Gordon Choi
Gordon Choi
Author


Analytics

By default, Google Analytics makes built-in dimensions and metrics available. However, if some dimensions and metrics are not available, you can create custom dimensions and/or custom metrics.

Once the custom dimensions and/or custom metrics are created, you can use them to collect and analyze data that Google Analytics did not automatically track by default.

Each dimension and/or metric has a scope. Some examples:

  • Scope of Hit – The scope of hit is applied to page views. A user on your website can send one hit (by triggering one page view) or multiple hits (by triggering multiple page views). The value of a custom dimension is sent once per hit.
  • Scope of Session – When a custom dimension is created with session scope, its value is applied to all the hits in a current session.
  • Scope of User – When a custom dimension has a user scope, the user’s lifetime on your website can last or expire. The user’s lifetime is applied to all the hits in the current session and all future sessions until the user’s lifetime expires for your website.

Custom Dimensions

  • The dimension index: Each custom dimension must be assigned with an index. The format is dimension[0-9]+. Examples are dimension1, dimension13, etc.
  • Google Analytics has made up to 20 custom dimensions available per property. For Google Analytics Premium version, the limit is up to 200 custom dimensions.

Custom Metrics

  • The metric index: Each custom metric must be assigned with an index. The format is metric[0-9]+. Examples are metric1, metric13, etc.
  • A metric is numerical which can be integer, currency or time.
  • Google Analytics has made up to 20 custom metrics available per property. For Google Analytics Premium version, the limit is up to 200 custom metrics.

Steps to Create and Use Custom Dimensions and/or Custom Metrics

Below are the steps when using custom dimensions and custom metrics.

  • Step 1 Configuration: Create and define your custom dimensions and/or custom metrics in your Google Analytics account. Admin access to your Google Analytics account is required.
  • Step 2 Code implementation: Add the additional codes (for custom dimensions and/or custom metrics) to your current Google Analytics tracking code.
  • Step 3 Data Collection: Allow your website to collect users’ custom dimension and/or custom metric data.
  • Step 4 Reporting: View reports that contain custom dimension and/or custom metric data.

Create a New Custom Dimension

Go to Admin -> Custom Definitions -> Custom Dimensions -> + New Custom Dimension

Under Add Custom Dimension,

  • Enter the dimension’s name in the Name field.
  • Select Scope from one of the options: Hit, Session, User, or Product.
  • Check the Active radio button.
  • Click Create. Now you have successfully created a new dimension.

Create a New Custom Metric

Go to Admin -> Custom Definitions -> Custom Metrics -> + New Custom Metric

Under Add Custom Metric,

  • Enter the metric’s name in the Name field.
  • Select Scope from one of the options: Hit, or Product.
  • Select Formatting Type from one of the options: Integer, Currency or Time.
  • Check the Active radio button.
  • Click Create. Now you have successfully created a new metric.

Scope of Hit for Custom Dimensions

A hit is a user’s interaction with your mobile website that results in data being sent to Google Analytics. Examples of hits include:

  • Page views
  • Screen views
  • Events
  • Transactions

A user on your mobile website can send one or more hits, and value of a custom dimension is sent once per hit.

Scope of Session for Custom Dimensions

A session is a group of hits recorded for a user in a given time period. When a custom dimension is created with session scope, its value is applied to all the hits in a current session. A custom dimension’s value is sent once per session during a user’s session on your mobile website.

A session expires after 30 minutes of a user’s inactivity on your mobile website or at midnight (i.e. 00h00). A session can also expire when a user returns to your mobile website through a different campaign.

Scope of User for Custom Dimensions

When a user visits your mobile website for the first time, Google Analytics sets a new cookie on his / her web browser. A session is created for each user’s visit to your mobile website. For each user’s session:

  • A new user is counted in Google Analytics when the user visits your website for the first time. No Google Analytics cookie exists prior to this current session.
  • A returning user is counted in Google Analytics when it is not the first time the user visits your website. A previous Google Analytics cookie already exists.

For a custom dimension with user scope, a user’s lifetime on your mobile website can last or expire.

  • The user’s lifetime is applied to all the hits in the current session and all future sessions.
  • A user’s lifetime ends when he / she visits your mobile website through a different device or a different web browser. Google Analytics generates a new cookie for the user.
  • A user’s lifetime ends, when a user deletes cookies on his / her web browser.

A custom dimension’s value is sent once per user during a user’s lifetime on your mobile website.

Custom Dimension Example

Assume your mobile website is a hotel booking website which has different level of pages:

Homepage: http://www.example.com/
Hotel search result page per city: http://www.example.com/hotel-list/beijing/
Hotel detail page: http://www.example.com/hotel-detail/h00011

Assume the specific hotel detail page (with id h00011) is a hotel located in city Beijing.

http://www.example.com/hotel-detail/h00011

Assume the specific hotel detail page (with id h00012) is a hotel located in city Shanghai.

http://www.example.com/hotel-detail/h00012

Assume the specific hotel detail page (with id h00013) is a hotel located in city Shenzhen.

http://www.example.com/hotel-detail/h00013

In this case, you will need Google Analytics to report on sessions by Beijing hotels, sessions by Shanghai hotels, sessions by Shenzhen hotels, etc. Not a single standard Google Analytics report can provide such information.

Step 1: Configuration

You can set up a custom dimension to track sessions per city.

Go to Admin -> Custom Definitions -> Custom Dimensions -> + New Custom Dimension

Under Add Custom Dimension,

  • Enter “hotelcity” in the Name field for the dimension.
  • Select Session as scope.
  • Check the Active radio button.
  • Click Create. Now you have successfully created a new dimension with session scope.

Step 2: Code Implementation

The next step is you will have to add an additional code to the Universal Analytics version of your standard Google Analytics tracking code. The format of the additional code is:

ga('set', 'dimension1', 'value');

On all the web pages which contain a Beijing hotel, assign ‘hotel-beijing’ as value.

ga('set', 'dimension1', 'hotel-beijing');

One the web page, the entire Google Analytics tracking code will become:

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-Y', 'auto');
ga('set', 'dimension1', 'hotel-beijing');
ga('send', 'pageview');

The sequence of each line of code is important. The line of code that sets the custom dimension has to be defined before the page view is sent.

ga('create', 'UA-XXXXXXXX-Y', 'auto');
ga('set', 'dimension1', 'hotel-beijing');
ga('send', 'pageview');

For web pages with a Shanghai hotel, assign ‘hotel-shanghai’.

ga('set', 'dimension1', 'hotel-shanghai');

For web pages with a Shenzhen hotel, assign ‘hotel-shenzhen’.

ga('set', 'dimension1', 'hotel-shenzhen');

On all other web pages that do not require tracking sessions by hotel city, you will still use the standard tracking code without changes. Or refer to Google Analytics Tracking Codes.

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-Y', 'auto');
ga('send', 'pageview');

Steps 3 & 4: Data Collection and Reporting

Assume you have allowed time for Google Analytics to collect data into your newly implemented custom dimension.

From any Google Analytics report that has Second Dimension available for selection, click to expand the Second Dimension drop-down. Your newly created “hotelcity” custom dimension should appear under Custom Dimensions.

Now you can use your custom dimensions in your Google Analytics reports. Example:

  • Under the Source/Medium report, select “hotelcity” from the Second Dimension drop-down.
  • Now you should see “hotel-beijing”, “hotel-shanghai” and “hotel-shenzhen” appear under the Second Dimension column alongside all the source/medium values in the Source/Medium report.

Previous Chapters

Next Chapters



Content on Gordon Choi’s Analytics Book is licensed under the CC Attribution-Noncommercial 4.0 International license.

Gordon Choi’s Other Books:
The China Mobile SEO Book
Mobile Website Book

[elementor-template id=”764″]

Copyright 2016-2021 www.AnalyticsBook.org