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}>m_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:
- How to link GTM dataLayer and events data to GA?
- Should I use gtag instead of ga? I don't understand why GTM doesn't include the new version of GA with
gtag
www.googletagmanager.com/gtm.js
orwww.googletagmanager.com/gtag.js
script to fire my events. – VadorequestGA 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 analytics – Vadorequest