@sho-js/analytics
v6.0.2
Published
## Installation
Downloads
4
Readme
Wearesho Analytics
Installation
npm i --save @sho-js/analytics
Usage
Setup
Create instance of WeareshoAnalytics.Service with following params:
import * as WeareshoAnalytics from "@sho-js/analytics";
const axiosInstance = Axios.create({baseURL: "https://wearesho.public.api.com/"});
const token = ""; // your way to receive unique fingerprint value
const components = {
resolution: "1920,1080",
offset: 3,
// ... other key/value pairs
};
const fingerPrint: FingerPrint = { token, components }
const analytics = await WeareshoAnalytics.Service.create(axiosInstance, fingerPrint);
where
axiosInstance
- instance of Axios. Required.fingerPrint
- fingerprint data. Required.
Actions
analytics.action("some unique action name");
analytics.input("fieldName", ["valuePrev", "valueNext"]);
analytics.user(1 /* UserId */);
Helpers
const actionHandler = analytics.handler(analytics.action, "some unique action name");
const inputHandler = analytics.handler(analytics.input, "fieldName", ["valuePrev", "valueNext"]);
const userHandler = analytics.handler(analytics.input, 1);
<button onClick={actionHandler}/>
<button onClick={inputHandler}/>
<button onClick={userHandler}/>