@arcblock/analytics-js

0.19.0 • Public • Published

@arcblock/analytics-js

build status code coverage styled with prettier license

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');

// init client
SDK.initialize('ocap_playground');

// set param
SDK.set('userId', 123455);

// all param values are converted to underscore_case
const result = await SDK.event({
  category: 'interaction', // only `activity` and `interaction` supported
  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) => {
  // in production, you should not wait for event sending complete
  const result = await req.ABA.event({
    category: 'activity', // only `activity` and `interaction` supported
    action: 'submit',
    type: 'order',
    label: '123456',
    data: {},
  });

  res.jsonp(result);
});

app.listen(3000, () => console.log('server started'));

Package Sidebar

Install

npm i @arcblock/analytics-js

Weekly Downloads

1

Version

0.19.0

License

Apache-2.0

Unpacked Size

314 kB

Total Files

18

Last publish

Collaborators

  • gxw
  • mave99a
  • polunzh
  • wangshijun