Angular library that automatically injects the script tag required to use Google Tag Manager.
npm:
npm install --save @jerkovicl/ngx-gtm
Yarn:
yarn add @jerkovicl/ngx-gtm
Version | Angular Version |
---|---|
1.x.x |
>=17 <=18 |
- Automatically inject scripts for Google Tag Manager.
Import provideGtm
from ngx-gtm
and pass the required configuration when using it as a provider during application bootstrap.
import { provideGtm } from '@jerkovicl/ngx-gtm';
@NgModule({
providers: [
provideGtm({
enabled: true,
id: 'tag-id',
}),
],
})
export class AppModule {}
// Or if you are using standalone bootstrap
bootstrapApplication(AppComponent, {
providers: [
provideGtm({
enabled: true,
id: 'tag-id',
}),
],
});
Checkout the demo application in the demo folder for a working example.
The supported configuration parameters are:
Property | Requirement | Description |
---|---|---|
enabled | Required | Whether or not this module is enabled. Useful for disabling the script in development environments. |
id | Required | Your Google Tag Manager tag Id. This is found in the Google Tag Manager settings page. |
MIT