Adding in Analytics

Let's add some analytics to track how people use the site and plugin a universal HTTP error handler.

Routing analytics

Let’s hook up some analytics trackers to Angular’s router. Instead of listening in on individual routes, this service needs to know about every route change. Generate a new service and attach it to the routing module with ng g service analytics.

⚠️ While working locally, make sure you’re on the latest version of the Angular CLI. Older versions will fail, with "Error: Specified module does not exist."

Open the fresh analytics.service.ts and modify it to add in some structure for recording routing changes:

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy