1
votes

in Analytics, under Admin -> Property -> Custom Dimension

I did create a Custom Dimension with index 1, scope session, the name abTestDesign

Also, I did create a custom segment with the name 'AbTestDesign=1' which is defined as abTestDesign (custom Dimension) contains 1. I can see this segment in Google Analytics.

For the potion of the website traffic, I did change the Analytics Code to the following (I did follow the instructions from https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets thanks @MichelePisani for help to reach this stage).

So the code which some pages add is the following:

<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-10969791-1');
  gtag('config', 'GA_MEASUREMENT_ID', {
  'custom_map': {'dimension1': 'abTestDesign'}
  });

  gtag('event', 'abTestDesign_dimension', {'abTestDesign': 1});
</script>

The code doesn't produce any Javascript error but it doesn't seem to be working as it shows 0 entrances, while there were at least some entrances by myself.

Where did I get this wrong? (I guess the problem is with the code).

1

1 Answers

1
votes

This question helped me:

gtag not sending custom dimensions for events

Installed in Chrome web browser, the Google Analytics Debugger extension. Opened the F12 Developer Tools and then visit a page that has your GTag script running.

The error message for me was:

Cannot parse target: ""GA_MEASUREMENT_ID"

So the correction for the code would be

<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-xxxxxxx-x', {
  'custom_map': {'dimension1': 'abTestDesign'}
  });

  gtag('event', 'abTestDesign_dimension', {'abTestDesign': 1});
</script>

Replace the UA string with your own Analytics string.