Search code examples
angularcordovaionic-frameworkgoogle-tag-manager

How can I change the title of an ionic app


My App is connected withe the GTM (Google Tag Manager). I want to see all page views from the users, but i only see the Ionic App. the title in the index.html is static, but can i do this dynamic?


Solution

  • In your app.component.ts file import Title class from @angular/platform-browser and add it in the constructor. Then add the code mentioned below

    ngOnInit() {
        this.router.events
          .pipe(filter((event) => event instanceof NavigationEnd))
          .subscribe((event: any) => {
            const title = event.url;
            this._title.setTitle(`${title}`);
          });
      }
    

    This way, you will be able to change the title of your index.html file.