Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

98
Views
Not able to push data to data layer on each page in angular 9

I am trying to add GTM snippet to my angular project. But on hard reload of page it's pushing data. On normal navigation it doesn't.

I have added GTM snippet provided by Google to index.html. what is the next step I need to do?

What I want is push dta to dataLayer on each page navigation or on Ngonit of each page?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

there are a lot of implemented angular modules which are wrapping interaction with GTM and provide some tools, for instance this one https://www.npmjs.com/package/angular-google-tag-manager here is how you can push event on each route change

class AppComponent implements OnInit {

    constructor(
       private router: Router,
       private gtmService: GoogleTagManagerService,
    ) { }

    ngOnInit() {
    
         this.router.events.subscribe(event=> {
             if (event instanceof NavigationEnd) {
                const gtmTag = {
                        event: 'page',
                        pageName: event.url
                      };
        
                this.gtmService.pushTag(gtmTag);
              }
         });
    }
}

also, you can move this logic to Guard (do not forget in such case to add it for routing)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!