IdentityContext
IdentityContext enables cross session, platform and device tracking.
Installation
yarn add @objectiv/plugin-identity-context
or
npm install @objectiv/plugin-identity-context
Implementation
Implements PluginInterface's enrich
method.
enrich
Creates one or more instances of IdentityContext as configured at construction.
isUsable
Always true.
Configuration
The plugin's constructor accepts one of the following configurations:
- an IdentityContextAttributes object
- an array of IdentityContextAttributes objects
- a function returning an IdentityContextAttributes object
- a function returning an array of IdentityContextAttributes objects
IdentityContextAttributes
type IdentityContextAttributes = {
id: string;
value: string;
}
- The
id
property specifies the scope of identification. - The
value
is the actual identifier within the scope defined byid
.
Usage
In this example we assume to have a cookie called backend_user
holding an identifier of the currently logged-in user.
import { DebugTransport } from "@objectiv/transport-debug";
import { IdentityContextPlugin } from "@objectiv/plugin-identity-context";
import { ReactTracker } from "@objectiv/tracker-react";
import Cookies from 'js-cookie';
const userId = Cookies.get('backend_user');
const tracker = new ReactTracker({
applicationId: 'app-id',
transport: new DebugTransport(),
plugins: [
new IdentityContextPlugin({
id: 'backend',
value: userId
})
],
});