Angular Pageviews

Hi All,

Does anybody has experience with Angular application and have implemented some solution in order to track and record pageviews?

We are interested in to know how to capture those pageviews information and call a Caché REST Api in order to store those data.

Thanks.

  • 0
  • 0
  • 208
  • 5
  • 3

Answers

HI Fabio


I've built it into my Authentication routine on my REST services, as all of my functionality goes through REST.  I created a simple Audit class, and had each call to the Authentication include information specific to which service called it.

 

HTH

Chris

Hi Cris, 

Thanks! I am going contact you as suggested by Ben Spead. 

Later on I can post the solution over here.

 

Angular pages are often templates filled with data (via REST) and so it' possible to use that. In the root broker of the application add request tracking (who accessed what and when).

OnPreDispatch method works for that purpose.

/// This method Gets called prior to dispatch of the request. Put any common code here
/// that you want to be executed for EVERY request. If pContinue is set to 0, the
/// request will NOT be dispatched according to the UrlMap. If this case it's the
/// responsibility of the user to return a response.
ClassMethod OnPreDispatch(pUrl As %String, pMethod As %String, ByRef pContinue As %Boolean) As %Status
{
    Quit $$$OK
}

Pageviews is related to the UI side. Some UI can have acces to multiple API endpoints and it would not be a good approach. We have tried that already. Also they would not like to use Google Analytics.

Okay.

Another idea: you can define your session event class, and  set it as a session event class for your web application. That way you can track:

  • What pages and partials are requested
  • How long does the session lasts
  • How long does it take to execute the request

It will not work with Angular or any other modern web application and developed in right way. All pages opened without Cache at all. Web Application is made from static JavaScript, and this app can some time call REST on the server to fetch some data. And sessions now should be endless and stateless. You can only measure server's time.

It should not be a problem. I do Angular2+ application, but I have not done this logging. But, as far as I know, it is possible to subscribe to any routing changes.

import 'rxjs/add/operator/pairwise';
import { Router, ActivatedRoute } from '@angular/router;

export class AppComponent {

  constructor(
    private router: Router,
    private activatedRoute: ActivatedRoute) {
    
    this.router.events
        .filter(event => event instanceof NavigationStart)
        .subscribe((event:NavigationStart) => {
          console.log(event.url)
        });

    // OR
    this.activatedRoute.url.subscribe(url =>{
      console.log(url);
    });
  }

}

And you can then call any API as you want

Great! I am going to try that and call a rest api async in order to record that. We are concerned about a high volume of user access and have peformance issues.