@aubrey
To use Google Tag Manager with Angular 4 correctly, follow these steps:
1
|
npm install angular-google-tag-manager --save |
1 2 3 4 5 6 7 8 9 10 11 12 |
import { AngularGoogleTagManagerModule } from 'angular-google-tag-manager'; @NgModule({ imports: [ ... AngularGoogleTagManagerModule.forRoot({ id: 'YOUR-GTM-ID' }) ], ... }) export class AppModule { } |
Replace 'YOUR-GTM-ID'
with your actual Google Tag Manager Container ID.
1 2 3 4 5 6 7 8 |
<head> ... </head> <body> <app-root> <gtm></gtm> </app-root> </body> |
1 2 3 4 5 6 7 8 9 10 11 12 |
import { GtmService } from 'angular-google-tag-manager'; @Component({ ... }) export class MyComponent { constructor(private gtmService: GtmService) { } trackEvent() { this.gtmService.pushEvent('eventCategory', 'eventAction', 'eventLabel', 'eventValue'); } } |
By following these steps, you can integrate Google Tag Manager with Angular 4 and track events and data on your website effectively.