easily-gtm

Easily library to Google Tag Manager by Angular 5+

Usage no npm install needed!

<script type="module">
  import easilyGtm from 'https://cdn.skypack.dev/easily-gtm';
</script>

README

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'
}