analytics icon indicating copy to clipboard operation
analytics copied to clipboard

`@analytics/google-tag-manager` adds `gtag` to `gtm.js` as well

Open Carduelis opened this issue 2 years ago • 2 comments

While @analytics/google-tag-manager should add only gtm.js script, I see in my HTML also gtag.

I'm not sure it's a part of the package, since I wasn't able to find any evidence in the source code of the library, but I am curious, why gtm adds gtag as well. Due to this fact, the performance of the page is affected.

image

Carduelis avatar Feb 09 '23 11:02 Carduelis

To make it clearer, I have a couple of questions:

  1. Does gtm.js add gtag/js automatically? (Looks like it is "yes", since gtm.js contains the G-xxxxxx key inside
  2. Is this behavior intentional? I read a lot that we do not need both tags, and they claim it's bad to add both
  3. Is there a way to have a certain setting in @analytics/google-tag-manager to manage the behavior?
  4. I bet @analytics/google-tag-manager needs a Readme about this behavior.

Because, it looks like @analytics/google-tag-manager also behaves like @analytics/google-analytics (which v4)

import Analytics from 'analytics'
import googleAnalyticsPlugin from '@analytics/google-analytics'
import googleAnalyticsV3Plugin from '@analytics/google-analytics-v3'

/* Initialize analytics instance */
const analytics = Analytics({
  app: 'my-app',
  plugins: [
    /* Load Google Analytics v4 */
    googleAnalyticsPlugin({
      measurementIds: ['G-abc123'],  // this is the `G-xxxxx` key i have in my setup
    }),
  ],
})

analytics.page()

Carduelis avatar Feb 09 '23 11:02 Carduelis

GTM only adds one script tag here https://github.com/DavidWells/analytics/blob/master/packages/analytics-plugin-google-tag-manager/src/browser.js#L66

It sounds like your google tag script is added the additional script. Check your container ID and verify what it's loading

DavidWells avatar Mar 17 '23 17:03 DavidWells