Analytics Javascript SDK for ArcBlock for both Node.js and Browser
If you are using this SDK in browser environment, babel-polyfill is required.
Table of Contents
Install
npm install @arcblock/analytics-js
// or
yarn add @arcblock/analytics-js
Usage
In Browser
const SDK = require('@arcblock/analytics-js');
SDK.initialize('ocap_playground');
SDK.set('userId', 123455);
const result = await SDK.event({
category: 'interaction',
action: 'click',
type: 'button',
label: 'run_query',
data: {},
});
const result2 = await SDK.pageview('/');
Browser Compatibility
TO BE DONE
In Node.js
Usually on server side
const express = require('express');
const ABA = require('@arcblock/analytics-js');
const app = express();
app.use(ABA.initializeExpress('ocap_widget'));
app.use(async (req, res, next) => {
const result = await req.ABA.event({
category: 'activity',
action: 'submit',
type: 'order',
label: '123456',
data: {},
});
res.jsonp(result);
});
app.listen(3000, () => console.log('server started'));