Plugins — Google Tag Manager

This is a plugin to help you capture events from GTM's (Google Tag Manager) dataLayer object. Currently, it focuses on GTM's Enhanced Ecommerce extension.

Installation

Install the npm modules:

npm install --save @miso.ai/client-sdk @miso.ai/client-sdk-gtm

In your app, import and setup the plugin:

import MisoClient from '@miso.ai/client-sdk';
import { GtmPlugin } from '@miso.ai/client-sdk-gtm';

MisoClient.plugins.use(GtmPlugin);

Basic Usage

The plugin captures Enhanced Ecommerce events from dataLayer and sends corresponding user interactions to the Miso API.

const client = new MisoClient('...');

client.gtm.ecommerce();

Enhanced Ecommerce

This module captures GTM Enhanced Ecommerce events and turns them into Miso user interactions automatically.

For example, if you start e-commerce tracking with default settings:

const client = new MisoClient('...');

client.gtm.ecommerce.start();

A push of such event to dataLayer:

window.dataLayer.push({
  ecommerce: {
    add: {
      actionField: { /*...*/ },
      products: [
        {
          id: 'a001',
          quantity: 3
          //...
        },
        {
          id: 'a002',
          quantity: 4
          //...
        }
      ]
    }
  }
});

Will result in this interaction sent to the Miso API:

client.api.interactions.upload({
  type: 'add_to_cart',
  product_ids: ['a001', 'a002'],
  quantities: [3, 4]
});

Default mapping

Untitled

Select events to track

You can specify a set of events to track inclusively:

client.gtm.ecommerce
  .accept('add', 'remove')
  .start();

Or exclusively:

client.gtm.ecommerce
  .accept('*', '-checkout')
  .start();

Custom event mapping

You can customize how events are mapped to Miso's interaction payloads:

client.gtm.ecommerce
  .mapping((eventKey, eventData) => {
    if (eventKey === 'add') {
      // some custom handling...
      return [
        {
          type: 'add_to_cart',
          product_ids: [/* ...*/],
          quantities: [/* ...*/],
        }
      ];
    }
    // fallback to default mapping
    return client.gtm.ecommerce.helper.defaultMapping(eventKey, eventData);
  })
  .start();

Stop tracking

Tracking can be stopped and resumed any time:

client.gtm.ecommerce.stop();

client.gtm.ecommerce.start();
Icon/Activity Icon/Add Icon/API Icon/Arrow/Down Icon/Arrow/Left Icon/Arrow/Right Icon/Arrow/TopRight Icon/Arrow/Up Icon/Bento Icon/Billing Icon/Bin Icon/Book Icon/Bookmark/Default Icon/Bookmark/Filled Icon/Calendar Icon/Caret/Down Icon/Caret/Up Icon/Chavron/DownIcon/Chavron/LeftIcon/Chavron/RightIcon/Chavron/UpIcon/Checknox/CheckedIcon/Checknox/Unchecked Icon/Checklist Icon/Chip Icon/Clipboard / Copied Icon/Clipboard/Default Icon/Clock/Stopwatch Icon/CMD Icon/Data/Catalog Icon/Data/Engine Icon/Data/Group Icon/Data/Interact Icon/Data/Users Icon/Dive Icon/Docs/Key Icon/Dojo Icon/Email Icon/Env/Development Icon/Env/Playground Icon/Env/Prod Icon/Folder Icon/Fullscreen/Collapse Icon/Fullscreen/Expand Icon/Guides/Multiple Icon/Guides/Single Icon/Hashtag Icon/Heart/Outline Icon/Heart/Solid Icon / Cart z Icon / Click Icon / Clock Icon / Data Icon / Doc Icon / EmptyCart z Icon/Social/Facebook Icon / Genome Incognito Icon / Money Icon/Social/ProductHunt Icon / Search Icon/Social/Twitter Icon / User Icon/Info/Error Icon/Info/Info Icon/Info/Question Icon/Info/Warning Icon/Interact/Download Icon/Interact/Edit Icon/Interact/External v2 Icon/Interact/External Icon/Interact/Filter Icon/Interact/Logout Icon/Interact/Options Icon/Interact/Re-order Icon/Interact/Reload Icon/Interact/Remove Icon/Interact/Replace Icon/Interact/Search Icon/Interact/Shuffle Icon/Interact/Undo Icon/Interact/Upload Icon/Interact/Video Icon/Invoice Icon/Loading Icon/Loading Icon/Lock/Locked Icon/Lock/Unlocked Icon/Lock Icon/Mapping Menu Icon/Notification Icon/Overview Icon/Person/Team Icon/Person/User Icon/Plan/Enterprise Icon/Plan/Growth Icon/Plan/Startup Icon/Plan/Trial Icon/Recipe Icon/Rocket Icon/Settings/App Icon/Settings/User Icon/Settings Icon/Shrine Icon/Sidebar/Close Icon/Sidebar/Open Icon/Slideout Icon/Sort/Ascending Icon/Sort/Default Icon/Sort/Descending Icon/Star/Filled Icon/Star/Outlined Stopwatch Icon/Support Icon/Tag Icon/Interact/Thumb/Dislike Icon/Interact/Thumb/Like Icon/Tick Icon/Trend/New Icon/Trend/Trending Icon/Tutorial Icon/Lock/Unlocked Icon/View/Grid Icon/View/List Icon/Watchlist/Add