# API Reference

### Web3Analyitcs.init

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

**Usage**

```javascript
Web3Analytics.init({ appKey: 'YOUR APP KEY'});
```

<table><thead><tr><th width="148">Argument</th><th width="96">Type</th><th>Description</th></tr></thead><tbody><tr><td>appKey</td><td>String</td><td>Unique appKey like <code>eba6...28c</code> for tracking. Can be obtained from the app's <a href="https://app.spockanalytics.xyz/dapp/config">configuration</a> page.</td></tr><tr><td><strong>Optional</strong></td><td></td><td></td></tr><tr><td>debug</td><td>Boolean</td><td>Defaults to <code>false</code>. Enable consoles for all the tracking events.</td></tr><tr><td>dataPoints</td><td>string[]</td><td><p>By default, SDK will track all data </p><p>points. But you can limit them by passing the desired <a href="..#data-points">datapoints</a>.</p></td></tr><tr><td>inactivityTimeout</td><td>number</td><td>Defaults to <code>30</code>. This field takes time in mins to specify the inactivity duration in which the session will expire.</td></tr><tr><td>optOut</td><td>Boolean</td><td>Defaults to <code>false</code>. Opt users out of tracking.</td></tr><tr><td>testENV</td><td>Boolean</td><td>Defaults to <code>false</code>. Enable testing version of SDK in which SDK will interact with testing servers.</td></tr><tr><td>testMode</td><td>Boolean</td><td>Defaults to <code>false</code>. Enable test mode in which you can test tracking events without logging data onto the server in order to avoid storing testing data.</td></tr></tbody></table>

### Web3Analytics.walletProvider

Pass `web3 provider` to track wallet connections and transaction status that are submitted or rejected on the dApp.

Wallets that are not included in [Supporting Wallets](https://spock-analytics.gitbook.io/introduction/configuration/sdk/supporting-wallets) will be classified as `Other`  wallet type.

#### Usage

```javascript
Web3Analytics.walletProvider(window.ethereum);
```

In case of handling multiple wallets on the dApp. Example in `React`.

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

const { provider } = useWeb3React();

//in order to pass an updated provider if the user changes wallet, account or chain.
useEffect(() => {
  if (provider?.provider) {
    Web3Analytics.walletProvider(provider.provider);
  }
}, [provider]);
```

<table><thead><tr><th width="139">Argument</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>provider</td><td>Web3Provider</td><td>EIP-1193 Standard Provider or Web3Provider-compatible Provider</td></tr></tbody></table>

### Web3Analytics.trackWalletConnection

To track the wallet type for wallets that are not part of [Supporting Wallets](https://spock-analytics.gitbook.io/introduction/configuration/sdk/supporting-wallets).\
\
**Usage**

```javascript
Web3Analytics.trackWalletConnection('Ledger', '0x...96', 1);
```

<table><thead><tr><th width="142">Argument</th><th width="105">Type</th><th>Description</th></tr></thead><tbody><tr><td>walletType</td><td>String</td><td>Name of wallet</td></tr><tr><td>account</td><td>String</td><td>User Ethereum address</td></tr><tr><td>chainId</td><td>number</td><td>User connected chainId</td></tr></tbody></table>

### Web3Analytics.trackPageView

Track all the pages visited on a DApp.

#### Usage

```javascript
Web3Analytics.trackPageView('/home');
```

<table><thead><tr><th width="147">Argument</th><th width="108">Type</th><th>Description</th></tr></thead><tbody><tr><td>path</td><td>String</td><td>Path of the page. e.g. '/about', '/dashboard/stats'</td></tr><tr><td>search</td><td>String</td><td>Query string of the page. eg: '?id=ab02'</td></tr></tbody></table>

### Web3Analytics.optOutTracking

Opt user out from tracking.

#### Usage

```javascript
Web3Analytics.optOutTracking();
```

<table><thead><tr><th width="147">Argument</th><th width="108">Type</th><th>Description</th></tr></thead><tbody><tr><td>expiration</td><td>number</td><td>Default <code>365</code>. Duration in days for which the user is opt-out</td></tr></tbody></table>

### Web3Analytics.optInTracking

Opt user in tracking.

#### Usage

```javascript
Web3Analytics.optInTracking();
```

<table><thead><tr><th width="147">Argument</th><th width="108">Type</th><th>Description</th></tr></thead><tbody><tr><td>expiration</td><td>number</td><td>Default <code>365</code>. Duration in days for which the user is opt-in</td></tr></tbody></table>

### Web3Analytics.hasOptedOutTracking

Getter method for the status of user tracking consent.

#### Usage

```javascript
Web3Analytics.hasOptedOutTracking();
```

<table><thead><tr><th width="134">Argument</th><th width="137">Return Type</th><th>Description</th></tr></thead><tbody><tr><td>-</td><td>number</td><td>Status of user tracking consent</td></tr></tbody></table>

### Web3Analytics.widgetOnClick

For the custom on-click implementation of widget button.

#### Usage

```javascript
Web3Analytics.widgetOnClick(({ campaignId }) => {
  if (campaignId === YOUR_CAMPAIGN_ID) {
    //do something
  }
});
```

<table><thead><tr><th width="134">Params</th><th width="137">Type</th><th>Description</th></tr></thead><tbody><tr><td>campaignId</td><td>number</td><td>A unique campaign ID belongs to the widget.</td></tr><tr><td>redirectUrl</td><td>string | undefined</td><td>Redirect URL set on the campaign button click.</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://spock-analytics.gitbook.io/introduction/configuration/sdk/api-reference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
