easily-gtm
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

Simple Google Tag Manager

Simple GTM library for Angular 7+

Open issues licence version angular

Install

  • Run npm install easily-gtm --save-dev
  • Create a attribute on environment config:
export const environment = {
  production: false,
  tagManagerId: 'GTM-XXXXXXX',
};
  • Import on main.js:
import { EasilyGtmService } from 'easily-gtm/easily-gtm.service';
  • Implement function generate on <header> and <body>:

This function create the script and no-script tags.

EasilyGtmService.generate(environment.tagManagerId);

Using

This library has one function only: push

  • Import the library
import { EasilyGtmService } from 'easily-gtm/easily-gtm.service';
  • Include on components' constructor
constructor(private egtm: EasilyGtmService) {}
  • Use the method:
this.egtm.push('vpageview', {'page': '/teste'});

The mothod has two params: event, params:

Event

This attribute is a String and receive the event.

Example: vpageview, ga-event, ga-exception

Params

This attribute is a object with this format:

{
  'page': 'value'
}

or

{
  'category': 'your category',
  'action': 'your action',
  'label': 'your label'
}

or

{
  'category': 'your category',
  'action': 'your action',
  'value': 'your value'
}

Package Sidebar

Install

npm i easily-gtm

Weekly Downloads

3

Version

2.0.1

License

MIT

Unpacked Size

92.8 kB

Total Files

21

Last publish

Collaborators

  • regivaldorfs