Setting up and tracking custom dimensions and metrics in Google Tag Manager (GTM) involves configuring both Google Analytics (Universal or GA4) and Google Tag Manager itself. Custom dimensions and metrics allow you to collect and analyze more granular data that is specific to your business needs, beyond what is automatically tracked by Google Analytics.
Here’s a step-by-step guide on how to set up and track custom dimensions and metrics using Google Tag Manager:
Step 1: Understand Custom Dimensions and Metrics
Before you begin, it’s essential to understand the difference between custom dimensions and custom metrics:
- Custom Dimensions: These are used to collect additional information about your users, sessions, or interactions (e.g., User Type, Membership Level, Product Category).
- Custom Metrics: These are numerical values that you want to track (e.g., number of downloads, time spent on a page).
Step 2: Set Up Custom Dimensions and Metrics in Google Analytics
- Sign into Google Analytics.
- For Universal Analytics:
- Go to Admin > Property > Custom Definitions > Custom Dimensions (or Custom Metrics for metrics).
- Click the + New Custom Dimension button.
- Enter a name for your custom dimension (e.g., “User Type”).
- Set the scope: “Hit,” “Session,” “User,” or “Product” based on how you want to track the data.
- Set the Active status to True.
- Click Create.
- For Google Analytics 4 (GA4):
- Go to Admin > Property > Custom Definitions.
- Click Create Custom Dimension (for dimensions) or Create Custom Metric (for metrics).
- Enter a name for your custom dimension or metric, and define the parameter or event parameter that will hold the value you wish to track.
- Choose the scope (Event-level, User-level).
- Click Save.
Step 3: Set Up Google Tag Manager
- Log into Google Tag Manager.
- Ensure you have the correct Google Analytics Tag already set up (either Universal Analytics or GA4).
Step 4: Create Variables in Google Tag Manager
You need to create variables in GTM that will pull the data you want to send to Google Analytics.
- For Custom Dimensions (Universal Analytics):
- Navigate to the Variables section in GTM.
- Click New to create a variable.
- Choose the variable type based on the data you want to capture:
- First Party Cookie (if you’re storing data in cookies).
- JavaScript Variable (to capture values from the data layer or DOM).
- Data Layer Variable (if the data is in the data layer).
- Name your variable (e.g.,
userType
). - For instance, if you’re using the data layer, select Data Layer Variable and enter the variable name that’s used in your data layer (e.g.,
user_type
). - Click Save.
- For Custom Dimensions (GA4):
- In GA4, you can capture custom dimensions directly from event parameters or user properties.
- Set up variables for each parameter you want to capture. For example, use JavaScript Variable or Data Layer Variable to pull event parameters.
Step 5: Modify Your Google Analytics Tag to Send Custom Dimensions or Metrics
For Universal Analytics:
- Go to Tags in GTM and either create a new tag or edit an existing Google Analytics pageview tag.
- Under Tag Configuration, select Universal Analytics as the tag type.
- Scroll down to the More Settings section and click on it.
- Click on Custom Dimensions.
- Click Add Custom Dimension.
- For Index, enter the custom dimension index (you can find this in Google Analytics under Admin > Custom Dimensions).
- For Dimension Value, select the variable you created in Step 4 (e.g.,
userType
). - Repeat this process if you need to set multiple custom dimensions.
- Once done, click Save.
For Google Analytics 4 (GA4):
- Create a GA4 Event Tag in GTM (or modify an existing one).
- Under Event Parameters, click Add Row.
- For Parameter Name, enter the name of the custom dimension (e.g.,
user_type
). - For Value, select the GTM variable you created in Step 4.
- Click Save.
Step 6: Trigger the Tag
Make sure the tag you created is triggered on the correct page or event:
- If you’re tracking custom dimensions on a page, use the Page View trigger.
- If it’s an event-based custom dimension, such as a user action, use the appropriate Event Trigger.
For example:
- Page View Trigger: To track custom dimensions across all pages.
- Click Trigger: To track a custom dimension when a user clicks a specific element.
Step 7: Test the Implementation
Before going live, use Preview Mode in GTM to test that the custom dimensions and metrics are being sent correctly to Google Analytics.
- Click the Preview button in Google Tag Manager.
- Open your website in a new tab. You should see the GTM debug console.
- Verify that the correct custom dimensions are being fired and sent to Google Analytics.
- In GA, you can check Real-time reporting to see if the data is coming through.
- In GA4, you can check DebugView for real-time event tracking.
Step 8: Verify Data in Google Analytics
Once you’ve published your changes in Google Tag Manager, you can view the data in Google Analytics.
- For Universal Analytics: Check the Custom Reports section or use the Customization options to view the custom dimension in reports.
- For GA4: Go to the Events or User Explorer section, and view the event parameters you’ve set up as custom dimensions.
Step 9: Monitor and Optimize
- Keep an eye on how the custom dimensions and metrics are impacting your reporting and analysis.
- Use the custom data to build custom reports or to create segments based on user behavior or attributes captured by your custom dimensions.
Conclusion
Setting up and tracking custom dimensions and metrics through Google Tag Manager involves several steps: configuring the custom dimensions and metrics in Google Analytics, creating the necessary variables in GTM, and adjusting your tags to send this data. Testing and verification are crucial to ensure that your data collection is accurate. Custom dimensions and metrics help you capture detailed, business-specific data that can provide deeper insights into user behavior, enhancing your ability to make data-driven decisions.