3.1.6 • Published 1 year ago

@zahooz/usage-tracker v3.1.6

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

usage-tracker

Installation

Using npm:

$ npm install --save @zahooz/usage-tracker

How to Initialize

Initialization of the tracker should be done once per page load, when your app is initialized. Please contact Nicholas Day to get the domain_id and api_url for your application. If you deploy your app to multiple platforms (e.g. dev, staging, prod) then you will be provided will a unique domain_id to use on each platform. The api_url will be consistent across platforms.

import UsageTracker from '@zahooz/usage-tracker';

UsageTracker.init(domain_id, api_url, {
  sessionTimeOut: 30 // defaults to 15 minutes if not provided
});
UsageTracker.listenRoutes();

The sessionTimeOut property in the config refers to the time of inactivity before a new tracking session is created. This will not effect sessions within your application, it is internal to the tracker.

Login Event

The tracker will only start tracking user activity once a user has logged in. To perform the login operation, you'll need to add the below script to the point in your code that a user logs in.
If a user is already logged in when they hit your site, you can just call this function once when the page loads.

Note that values for id, displayName and email are all required. If they are not provided, then a session will not be created, and no tracking will happen.

UsageTracker.login({
  id: '{external id of the user, e.g. DAYN02}',
  displayName: 'John Doe',
  email: 'test@test.com'
});

Logout Event

When the user logs out of your application, you should call the following to tell the tracker to end the user's session.

UsageTracker.logout();

Pause Tracking

For situations where you want to temporarily pause tracking, you can call the below function.

UsageTracker.pauseTracking();

Resume Tracking

If you're previously paused tracking, you can resume it again by calling the following function.

UsageTracker.resumeTracking();

Updating the Domain ID after initialization

If you need to update the domain ID after you've already initialized the Usage Tracker, for instance if you're serving multiple projects from the same single-page app, then you can just do the following.

UsageTracker.setDomain(domain_id);

Behind the scenes, this will start a new session for the user with the new domain.

Custom Events

You can create your own events to track whatever you want within your application. You just need to call the dispatch function, with an arbitrary string for your event name, and any JSON for the event payload, as shown below.

UsageTracker.dispatch('myCustomEvent', {
  test: '123',
});
2.0.7

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.8

2 years ago

3.0.7

2 years ago

3.0.5

2 years ago

3.0.0

2 years ago

2.0.15

2 years ago

2.0.16

2 years ago

2.0.13

2 years ago

2.0.14

2 years ago

2.0.11

2 years ago

2.0.12

2 years ago

2.0.10

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.1.6

1 year ago

3.1.4

1 year ago

2.0.17

2 years ago

2.0.18

2 years ago

2.0.6-dev

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.9-dev

3 years ago

1.0.7

3 years ago

1.0.10

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.0

3 years ago