@zahooz/usage-tracker v3.1.6
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 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago