Google Tag Manager Plugin

Sending relevant events downstream to your customer data platforms or analytics tools.

To find out how to use the Google Tag Manager, have a look at our Custom Insights (via GTM) section.

The Google Tag Manager plugin sends data to a Google Tag Manager (GTM) container already present on your client-side application when an <Experience> component remains in the viewport for a specified amount of time. This allows you to forward events representing impressions of experiments and personalizations to any tags you have configured in GTM, including any downstream analytics systems you have configured as tags.

Installation

To set up Ninetailed to send events to Google Tag Manager, you need to install Ninetailed's GTM plugin.

npm install @ninetailed/experience.js-plugin-google-tagmanager

Then, add the plugin to the Ninetailed instance:

import { NinetailedGoogleTagmanagerPlugin } from '@ninetailed/experience.js-plugin-google-tagmanager';
<NinetailedProvider
  // ...
  plugins={[
    new NinetailedGoogleTagmanagerPlugin()
  ]}
  componentViewTrackingThreshold={2000} // (Optional prop) Number, default = 2000
>
  //...
</NinetailedProvider>

Timing Configuration

The Google Tag Manager Plugin logs that an element has been seen only after the element has remained within the user's viewport for a specified amount of time (in milliseconds), determined by the value of the componentViewTrackingThreshold property on the Ninetailed instance (see code samples above). If the option is unspecified, the value defaults to 2000.

Default Data Layer Properties

Events sent from this plugin are named nt_experience. They are sent with five default properties:

Custom Event Properties

You can also define your own variables to push to GTM's data layer on each event by passing in a configuration object when instantiating the plugin. To do so, define a config object with a template property whose value is an object consisting of key-value pairs, where the key is the name of the property you want to add to the GTM data layer and the value is a string of the desired variable value surrounded by double curly braces ({{ }}).

Available Properties

Example Custom Use

This example shows passing the human-readable name of an audience to a custom data layer property titled ninetailed_audience_name. The default data layer properties are also pushed.

<NinetailedProvider
   // ...
    plugins={[
      new NinetailedGoogleTagmanagerPlugin({
        template: {
          ninetailed_audience_name: '{{ audience.name }}',
        },
      })
     ]}
     componentViewTrackingThreshold={2000}
  >
   //...
 </NinetailedProvider>

Last updated