ngx-google-analytics
ngx-google-analytics copied to clipboard
Logging errors via this.$gaService.event?
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!
I believe the lib should log erros on console in development mode...
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