This plugin adds the GTM script tag to your HTML files. You only need to supply the GTM ID.
In an existing react-static site run:
$ yarn add -D react-static-plugin-google-tag-manager
Then add the plugin to your static.config.js
:
export default {
plugins: [
[
'react-static-plugin-google-tag-manager',
{
// example configuration
id: 'your-gtm-id-here',
debug: true,
},
],
],
};
In your static.config.js
, you should pass configuration options to the plugin.
Pass your Google Tag Manager ID in here. The plugin will not work without it.
Default value: false
When setting debug
to true
, the plugin will not check for stage === 'prod'
and instead always inject the GTM. Useful for debugging data layer events and such locally.
cookieRestriction?: {
cookieName: string;
value: string | number;
}
Only loads the GTM when a cookie is set to the supplied value.