Skip to content

Commit

Permalink
Fix config for callbacks (close #1275)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-el committed Dec 13, 2023
1 parent 26e826a commit fc3a354
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libraries/browser-tracker-core/src/tracker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ export function Tracker(
trackerConfiguration.retryStatusCodes ?? [],
(trackerConfiguration.dontRetryStatusCodes ?? []).concat([400, 401, 403, 410, 422]),
trackerConfiguration.idService,
trackerConfiguration.retryFailedRequests
trackerConfiguration.retryFailedRequests,
trackerConfiguration.onRequestSuccess,
trackerConfiguration.onRequestFailure
),
// Whether pageViewId should be regenerated after each trackPageView. Affect web_page context
preservePageViewId = false,
Expand Down
15 changes: 15 additions & 0 deletions libraries/browser-tracker-core/src/tracker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,21 @@ export type TrackerConfiguration = {
* @defaultValue true
*/
retryFailedRequests?: boolean;
/**
* a callback function to be executed whenever a request is successfully sent to the collector.
* In practice this means any request which returns a 2xx status code will trigger this callback.
*
* @param data - The event batch that was successfully sent
*/
onRequestSuccess?: (data: EventBatch) => void;

/**
* a callback function to be executed whenever a request fails to be sent to the collector.
* This is the inverse of the onRequestSuccess callback, so any non 2xx status code will trigger this callback.
*
* @param data - The data associated with the event(s) that failed to send
*/
onRequestFailure?: (data: RequestFailure) => void;
};

/**
Expand Down

0 comments on commit fc3a354

Please sign in to comment.