ngx-google-analytics icon indicating copy to clipboard operation
ngx-google-analytics copied to clipboard

Logging errors via this.$gaService.event?

Open Wiljanneman opened this issue 3 years ago • 2 comments

Hi I was wondering if it were possible to globally log any errors on a window via the event function? Or do you have any suggestions perhaps?

Thanks in advance!

Wiljanneman avatar Jun 25 '21 11:06 Wiljanneman

I believe the lib should log erros on console in development mode...

maxandriani avatar Feb 14 '22 14:02 maxandriani

try/catch probably, and:

import { ErrorHandler } from '@angular/core';

@Injectable()
export class GlobalErrorHandler implements ErrorHandler {

constructor(
    private $gaService: GoogleAnalyticsService
  ) {} 
 
  handleError(error) {
    // your custom error handling logic    
     this.$gaService.event('error', 'globalErrorHandler', 'Trololo');
  }
}

...

@NgModule({   
  providers: [{provide: ErrorHandler, useClass: GlobalErrorHandler}]
})

https://medium.com/angular-in-depth/expecting-the-unexpected-best-practices-for-error-handling-in-angular-21c3662ef9e4

kurtiev avatar Jun 15 '22 13:06 kurtiev