autonomous-analytics
v1.0.18
Published
Event tracking package for Autonomous Product
Downloads
26
Readme
Autonomous Analytics
Event tracking package for Autonomous products. This can be used on:
- Web (JS, framework-independent)
- React Native
- Node.JS
Installation
npm install --save autonomous-analytics
Usage
Initialize
clientSecret
is required for the library to work. Please contact Data team to obtain clientSecret for your product.
import ApiCaller from 'autonomous-analytics';
const caller = new ApiCaller({ clientSecret });
Optional options:
persistData: (key: string, value: string) => void
to override the persistData built-in
getData: (key: string) => void
to override the getData built-in
Event tracking
An event is an action of the user on your product. It could be a page load, a click on a specific button, and any other actions that you want to track.
Quick and dirty code to get started with event tracking:
import ApiCaller from 'autonomous-analytics';
const clientSecret = '<your client secret>';
const caller = new ApiCaller({ clientSecret });
const eventName = 'test_event_name';
const eventParams = [
{ key: 'event_key_1', value: 'event_value_1' },
{ key: 'event_key_2', value: 'event_value_2' },
]
const platform = 'web';
const userId = 1;
const response = caller.trackEvent({
eventName: eventName,
userId,
eventParams,
platform,
});
console.log(response);
References:
trackEvent()
Track a specific event
Params:
eventName
: Name of your event (required)userId
: logged in user_iduserPseudoId
: an ID represent a unique user accessing Autonomous product. For web-based products, you can use device fingerprint method to generate an pseudo ID.platform
:web
,android
orios
are accepted values. Default isweb
eventParams
: an array of parameters you may use to differentiate events. For example, you may attach button names, links name, page section names, and any other data you may need for further analyze user activities. This array consists of one or more { key, value } objects.
trackPageView()
Alias for caller.trackEvent()
, but with less parameters. You may use this function to track pageview for your product
Params:
pageName
: Name of your page (web) or screen (app) (required)platform
: Name of your platform, default toweb
trackComponentLoadTime()
Alias for caller.trackEvent()
, but with less parameters. You may use this function to track component load time for your product.
For component load, a prefix of component_load_
will be added to your component's name for data storage and query.
Params:
componentName
: Name of your componentstartTime
: When the component is starting to loadendTime
: When the component finishes loading