Initialize options
First step is to initialize the async devunusClient.init()
User Context
Use the user_id
and user_name
to target features and generate analytics at the user level.
environment key is unique to each environment
import { devunusClient } from "@devunus/js-client-sdk";
const context: Context = {
user_id: 'your users id', // optional if added will allow flag targeting and generate user analytics
user_name: 'your users name', // optional, allows easier user searches
user_email: 'your users email', // optional, useful for user targeting
};
devunusClient.init(env_key, context);
B2B/Saas Options
Use the company_id
and company_name
to target features and generate analytics at the organization level.
import { devunusClient } from "@devunus/js-client-sdk";
const context: Context = {
...
company_id: 'users organization/account id', // optional if added will allow flag targeting and generate organization analytics
company_name: 'company name' // optional, used to make searchable in analytics
};
devunusClient.init(env_key, context);
Release Analytics
Use the git_commit
or app_name
to generate release analytics.
import { devunusClient } from "@devunus/js-client-sdk";
const context: Context = {
...
app_name 'app or service name' // optional if added will drive release dashboard
app_version: '1.0.0' // optional if added will drive release dashboard
git_commit: 'GIT_SHA' // optional if added will generate release data
};
devunusClient.init(env_key, context);
User Traits
Use the user_traits
to provide additional user information.
const context: Context = {
...
user_traits: {
plan: 'pro',
company_size: '1-10',
};
devunusClient.init(env_key, context);
Advanced Options
Http Path grouping
To enable url path grouping by default Ids are replaced with an *
in the path. The default implementation will replace UIDs with an *
.
If you use other id formats you can override this behavior by providing a removeIds
function.
devunusClient.init('key', {
...,
urlRemoveIds: removeIds
});
/* this function will replace account ID in admin routes with * and project ID with * */
function removeIds(path: string): string {
return path
// Replace account ID in admin routes with *
.replace(/\/admin\/[a-zA-Z0-9]+(?=\/|$)/g, '/admin/*')
// Replace project ID (number only) with *
.replace(/\/project\/\d+(?=\/|$)/g, '/project/*');
}
describe('remove IDs from paths to allow api call grouping', () => {
test('should replace account ID and project ID in routes with *', () => {
expect(removeIds('/admin/abc1236/project/1/metrics/')).toBe('/admin/*/project/*/metrics/');
});
});