@tokenscript/analytics-client
v0.4.0
Published
This is the client SDK for Analytics
Downloads
13
Keywords
Readme
Analytics Client
This is the client SDK for Analytics
Install
npm install --save @tokenscript/analytics-client
How to use
- Initialize the sdk client
The analytics client will generate a distinctId(uuid) to be used for the following event report and user identification.
import Analytics from '@tokenscript/analytics-client';
const analyticsUrl = "http://127.0.0.1:3006";
// jwt token is generated per client_id/brand/campaign
const jwtToken = "eyJhbGciOiJIUzI...";
const analytics = new Analytics(analyticsUrl, jwtToken);
- Hook with Token Negotiator
By connecting to the tokenNegotiator, all the concerned events triggered from tokenNegotiator will be reported automatically.
// accept the token negotiator instance
analytics.connectTokenNegotiator(window.tokenNegotiator);
- Manual user/event report
When Token Negotiator is not used or a custom event outside of Token Negotiator need to be reported, user can perform manual report by directly accessing the tRPC client
// Report event (timestamp is added automatically)
analytics.client.event({
name: "customer-event",
properties: {...}
});
// Identify user
analytics.client.user({
email: "[email protected]",
chain_id: 1,
wallet_address: "0x123abc..."
});