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 key in our AsyncStorage called @backend_user
holding an identifier of the
currently logged-in user.
import AsyncStorage from '@react-native-async-storage/async-storage';
import { DebugTransport } from "@objectiv/transport-debug";
import { IdentityContextPlugin } from "@objectiv/plugin-identity-context";
import { ReactNativeTracker } from "@objectiv/tracker-react-native";
const getUser = async () => {
const userId = await AsyncStorage.getItem('@backend_user')
const tracker = new ReactNativeTracker({
applicationId: 'app-id',
transport: new DebugTransport(),
plugins: [
new IdentityContextPlugin({
id: 'backend',
value: userId
})
],
});
}