UNPKG

@arcblock/analytics-js

Version:

Analytics Javascript SDK for API Service by ArcBlock

88 lines (62 loc) 2.25 kB
# [**@arcblock/analytics-js**](https://github.com/arcblock/arc-javascript-sdk) [![build status](https://img.shields.io/travis/ArcBlock/arc-javascript-sdk.svg)](https://travis-ci.org/ArcBlock/arc-javascript-sdk) [![code coverage](https://img.shields.io/codecov/c/github/ArcBlock/arc-javascript-sdk.svg)](https://codecov.io/gh/ArcBlock/arc-javascript-sdk) [![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier) [![license](https://img.shields.io/github/license/ArcBlock/arc-javascript-sdk.svg)](LICENSE) > Analytics Javascript SDK for ArcBlock for both Node.js and Browser > > If you are using this SDK in browser environment, [babel-polyfill](https://babeljs.io/docs/en/babel-polyfill) is required. ## Table of Contents - [**@arcblock/analytics-js**](#arcblockanalytics-js) - [Table of Contents](#table-of-contents) - [Install](#install) - [Usage](#usage) - [In Browser](#in-browser) - [Browser Compatibility](#browser-compatibility) - [In Node.js](#in-nodejs) ## Install ```sh npm install @arcblock/analytics-js // or yarn add @arcblock/analytics-js ``` ## Usage ### In Browser ```javascript 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 ```javascript 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')); ```