1
votes

I have created in Google Analytics custom segment

Custom Variable (Key 1) contains AbTestDesign

This is the screenshot:

enter image description here

My current analytics script is:

!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-10969791-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-xxxxxxx-1');
</script>

How should I change my script so that this custom variable (key 1) is set to 'AbTestDesign' using Javascript on the session level?

The documentation is so confusing (as the analytics changes much faster than original documentation I guess): https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets

1

1 Answers

0
votes

That page of documentation describes how to send custom dimensions and metrics to Google Analytics. It is a value that you send to GA in certain situations. You have to set this 'variable' in Admin Property of GA (https://support.google.com/analytics/answer/2709829?hl=en), so you can define here the name and the scope (in your case Session) and send data from the website to that index of custom 'variable' with pageview or event.

A segment is a subset of your Analytics data, you can configure it in GA interface (i.e. sessions that have your custom dimension with value you prefer) and apply it on the reports to view filtered data based only for that subset.

[EDIT]

You don't have to use the custom variables but the name of the custom dimension you created. Furthermore your gtag code does not contain the part to send the custom dimension to Analytics, you must follow the link to the documentation you have put.

The doubt you have is why you are using custom variables that no longer exist, so modify the segment accordingly with your custom dimension name after you created it.