Custom dimensions is a powerful feature that allows you to track values that persist across multiple events or pageviews. When you set the dimension to a value, it is activated and will be attached to any event/pageview that is triggered during its active state. We can specify when it should be deactivated by setting its scope.
In this example, we have a shopping app where we need to track events with a user type attached. Users can be one of the following:
- Visitor (not logged in)
One way to achieve this, without using dimensions, is to use a label or category exclusively to indicate user type:
|Category||Action||Label||Value (Product ID)|
|Buyer - VIP - Silver||View Product From Direct Link||Candies||7253|
|Visitor||View Product From Daily Deals||Candies||7253|
|Buyer - Regular||Add Product To Cart||Candies||7253|
However, there are a few disadvantages:
- We have to find the user type each and every time an event happens
- It takes up a precious slot, which could be used for more unique data (such as which page the users views the product)
- If there are more subcategories, it will become a slew of " - " seperators, and we'd have to use regex to search for them afterwards
By using custom dimensions, we will be able to add extra layers on top the event, indicating the user type and possible VIP status. This only needs to be sent once at login, and once at logout.
In the Admin panel, find the row named "Custom Definitions" in the middle column. Then you will be able to add a new dimension:
"Hit" only persists for the event/pageview immediately following it.
"Session" persists for the duration of what Google defines as a session (normally after 30 minutes of inactivity, or at midnight)
"User" persists until the user's GA cookie expires. (The User ID feature needs to be turned on)
"Product" persists until a user purchases an item. This can only be used if you import product data into Google Analytics.
In this case, the appropriate scope would be "User", since we are tracking the user type. The "Product" scope can also be used to track from which page the user added the bag of candies to cart.
Before You Start
If the dimension changes during a session or user scope, the last value will overwrite all previous values. That's why it is very important to tell GA that a user has logged out. This overriding behavior can also be used as a feature. If we let GA set an auto user ID for visitors, when a visitor adds candies to cart and then logs in, we will be able to save the previous actions onto the existing user's profile (note that Session Unification needs to be turned on).
Read this section from GA's docs for implementation details.