3

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't see how removing the GA_MEASUREMENT_ID line fixes this - that may be needed for initialising another property (example). I have this same "Cannot parse target" error, any ideas how to fix?
@AlecRust this is working in production for us, on website numbeo.com . Analytics shows this custom dimension in the reports and it looks correct (approx. half sessions with abTestDesign 1 and the rest with 0). The line with GA_MEASUREMENT_ID was errornes it is the same as 'UA-xxxxx-x' string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.