@sho-js/analytics

npm i --save @sho-js/analytics

Usage no npm install needed!

<script type="module">
  import shoJsAnalytics from 'https://cdn.skypack.dev/@sho-js/analytics';
</script>

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}/>