angular-gtag icon indicating copy to clipboard operation
angular-gtag copied to clipboard

Change default page_title

Open roffus opened this issue 6 years ago • 1 comments

In automatic tracking of Pageviews, is there a way to change page_title default value 'Angular App', to another value or to a real document title?

roffus avatar Dec 06 '18 10:12 roffus

Hi. I changed trackPageviews to false in app.module.ts : GtagModule.forRoot( { trackingId: '...', trackPageviews: false });

and set the page title on each page change using the following in ngOnInit() in app.component.ts :

this.router.events.subscribe(event => { if (event instanceof NavigationEnd) { this.gtag.pageview({ page_title: this.titleService.getTitle(), page_path: this.router.url, page_location: environment.server + this.router.url }); } });

(titleService is of type Title imported from @angular/platform-browser.)

But I'm not getting the gtagEvents -- i.e., in your example, gtagEvent trackOn="dragstart" action="product_dragged" category="ecommerce" [params]="{ event_label: 'Something cool just happened' }"

Is this because trackPageviews is set to false ?

If trackPageviews is set to true though, the same page will get two entries per visit -- one the default call to pageview() -- with page title "Angular App" and one for the call we make manually.

Any suggestions on how to also get the gtagEvent directive to work?

amarnathm avatar Dec 16 '18 08:12 amarnathm