alinemorelli / react-gtm

React Google Tag Manager
MIT License
659 stars 140 forks source link

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

Open gugol2 opened 2 years ago

gugol2 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Ok, I made a small development...

How could I open a PR to this repo?

natterstefan commented 2 years ago

Hi @gugol2,

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

kodiekenta commented 2 years ago

what npm version did you use to install the package