Mike O.
Mike O.

Reputation: 1045

Capturing hash routes using google analytics in Angular 5 application

All of my application route is based on "/#/". For example "/#/home", "/#/contact" and so on . Nut all I see in my google analytics is "/" route. Which means it's dumping my hash routes following "#". Is there any way to capture those routes on my google analytics? Thank you all in advance.

Upvotes: 0

Views: 855

Answers (2)

Mike O.
Mike O.

Reputation: 1045

I have found a solution, You can just fire

gtag('config', 'YOUR_ID' , { 'page_path': location.pathname + location.hash }); by subscribing to route.events which will fire the above code every time the routes changes

Upvotes: 1

Suresh Kumar Ariya
Suresh Kumar Ariya

Reputation: 9764

It is recommended to use the HTML 5 style (PathLocationStrategy) as location strategy in Angular. Don't use Hash Location Stratergy.

Because

1) It produces the clean and SEO Friendly URLs that are easier for users to understand and remember.

2) You can take advantage of the server-side rendering, which will make our application load faster, by rendering the pages in the server first before delivering it the client.

Use Hashlocationstrtegy only if you have to support the older browsers.

Upvotes: 0

Related Questions