@d-cat/tag-template-google-tag-manager
v1.8.0
Published
D-CAT Google Tag Manager Tag Template.
Downloads
3
Maintainers
Readme
Tag Template: @d-cat/tag-template-google-tag-manager
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.
}
}