Search code examples
javascriptgoogle-analyticscustom-dimensions

Google analytics not sending custom dimensions with pageview hits


I'm using google analytics to track page views on my site. trying to send custom dimensions during my pageviews. Here is what I have for the JS code

ga("create", '<UA-tracking ID goes here-01>', {
                'name': 'TrackingID3'
            });

                // SendPageView
                ga(function () {
                    var trackers = ga.getAll();
                    trackers.forEach(function (tracker) {

                        ga('set', 'dimension1', '187989840'); // departmentId
                        ga('set', 'dimension2', 'BLUE JEANS'); // caseName
                        tracker.send("pageview");
                    });
                });

The code above works but it does not send the custom dimensions

non-working live project

I made a new web project and a new google analytics account (new email). Everything is set up and working in the new google analytics account. Here is the code i have for the second web project

ga('create', 'UA-tracking ID goes here-01', {
        'cookieDomain': 'none'
    });

    // SendPageView
    ga(function () {
        var trackers = ga.getAll();
        trackers.forEach(function (tracker) {

            var dimensionValue = '187989840'; // departmentId
            ga('set', 'dimension1', dimensionValue);

            var dimensionValue = 'BLUE JEANS'; // caseName
            ga('set', 'dimension2', dimensionValue);

            tracker.send("pageview");
        });
    });

I tested the new web project and it successfully send the custom dimensions working example

Any Idea what I'm doing wrong?


Solution

  • there's a collision of using ga('set',...) command and tracker name parameter in the ga('create', ...) command. To avoid this you might want to use specific tracked method:

    trackers.forEach(function (tracker) {
    
                var dimensionValue = '187989840'; // departmentId
                tracker.set('dimension1', dimensionValue);
                // ...
    
                tracker.send("pageview");
    
            });