Skip to content

How to Save user Activity in angular App? [closed]

I want to get and save user interaction with angular app, and app interactions with the APIs the add this log to a file.


If I understood your question correctly, you can write common logic on one place for user page navigation and API call.

For page navigation, subscribe to router events. Ex.

constructor(router:Router) { => {
    if(event instanceof NavigationStart) {
    if(event instanceof NavigationEnd) {
      // log record to file here --> 'user navigated to XYZ page.'
    // NavigationCancel
    // NavigationError
    // RoutesRecognized

For API calls, you can implement HTTP interceptor.

  providers: [{
    provide: HTTP_INTERCEPTORS, 
    useClass: TokenInterceptorService, 
    multi: true
export class AppModule { }

export class MyInterceptor implements HttpInterceptor {
  intercept( req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    // log record to file --> 'calling api {url}'
    return next.handle(req);