Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

analytics-web3

xorddotcom41UNLICENSED1.5.0TypeScript support: included

Spock analytics SDK analytics-web3 is a js module to collect and log all the data and events of DApp for analytics.

spock, web3-analytics, web3, dapp-analytics, token-analytics, analytics

readme

Spock Analytics SDK

Spock analytics SDK analytics-web3 is a Javascript module to collect and log all the data and events of DApp for analytics.

Spock

Spock aims to accelerate your growth by tracking & analyzing crucial and opportunity-centric metrics that will help you to amplify your growth and reach to the right customer segment.

Table of contents

Installation

Install analytics-web3 sdk by using npm

npm install --save analytics-web3

or yarn

yarn add analytics-web3

Usage

Initialize and track wallet connection and transactions by passing web3 provider.

import Web3Analytics from 'analytics-web3';
Web3Analytics.init({ appKey: 'eba6...28c' });
Web3Analytics.walletProvider(window.ethereum);

API

Web3Analytics.init(options)

Web3Analytics must be initialized with appKey by invoking init method at the top level of application before using other methods.

Web3Analytics.init({ appKey: 'eba6...28c', debug: true });
Value Type Description
appKey String Unique appKey like eba6...28c for tracking. Can be obtained by getting onboarded in Spock.
Optional |
debug Boolean Defaults to false. Enable consoles for all the tracking events.
dataPoints string[] By default SDK will track all data points. But you can limit them by passing the desired datapoints.
inactivityTimeout number Defaults to 30. This field takes time in mins to specify the inactivity duration in which the session will expires.
optOut Boolean Defaults to false. Opt users out of tracking.
testENV Boolean Defaults to false. Enable testing version of SDK in which SDK will interact with testing servers.
testMode Boolean Defaults to false. Enable testMode in which you can test tracking events without logging data onto server. Inordre to avoid store testing data.

Web3Analytics.walletProvider(provider)

Pass web3 provider to track wallet connections for all Supporting Wallets and transactions state that are submitted or rejected from DApp.

Web3Analytics.walletProvider(window.ethereum);

In-case of handling multiple wallets on DApp. Example in React.

import { useWeb3React } from '@web3-react/core';

const { provider } = useWeb3React();

// in-order to pass updated provider if user changes wallet, account or chain.
useEffect(() => {
  if (provider?.provider) {
    Web3Analytics.walletProvider(provider.provider);
  }
}, [provider]);
Value Type Description
provider Web3Provider EIP-1193 Standard Provider or Web3Provider-compatible Provider.

Web3Analytics.trackWalletConnection(walletType,account,chainId)

To track other wallets that currently not include in Supporting Wallets.

Web3Analytics.trackWalletConnection('Ledger', '0x...96', 1);
Value Type Description
walletType String Name of wallet
account String User ethereum address
chainId number User connected chainId

Web3Analytics.trackPageView(pathname,search)

Track all the pages visited on a DApp.

Web3Analytics.trackPageView('/home');
Value Type Description
pathname String Path of the page. e.g. '/about', '/dashboard/stats'
search String Query string of the pgae. eg: '?id=ab02'

Web3Analytics.optOutTracking(expiration)

Opt user out from tracking.

Web3Analytics.optOutTracking();
Value Type Description
expiration number Default 365. Duration in days for which user is opt-out.

Web3Analytics.optInTracking(expiration)

Opt user in tracking.

Web3Analytics.optInTracking();
Value Type Description
expiration number Default 365. Duration in days for which user is opt-in.

Web3Analytics.hasOptedOutTracking()

Getter method for the status of user tracking consent.

Web3Analytics.hasOptedOutTracking();
Value Return Type Description
- Boolean Status of user tracking consent.

Web3Analytics.widgetOnClick(method)

For custom on-click implementation of widget button.

Web3Analytics.widgetOnClick(({ campaignId }) => {
  if (campaignId === YOUR_CAMPAIGN_ID) {
    //do something
  }
});
Param Type Description
campaignId number Unique campaign id belongs to the widget.
redirectUrl string / undefined Redirect url set on the campaign button click.

Supporting wallets

  • MetaMask
  • WalletConnect
  • Coinbase Wallet
  • Portis
  • Fortmatic

To track wallet not including in the list you can use trackWalletConnection method.

Datapoints

  • web3 (Mandatory) - Wallet Address, Chain ID, Wallet Type, Wallet Connection, Max Gas Fee, Quoted Gas Fee, Transaction Hash, Transaction Status, Submitted and Rejected Transaction Count and Failed Transactions.
  • web2 - Current URL, Operating System, Browser, Referrer, Device, Referring Domain, Screen Width, Screen height, Search Engine, Page Views, External Links and UTM Params.
  • demographics - Country, City and Region.
  • engage - Campaign Serving, Campaign Clicks, Click Through Rate (CTR), Transaction Through Rate (TTR), Unique Wallets, Dialogs Served, and Dialogs Closed.

