0.0.4-alpha.28 • Published 8 months ago

@brainfish-ai/web-tracker v0.0.4-alpha.28

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

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,
  // trackAttributes: true,
  // trackOutgoingLinks: true,
});

Config

Ready!

You're now ready to use the library.

// Sends an event with payload foo: bar
tracker.event('my_event', { foo: 'bar' });

// Identify with user id
tracker.setUserId('123');

// or with additional data
tracker.setUser({
  userId: '123',
  firstName: 'John',
  lastName: 'Doe',
  email: 'john.doe@brainfi.sh',
});

// Increment a property
tracker.increment('app_opened'); // increment by 1
tracker.increment('app_opened', 5); // increment by 5

// Decrement a property
tracker.decrement('app_opened'); // decrement by 1
tracker.decrement('app_opened', 5); // decrement by 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,
  // firstName?: string;
  // lastName?: string;
  // email?: string;
  // avatar?: string;
  // properties?: Record<string, unknown>;
});

Increment property

Increment a property on the user.

// Increment by 1
tracker.increment('app_opened');

// Increment by 5
tracker.increment('app_opened', 5);

Decrement property

Decrement a property on the user.

// Increment by 1
tracker.decrement('app_opened');

// Increment by 5
tracker.decrement('app_opened', 5);

Clear / Logout

Clear the user id and all the data.

tracker.clear();
0.0.4-alpha.26

8 months ago

0.0.4-alpha.25

8 months ago

0.0.4-alpha.28

8 months ago

0.0.4-alpha.22

8 months ago

0.0.4-alpha.21

8 months ago

0.0.4-alpha.24

8 months ago

0.0.4-alpha.23

8 months ago

0.0.4-alpha.20

8 months ago

0.0.4-alpha.19

8 months ago

0.0.4-aplha.19

8 months ago

0.0.4-alpha.18

8 months ago

0.0.4-alpha.17

8 months ago

0.0.4-alpha.16

8 months ago

0.0.4-alpha.15

8 months ago

0.0.4-alpha.13

9 months ago

0.0.4-alpha.12

9 months ago

0.0.4-alpha.11

9 months ago

0.0.4-alpha.10

9 months ago

0.0.4-alpha.9

9 months ago

0.0.4-alpha.8

9 months ago

0.0.4-alpha.7

9 months ago

0.0.4-alpha.6

9 months ago

0.0.4-alpha.5

9 months ago

0.0.4-alpha.4

9 months ago

0.0.3-alpha.3

9 months ago

0.0.2-alpha.2

9 months ago

0.0.1-alpha.1

9 months ago

0.0.1-alpha.0

9 months ago