0
votes

Anyone with a bit of experience would be kind to clarify the GA/GA-old/GTM mix for me?

I am using GTM (Google Tag Manager) and I basically inject this in the DOM on page load (I got this script from GTM):

const scriptTag = `
    (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
      new Date().getTime(),event:'gtm.js',${JSON.stringify(events).slice(1, -1)}});
      var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';
      j.async=true;j.src='${protocol}://www.googletagmanager.com/gtm.js?id='+i+dl+'${gtm_auth}${gtm_preview}&gtm_cookies_win=x';
      f.parentNode.insertBefore(j,f);
    })(window,document,'script','${dataLayerName}','${id}');`;

I have set up a "Universal Google Analytics" on my GTM, and I have ga function available in the browser console. I have successfully used the dataLayer feature of GTM and I can see my dataLayer get filled when using the preview GTM mode.

But, I don't understand how to link the variables I store in the dataLayer to GA, I save a env variable in my dataLayer, and I have added a "data layer" variable env on GTM, but I feel like I missed a step to link that variable to GA. (None of the variables I save in my dataLayer are stored into GA)

I also heard about the "new GA way", which relies on gtag... But I don't have a gtag function created by the "google analytics" script injected by GTM.

I'm getting lost in what is supposed to be the way of doing things.

Old way: https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications

New way: https://developers.google.com/analytics/devguides/collection/gtagjs/single-page-applications

(I'm building a SPA)

So:

  1. How to link GTM dataLayer and events data to GA?
  2. Should I use gtag instead of ga? I don't understand why GTM doesn't include the new version of GA with gtag
1
Are you having issues getting the dataLayer value to the tag or are you having trouble triggering a tag to fire when a value is added to the dataLayer?Brian Norman
@BrianNorman There are several issues. 1) my GTM dataLayer gets filled correctly, but those values aren't accessible in GA console. 2) I don't know if I should load www.googletagmanager.com/gtm.js or www.googletagmanager.com/gtag.js script to fire my events.Vadorequest
When you say 'GA console', are you referring to the browser's js console? I am using gtm.js on my site. Do you have any variables set up in GTM to store the dataLayer values which can then be used in your Universal Analytics tags?Brian Norman
by GA console I mean the GA Dashboard at analytics.google.com and yes, I created variables in GTM dashboard for my dataLayer variables, and when using the preview mode, they show up on the browser GTM debug view and they're correctly set, but not sent back to analyticsVadorequest

1 Answers

1
votes

Do you have a Google Analytics Settings variable set up that your are setting on your Universal Analytics tags?

My settings variable looks like this:

GA Settings Variable

The tracking ID variable set in the image above looks like this:

Tracking ID Variable

Then, in my Universal Analytics event tag, I set the settings variable in the tag configuration: enter image description here