Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

ERROR ReferenceError: gtag is not defined when running npm run build:prerender #681

@kuncevic

Description

@kuncevic

Hi there, thank you guys for a great universal starter project that was really useful to me.

I just added the gtag to be able to track the google analytics router change event in my application that based on the universal starter.

Then when I run npm run build:prerender that giving me an error ERROR ReferenceError: gtag is not defined

I modified the starter with this code :

export class AppComponent implements OnInit {
  constructor(public router: Router) {}

  ngOnInit() {
    const navEndEvent$ = this.router.events.pipe(filter(e => e instanceof NavigationEnd));
    navEndEvent$.subscribe((e: NavigationEnd) => {
      gtag('config', 'UA-xxxxxxxxx-x', { page_path: e.urlAfterRedirects });
    });
  }
}

So you can reproduce it by cloning https://github.com/kuncevic/universal-starter

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions