Gordon Choi

Author of the Analytics Book

User Tools

Site Tools


google_analytics_custom_dimensions_and_custom_metrics

Google Analytics Custom Dimensions and Custom Metrics

Chapter 06

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 they are created, you can use them to collect and analyze data that Google Analytics does not automatically track.

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

  • 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:

<script>
(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');
</script>

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.

<script>
(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');
</script>

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


Gordon Choi's Analytics Book has been available since August 2016 and is proudly powered by Folks Analytics.

Thank you for reading! If you love my book, you're welcome to donate through Paypal.

google_analytics_custom_dimensions_and_custom_metrics.txt · Last modified: 2017/02/16 23:19 by Gordon Choi