1

I have set up 4 dimensions. My code as follows,

 <script>//<![CDATA[
        window.dataLayer = window.dataLayer || [];
        function gtag() {
            dataLayer.push(arguments);
        }
        gtag('js', new Date());
        gtag('config', 'UA-XXXXX-1');

        gtag('set', {
            'user_id': _spPageInfo.userId,
            'JobTitle': jobTitle,
            'Department': department,
            'UserLocation': Location
        });
        gtag('send', 'pageview');

        //]]>
    </script>
    <script>//<![CDATA[
        // <!-- Google Tag Manager -->
        (function (w, d, s, l, i) {
            w[l] = w[l] || [];
            w[l].push({
                'gtm.start': new Date().getTime(),
                event: 'gtm.js'
            });
            var f = d.getElementsByTagName(s)[0],
                j = d.createElement(s),
                dl = l != 'dataLayer' ? '&l=' + l : '';
            j.async = true;
            j.src =
                'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
            f.parentNode.insertBefore(j, f);
        })(window, document, 'script', 'dataLayer', 'GTM-XXXX');

        // <!-- End Google Tag Manager -->

        //]]>
    </script>

I have set up dimenstion in tag manager as well.
In debug mode i can see "Conatiner Loaded" instead of "Page Load",

<p

And in datalayer i can not see any event name or dimension name.

enter image description here

After 24 hours also its showing undefined. Please,Can anyone guide me what i am missing here?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Chand Jogani
  • 146
  • 12

1 Answers1

1

you'll need to pass custom_map parameter with your config command you map your named dimension values to custom dimension. See an example here. Moreover, you'll need to call set before config since config is actually passing pageview hit to google analytics so calling set after config won't affect your data Eventually, your code would look something like this:

gtag('js', new Date());
gtag('set', {'custom_map': {
  'dimension1': 'department',
  'dimension2': 'jobTitile',
  // the same for other custom dimensions
}})
gtag('config', 'UA-XXXXX-1', { 'jobTitile': 'engineer', 'department':'maintenance' });

Moreover, avoid using both GTM and gtag code at the same time otherwise you'll get duplicated data sent to analytics.

Дмитро Булах
  • 3,697
  • 1
  • 14
  • 23
  • Thanks now i am seeing `Container Loaded: 1 {event: 'gtm.js', gtm.start: 1591683140892, gtm.uniqueEventId: 4}` and on document load or Dom load Window Loaded: {event: 'gtm.load', gtm.uniqueEventId: 215} Data Layer values after this Message: `{ event: 'gtm.load', gtm: {start: 1591683669174, uniqueEventId: 215}, custom_map: { dimension1: 'user_id', dimension2: 'JobTitle', dimension3: 'Department', dimension4: 'FacilityLocation' } }` Variable values are still undefined. – Chand Jogani Jun 09 '20 at 06:24
  • 1
    what you're seeing in GTM will be undefined because GTM uses another mechanism for analytics custom dimensions. If you're about using GTM please refer to respective GTM docs https://support.google.com/tagmanager/answer/6164990?hl=en – Дмитро Булах Jun 09 '20 at 08:26
  • Does it mean that i need to remove manually entered custom dimension from GTM and i have to keep only in JS code? Because i am seeing now against my id number under job title two row, one with "JobTitle" and another with "Developer". "JobTitle" is my dimension name. – Chand Jogani Jun 09 '20 at 09:56
  • 1
    keep all the `gtag` calls in the code if you're going to use `gtag` analytics implementation. remove all the code if you're going to use GTM and would like to see the data in preview tab. Follow the GTM instructions to configure the analytics tag properly. – Дмитро Булах Jun 09 '20 at 10:08
  • 2
    once again -- GTM and GTM preview mode has nothing to do with your `gtag` code. You won't see any confirmation from GTM preview tab even if your `gtag` code is working properly. GTM and `gtag` are two distinct incompatible tools. – Дмитро Булах Jun 09 '20 at 10:11
  • 1
    Thank you very much. You clear my concepts very well. – Chand Jogani Jun 09 '20 at 10:29