@arcblock/analytics-js

Analytics Javascript SDK for API Service by ArcBlock

Usage no npm install needed!

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

README

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