maxandriani / ngx-google-analytics

An easy way to use and configure Google Analytics on Angular 6+ applications
MIT License
120 stars 49 forks source link

Logging errors via this.$gaService.event? #67

Open Wiljanneman opened 3 years ago

Wiljanneman commented 3 years ago

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!

maxandriani commented 2 years ago

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

kurtiev commented 2 years ago

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