License

UNLICENSED

Demo

Example code for analytics-web3 integration Spock Analytics Demo

Documentation

You can use these docs for knowing more about Spock Analytics.

Credits

Backed by xord.com

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[0.1.0-beta.0] - 2022-09-14

Added

  • Initial version of sdk.

[0.1.0-beta.1] - 2022-09-15

Added

  • On-boarding and credits section in README.

[0.1.0-beta.2] - 2022-09-21

Changed

  • Server endponits

[0.1.0-beta.3] - 2022-09-22

Added

  • Value Extraction feature
  • Add license and value extraction in API section of README.
  • Add CHANGELOG.md file.
  • Documented some code.

Changed

  • Moved valueContribution code into generalized function protocolValue.
  • Rename brand name from DAppzero to Spock in README.
  • JSON formatting utils.

Fixed

  • Multiple reject txn logging.
  • Wallet disconnect expection.
  • Parse data in ls event.

[0.1.0-beta.4] - 2022-09-26

Changed

  • Provider event attach function.
  • Server endpoints

Fixed

  • README typo

[0.1.0-beta.5] - 2022-10-04

Fixed

  • Document reference for same domain.

[0.1.0-beta.6] - 2022-10-10

Fixed

  • RPC request method and params for new versions of ethers.js.

[0.1.0-beta.7] - 2022-10-21

Fixed

  • Fortmatic typo in wallet constants.

[0.1.0] - 2022-11-03

Changed

  • Remove beta tag from sdk

[0.1.1] - 2023-01-08

Changed

  • End session functionality on account and chain change.
  • Add submit and reject txn count in session data.
  • Config eslint, lint-staged and husky.

[0.1.2] - 2023-02-03

Changed

  • Convert user ip fetching as a one time procedure.
  • Add ip support on all server routes.
  • Deprecate value contribution functions.

Fixed

  • Navigation record in session.
  • New session starting on chain change.
  • Session duration bug.

[1.0.0-beta.0] - 2023-05-05

Added

  • Indentification, link distinctId with users(wallet).
  • New meta-data properties with all tracking events.
  • UTM paramters tracking.
  • Opt out support for make tracking consentful for the required application.

Changed

  • Improve session tracking through server support.
  • Removed deprecated value contribution functions.
  • Separated pathname and search parameters for trackPageView.

[1.0.0-beta.1] - 2023-05-05

Added

  • Make geolocation tracking optional.

[1.0.0-beta.2] - 2023-05-05

Fixed

  • Cookie handling with consent.
  • DistinctId key bug.

[1.0.0-beta.3] - 2023-05-06

Fixed

  • Events flow in session.
  • Geolocation tracking on intial events.

[1.0.0-beta.4] - 2023-05-10

Fixed

  • Add txn hash on txn-submit tracking.
  • Expire session on wallet or chain change.

[1.0.0-beta.5] - 2023-05-12

Fixed

  • Session expiry handling on page unload.

[1.0.0-beta.6] - 2023-05-29

Fixed

  • Add txn status in event flow tracking.

[1.0.0] - 2023-06-11

Fixed

  • Update constants documentation.
  • Remove beta

[1.0.1] - 2023-06-17

Fixed

  • Backward compatibility for old version device-id
  • Remove beta

[1.1.0] - 2023-08-22

Added

  • Allow user to limit the tracking of datapoints by passing the desired one on initialization.

[1.2.0] - 2023-09-08

Added

  • Revert the latest version back to 1.1.0 state.

[1.3.0] - 2023-09-10

Added

  • Widget support through iframe.
  • Pass events data into to widget.
  • Custom widget on-click handling.
  • Add engage data point.

[1.3.2] - 2023-09-11

Added

  • Engage data-points in README.
  • Widget on-click method in API section of README.

Fixed

  • Type of widget on-click method params.

[1.3.3] - 2023-09-12

Fixed

  • SDK Version constant

[1.4.0] - 2023-09-12

Added

  • Add popup events in session flow.

[1.5.0-beta.0] - 2023-10-18

Changed

  • Datapoints category.
  • Make web2 tracking optional, like sessions, visits.
  • Allow widget to serve campaign for exlcuded datapoints. (Just to serve camapaign not to track user data).

Added

  • Test version for widget.

[1.5.0] - 2023-11-16

Changed

  • Data points section in README.
  • Move beta changes to stable version.