react-static-plugin-google-tag-manager

A react-static plugin allowing you to add the GTM script tag to your page

Usage no npm install needed!

<script type="module">
  import reactStaticPluginGoogleTagManager from 'https://cdn.skypack.dev/react-static-plugin-google-tag-manager';
</script>

README

react-static-plugin-google-tag-manager 📈

License David dependencies

This plugin adds the GTM script tag to your HTML files. You only need to supply the GTM ID.

Installation

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,
      },
    ],
  ],
};

Options

In your static.config.js, you should pass configuration options to the plugin.

id: string

Pass your Google Tag Manager ID in here. The plugin will not work without it.

debug: boolean

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: object

cookieRestriction?: {
  cookieName: 'string';
  value: 'string' | 'number';
}

Only loads the GTM when a cookie is set to the supplied value.