How to set up custom dimensions and metrics in Google Analytics

Author:

Custom dimensions and metrics in Google Analytics allow you to collect and analyze data that’s not automatically tracked by default. They provide the flexibility to tailor your analytics to your specific needs, enabling you to gather more detailed insights about your website or app users. This guide will walk you through the steps to set up custom dimensions and metrics in Google Analytics.

What Are Custom Dimensions and Metrics?

  • Custom Dimensions: These are user-defined attributes that can be used to describe your data. For example, you might create custom dimensions for user roles, content categories, or campaign names.
  • Custom Metrics: These are user-defined measurements that allow you to quantify aspects of your data. For example, you might create custom metrics for user ratings, download counts, or interactions.

Why Use Custom Dimensions and Metrics?

Using custom dimensions and metrics can provide several benefits, including:

  • Enhanced Data Collection: Capture information that’s specific to your business needs.
  • Improved Analysis: Analyze data in ways that aren’t possible with standard dimensions and metrics.
  • Better Reporting: Create more detailed and meaningful reports.

Steps to Set Up Custom Dimensions and Metrics

1. Access Google Analytics Admin

Log in to your Google Analytics account and navigate to the Admin section. Select the property where you want to create custom dimensions and metrics.

2. Create Custom Dimensions

To create custom dimensions, follow these steps:

  1. Navigate to Custom Definitions: In the Admin panel, under the “Property” column, click on “Custom Definitions” and then “Custom Dimensions.”
  2. Click on + New Custom Dimension: This opens a form to create a new custom dimension.
  3. Fill in the Details: Provide a name for the custom dimension (e.g., “User Role”), select the scope (e.g., Hit, Session, User, or Product), and check the “Active” box.
  4. Save the Dimension: Click “Create” to save your custom dimension.

3. Create Custom Metrics

To create custom metrics, follow these steps:

  1. Navigate to Custom Definitions: In the Admin panel, under the “Property” column, click on “Custom Definitions” and then “Custom Metrics.”
  2. Click on + New Custom Metric: This opens a form to create a new custom metric.
  3. Fill in the Details: Provide a name for the custom metric (e.g., “User Rating”), select the formatting type (e.g., Integer, Currency, Time), and set the minimum and maximum values if applicable.
  4. Save the Metric: Click “Create” to save your custom metric.

4. Implement Tracking Code

After creating custom dimensions and metrics, you need to implement the tracking code on your website or app to collect data. This typically involves modifying your Google Analytics tracking code.

For Websites:

  1. Modify the GA Tracking Code: Use gtag.js or analytics.js to set custom dimensions and metrics. Here’s an example for gtag.js:
    javascript

    gtag('event', 'your_event_name', {
    'custom_dimension_name': 'your_custom_dimension_value',
    'custom_metric_name': your_custom_metric_value
    });

    And for analytics.js:

    javascript

    ga('create', 'UA-XXXX-Y', 'auto');
    ga('set', 'dimension1', 'your_custom_dimension_value');
    ga('set', 'metric1', your_custom_metric_value);
    ga('send', 'pageview');
  2. Set the Custom Dimensions and Metrics in Your Code: Ensure that the custom dimensions and metrics are set in the appropriate events or pages where you want to collect data.

For Mobile Apps:

If you’re using Google Analytics for Firebase, you can set custom parameters in your events. Here’s an example for Android:

java

Bundle params = new Bundle();
params.putString("custom_dimension_name", "your_custom_dimension_value");
params.putInt("custom_metric_name", your_custom_metric_value);
mFirebaseAnalytics.logEvent("your_event_name", params);

And for iOS:

objc

[FIRAnalytics logEventWithName:@"your_event_name"
parameters:@{
@"custom_dimension_name": @"your_custom_dimension_value",
@"custom_metric_name": @(your_custom_metric_value)
}];

5. Verify Data Collection

After implementing the tracking code, it’s essential to verify that the data is being collected correctly. You can do this by:

  1. Real-Time Reports: Check the real-time reports in Google Analytics to see if data is being recorded as expected.
  2. Custom Reports: Create custom reports to include the custom dimensions and metrics and verify the data.

6. Use Custom Dimensions and Metrics in Reports

Once you’ve verified that data collection is working, you can use custom dimensions and metrics in your reports:

  1. Custom Reports: Go to “Customization” > “Custom Reports” > “New Custom Report” and include your custom dimensions and metrics.
  2. Segments: Create segments using your custom dimensions and metrics to analyze specific subsets of data.
  3. Dashboards: Add widgets to your dashboards that use custom dimensions and metrics to monitor performance.

7. Regularly Review and Optimize

Regularly review the data collected through custom dimensions and metrics to ensure they continue to meet your business needs. Optimize your implementation and reports as necessary to gain the most valuable insights.

Best Practices for Custom Dimensions and Metrics

1. Plan Ahead

Carefully plan which custom dimensions and metrics you need before implementing them. This helps ensure that you collect meaningful data.

2. Use Descriptive Names

Choose descriptive names for your custom dimensions and metrics to make them easily identifiable in reports.

3. Limit the Number of Custom Dimensions and Metrics

Google Analytics allows a limited number of custom dimensions and metrics per property. Use them wisely to avoid reaching the limit.

4. Test Thoroughly

Thoroughly test your implementation to ensure that data is being collected accurately and consistently.

5. Document Your Setup

Maintain documentation of your custom dimensions and metrics, including their names, scopes, and where they are used. This can be helpful for future reference and when sharing insights with your team.

Conclusion

Setting up custom dimensions and metrics in Google Analytics allows you to tailor your data collection to your specific business needs. By following the steps outlined in this guide, you can create, implement, and utilize custom dimensions and metrics to gain deeper insights into your website or app performance. Regularly review and optimize your setup to ensure that you continue to gather valuable and actionable data.