@d-cat/tag-template-google-tag-manager
TypeScript icon, indicating that this package has built-in type declarations

1.8.0 • Public • Published

Tag Template: @d-cat/tag-template-google-tag-manager

codecov

Tag Template that injects Google Tag Manager in head of a web page.

Install

npm i @d-cat/tag-template-google-tag-manager

Usage

The Tag Template accepts 1 argument: id.

property type description
id string Google Tag Manager Container ID.
import GoogleTagManager from '@d-cat/tag-template-google-tag-manager';

const myGTMComponent = async () => {
  const id = 'GTM-XXXXXX';
  const gtm = new GoogleTagManager(id);

  return await gtm.render();
};

render(): Promise<boolean>

You can inherit the render method. The method injects the Google Tag Manager script, if it does not already exist.

import GoogleTagManager from '@d-cat/tag-template-google-tag-manager';

export default class MyClass extends GoogleTagManager {
  constructor(...props: any[]) {
    super(...props);
  }

  public async render(...args: any[]): Promise<boolean> {
    await super.render(...args);

    // here you can add your own logic.
  }
}

/@d-cat/tag-template-google-tag-manager/

    Package Sidebar

    Install

    npm i @d-cat/tag-template-google-tag-manager

    Weekly Downloads

    16

    Version

    1.8.0

    License

    ISC

    Unpacked Size

    10.9 kB

    Total Files

    5

    Last publish

    Collaborators

    • d-cat