-
Notifications
You must be signed in to change notification settings - Fork 190
Google Tag Manager
Scott Cooper edited this page Mar 11, 2018
·
10 revisions
The wiki is deprecated. Please see the project home or the provider folder for documentation
Add the full tracking code from Google Tag Manager to the beginning of your body tag.
Bootstrapping the application with Angulartics2
as provider and injecting both Angulartics2
and Angulartics2GoogleTagManager
(or any provider) into the root component will hook into the router and send every route change to your analytics provider.
// component
import { Angulartics2GoogleTagManager } from 'angulartics2';
import { Component } from '@angular/core';
@Component({
selector: 'app',
template: `<router-outlet></router-outlet>`
})
export class AppComponent {
constructor(angulartics2GoogleTagManager: Angulartics2GoogleTagManager) {}
}
// bootstrap
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, Routes } from '@angular/router';
import { Angulartics2Module, Angulartics2GoogleTagManager } from 'angulartics2';
const ROUTES: Routes = [
{ path: '', component: HomeComponent },
{ path: 'about', component: AboutComponent }
];
@NgModule({
imports: [
BrowserModule,
RouterModule.forRoot(ROUTES),
Angulartics2Module.forRoot([ Angulartics2GoogleTagManager ])
],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
Now is the time to setup tracking for the tags in GTM. Here is a great post on how to actually perform this setup. In essence here is the TLDR:
- Create a new tag
- Add Universal Analytics + Tracking ID from GA
- Create a new "Fire On" trigger (Custom Event) that tracks the
Page View
(forpageTrack()
)
Make sure to debug it :D