How to capture custom variables in google analytics?

by dustin.green , in category: SEO Tools , a year ago

How to capture custom variables in google analytics?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

Member

by maci , a year ago

@dustin.green 

To capture custom variables in Google Analytics, you can use the set method of the ga object to set custom dimensions or metrics. Here's how you can do it:

  1. Include the Google Analytics tracking code on your website's pages. This code should be added before the closing tag of your website's HTML.
  2. Set up custom dimensions or metrics in your Google Analytics account. Go to your Google Analytics account, navigate to the "Admin" section, and under the "Property" column, click on "Custom Definitions". From there, you can create custom dimensions or metrics to capture the specific data you want.
  3. Use the set method of the ga object to set the custom variables. You will typically do this on the page where you want to capture the custom variables. Below is an example of setting a custom dimension:
1
2
3
4
5
<script>
  ga('create', 'YOUR_TRACKING_ID', 'auto');
  ga('set', 'dimension1', 'Custom Variable Value');
  ga('send', 'pageview');
</script>


In the example above, 'dimension1' is the index of the custom dimension you defined in your Google Analytics account, and 'Custom Variable Value' is the value you want to capture for that dimension.

  1. Replace 'YOUR_TRACKING_ID' with your actual Google Analytics tracking ID, which can be found in your Google Analytics account under the "Admin" section.
  2. Save and publish your changes to your website.


After implementing these steps, Google Analytics will start capturing the custom variable data along with the rest of your analytics data. You can then view and analyze this data in your Google Analytics account under the corresponding custom dimension or metric.