react-gtm icon indicating copy to clipboard operation
react-gtm copied to clipboard

Is it possible exclude localhost from making the call to GTM?

Open gugol2 opened this issue 2 years ago • 4 comments

I read that this is possible when interacting directly with GTM:

if (admin || localhost) { // disable GA:
  window['ga-disable-UA-XXXXX-Y'] = true; // enter your tracking ID
}

Quoting the docs:

The analytics.js library includes a window property that, when set to true, disables analytics.js from sending data to Google Analytics. When Google Analytics attempts to set a cookie or send data back to the Google Analytics servers, it will check whether this property is set to true. If it is, no action will be taken.

To disable tracking, set the following window property to true:

window['ga-disable-UA-XXXXX-Y'] = true;

Where the value UA-XXXXX-Y corresponds to the property ID on which you would like to disable tracking.

Is this possible using react-gtm?

gugol2 avatar Jul 13 '22 08:07 gugol2

At the moment I am solving it like so:

if (!isLocalServer()) {
    optimizelyKey = process.env.REACT_APP_OPTIMIZELY_SDK_KEY!;

    const tagManagerArgs = {
        gtmId: process.env.REACT_APP_GTM_ID as string,
    };

    TagManager.initialize(tagManagerArgs);
}

But I wonder if could be done with an attribute in tagManagerArgs

gugol2 avatar Jul 13 '22 12:07 gugol2

Ok, I made a small development...

How could I open a PR to this repo?

gugol2 avatar Jul 13 '22 12:07 gugol2

Hi @gugol2,

here is a step by step guide: https://www.digitalocean.com/community/tutorials/how-to-create-a-pull-request-on-github.

natterstefan avatar Jul 18 '22 10:07 natterstefan

what npm version did you use to install the package

kodiekenta avatar Sep 09 '22 16:09 kodiekenta