The AnalyticsInterceptor
implements Angular's HttpInterceptor
interface and injects itself into your app's request-response chain. It will begin emitting events once you have initialized the library with a configuration that contains at least one destination.
The interceptor will dispatch an event for the start and completion (successful or not) for any HTTP call except for any destination URLs contained in your app configuration.
An ApiStartEvent
is dispatched when an HTTP request is sent. It is made up of the following properties.
Event property | Description |
---|---|
request | The HttpRequest object received by the interceptor. |
id | A string identifier that defaults to the target URL. This can be overridden by attaching an ApiEventContext to your call. |
scopes | An array of custom objects passed by attaching an ApiEventContext to your call. |
eventType | Always set to a value of 'API_START_EVENT'. |
location | The current location found in the Angular router when the call was made. |
An ApiCompleteEvent
is dispatched when an HTTP response is returned - successful or not. It is made up of the following properties.
Event property | Description |
---|---|
response | The response received as a result of the request . |
request | The HttpRequest object received by the interceptor. |
duration | The length of the call in milliseconds. |
id | A string identifier that defaults to the target URL. This can be overridden by attaching an ApiEventContext to your call. |
scopes | An array of custom objects passed by attaching an ApiEventContext to your call. |
eventType | Always set to a value of 'API_COMPLETE_EVENT'. |
location | The current location found in the Angular router when the call was made. |
When there is a need to associate more data to an API call, an ApiEventContext
object can be set on the HttpRequest.context
property and it will be dispatched with the different API events.
Property | Description |
---|---|
start | An ApiContext object to send with an ApiStartEvent |
success | An ApiContext object to send with a successful ApiCompleteEvent |
failure | An ApiContext object to send with a failed ApiCompleteEvent |
Property | Description |
---|---|
id | An identifier to use for the API call instead of the target URL |
scopes | An array of custom objects to attach to the event |
Is something not working or unclear? Please create an issue or PR.