0
votes

I'm trying to add a custom dimension in Google Analytics.

I think I have it set up correctly.

Configuring a custom dimension in Google Analytics.

And I've added the code to the pages

(function (i, s, o, g, r, a, m) {
          i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
          (i[r].q = i[r].q || []).push(arguments)
          }, i[r].l = 1 * new Date(); a = s.createElement(o),
          m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
          })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
          ga('set', 'dimension1', 'username');
          ga('set', 'dimension2', 'buyer name');
          ga('create', UA-xxx, 'auto');
          ga('send', 'pageview');

I made a custom report in order to use the custom dimension but it doesn't show anything at all.

Custom report using custom dimension in Google Analytics shows no data.

What have I got wrong?

1
How are you fetching buyer name? Are all the people signed in when they visit your website? - Emipro Technologies Pvt. Ltd.

1 Answers

1
votes

You need to "set" the dimension after you have created the tracker, but before the send call. So swap the create and "set" lines in your example:

ga('create', UA-xxx, 'auto');
ga('set', 'dimension1', 'username');
ga('set', 'dimension2', 'buyer name');
ga('send', 'pageview');

A set call always refers to a specific tracker instance (default tracker is named t0 and set calls will default to that name), so you need to have an instance before you can use it.

Also it takes a while before custom dimensions start to show up.