openreplay/tracker/tracker-fetch
2021-05-03 13:31:55 +02:00
..
src feat: tracker init 2021-05-03 13:31:55 +02:00
.gitignore feat: tracker init 2021-05-03 13:31:55 +02:00
.npmignore feat: tracker init 2021-05-03 13:31:55 +02:00
.prettierrc.json feat: tracker init 2021-05-03 13:31:55 +02:00
LICENSE feat: tracker init 2021-05-03 13:31:55 +02:00
package-lock.json feat: tracker init 2021-05-03 13:31:55 +02:00
package.json feat: tracker init 2021-05-03 13:31:55 +02:00
README.md feat: tracker init 2021-05-03 13:31:55 +02:00
tsconfig-cjs.json feat: tracker init 2021-05-03 13:31:55 +02:00
tsconfig.json feat: tracker init 2021-05-03 13:31:55 +02:00

OpenReplay Tracker Fetch plugin

Tracker plugin to support tracking of the fetch requests payload. Additionally it populates the requests with sessionID header for backend logging.

Installation

npm i @openreplay/tracker-fetch

Usage

Initialize the @openreplay/tracker package as usual and load the plugin into it. Then you can use the provided fetch method from the plugin instead of built-in.

import Tracker from '@openreplay/tracker';
import trackerFetch from '@openreplay/tracker-fetch';

const tracker = new Tracker({
  projectKey: YOUR_PROJECT_KEY,
});
tracker.start();

export const fetch = tracker.use(trackerFetch({
  sessionTokenHeader: 'X-Session-ID', // optional
  failuresOnly: true //optional
}));

fetch('https://my.api.io/resource').then(response => response.json()).then(body => console.log(body));

In case you use OpenReplay integrations (sentry, bugsnag or others), you can use sessionTokenHeader option to specify the header name. This header will be appended automatically to the each fetch request and will contain OpenReplay session identificator value.

Set failuresOnly option to true if you want to record only requests with the status code >= 400.