ecommerce-gtm

1.0.0 • Public • Published

ecommerce-gtm

Google Tag Manager Module for Enhanced Ecommerce

This is a Javascript module that implement Google Tag Manager for enahanced ecommerce. It is designed to use GTM snippet.

You can easily use custom dataLayer and additional events. You can use this library in any javascript framework for example:

  • react
  • angular
  • vue etc..

Installation

npm:

npm install ecommerce-gtm --save

Usage

Initializing GTM Module:

import GTagManager from 'ecommerce-gtm'
 
# With default dataLayer
GTagManager.initialize({ id: "GTM-000000" });
 
with custom data layer
GTagManager.initialize({ id: "GTM-000000", layer: "dataLayer2" });
 

Enhanced Ecommerce

Event example:

import GTagManager from 'ecommerce-gtm'
 
# With default dataLayer
GTagManager.initialize({ id: "GTM-000000" });
 
# Attach ecommerce to an event
GTagManager.event("test", {
    'currencyCode': 'EUR',
    'impressions': [
     {
       'name': 'Triblend Android T-Shirt',
       'id': '12345',
       'price': '15.25',
       'brand': 'Google',
       'category': 'Apparel',
       'variant': 'Gray',
       'list': 'Search Results',
       'position': 1
     }]
  })

Ecommerce only example:

If you do not want to attach ecommerce obj to event try this:

import GTagManager from 'ecommerce-gtm'
 
# With default dataLayer
GTagManager.initialize({ id: "GTM-000000" });
 
# Attach ecommerce to an event
GTagManager.ecommerce({
    'currencyCode': 'EUR',
    'impressions': [
     {
       'name': 'Triblend Android T-Shirt',
       'id': '12345',
       'price': '15.25',
       'brand': 'Google',
       'category': 'Apparel',
       'variant': 'Gray',
       'list': 'Search Results',
       'position': 1
     }]
  })

Note:

  • Disabling javascript in the browser can prevent the correct operation of this library.

Package Sidebar

Install

npm i ecommerce-gtm

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

7.1 kB

Total Files

11

Last publish

Collaborators

  • learn2torials