Web SDK
Installation
Steps to install the Brainfish Tracker SDK in your web application.
Install dependencies
npm install @brainfish-ai/web-tracker
Initialize
import { Tracker } from '@brainfish-ai/web-tracker';
const tracker = new Tracker({
accessKey: '{accessKey}',
trackScreenViews: true,
});
Config
Ready!
You're now ready to use the library.
tracker.event('my_event', { foo: 'bar' });
tracker.setUserId('123');
tracker.setUser({
userId: '123',
firstName: 'John',
lastName: 'Doe',
email: 'john.doe@brainfi.sh',
});
tracker.increment('app_opened');
tracker.increment('app_opened', 5);
tracker.decrement('app_opened');
tracker.decrement('app_opened', 5);
Usage
Track event
tracker.event('my_event', { foo: 'bar' });
Identify
Set user Id
Keep track of your users by identifying them with a unique id. This is a good features if you have things behind a login and want to track user behavior.
const userId = '123';
tracker.setUserId(userId);
Additional data
This method does the same as setUserId
but also allows you to update the user with additional data.
const userId = '123';
tracker.setUser({
userId,
});
Increment property
Increment a property on the user.
tracker.increment('app_opened');
tracker.increment('app_opened', 5);
Decrement property
Decrement a property on the user.
tracker.decrement('app_opened');
tracker.decrement('app_opened', 5);
Clear / Logout
Clear the user id and all the data.
tracker.clear();