# @web3analytic/retargeting-sdk

> Web3Analytic's typescript package for in-dapp retargeting

Latest version **1.0.2** (published 2023-06-28) · UNLICENSED license · 0 weekly downloads

## Install

```sh
npm install @web3analytic/retargeting-sdk
pnpm add @web3analytic/retargeting-sdk
yarn add @web3analytic/retargeting-sdk
bun add @web3analytic/retargeting-sdk
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-06-28 |
| First published | 2023-06-28 |
| Weekly downloads | 0 |
| License | UNLICENSED |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Web3Analytic |
| Maintainers | grubiroth |
| Keywords | in-dapp retargeting, action prompts, web3analytic sdk, on-chain analytics, web3 marketing |

## Links

- npm: https://www.npmjs.com/package/@web3analytic/retargeting-sdk
- Repository: https://github.com/web3analytic-xyz/web-app
- Homepage: https://www.web3analytic.xyz
- Issues: https://github.com/web3analytic-xyz/web-app/issues
- npm.io page: https://npm.io/package/@web3analytic/retargeting-sdk

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2023-06-28
- 1.0.1 — 2023-06-28
- 1.0.0 — 2023-06-28

## README

# retargeting-sdk

> Web3Analytic's javascript SDK for in-dapp retargeting

The goal of retargeting is to guide a user who has performed a source action to then perform a target action. A common example might be encouraging users to perform an on-chain swap after an approval. 

## Install

```bash
npm install @web3analytic/retargeting-sdk
```

## Usage

The most important function to import is `registerAction` which takes as input an address interacting with your protocol frontend, along with information about an action.

```js
import { registerAction } from '@web3analytic/retargeting-sdk';
```

You can register both on-chain and off-chain actions. For on-chain actions, you must provide the `chain` and the transaction hash (`txHash`). These can be obtained from any wallet provider (e.g. MetaMask) upon an on-chain action. It is not necessary to wait for a transaction to be confirmed.

```js
import { registerAction, RegisterActionInputType }  from '@web3analytic/retargeting-sdk';
const input: RegisterActionInputType = {
  apiKey: "...",
  address: "0x...",
  chain: "ethereum",
  txHash: "0x...",
} 
registerAction(input).then(...)
```

For off-chain actions, an `identifier` must be provided. These strings can be of any length and structure although it is important it matches the identifiers chosen during setup of this retargeting campaign through the Web3Analytic web application.

```js
import { registerAction, RegisterActionInputType }  from '@web3analytic/retargeting-sdk';
const input: RegisterActionInputType = {
  apiKey: "...",
  address: "0x...",
  identifier: "main-page-sidebar-button-click",
} 
registerAction(input).then(...)
```

Source and target actions are both registered using `registerAction`. The SDK will automatically detect whether the action is a source or target depending on the active retargeting campaigns. If the action is a source action, it will return an impression object:

```js
{
  hit: true,
  prompt: {
    title: ...,
    subtitle: ...
    ...,
  }
  impressionId: 120;
}
```
The `impressionId` will be useful for regsitering reactions (see next). The `prompt` can be used to render a notification to encourage the user to take the corresponding target action. 

If the action is a target action (or alternatively the action is not a match to any retargeting campaign), the returned object will only contain a single field `hit` set to `false`. 

Analytics on conversion rates between source and target actions can be found on the Web3Analytic app. 

Finally, we may be interested in the proportion of users that engage with a notification shown (irrespective of whether they take the target action or not). To track this, we can call the following
```js
import { registerReaction }  from '@web3analytic/retargeting-sdk';

await registerReaction(apiKey, impressionId);
```
when the user engages with the notification prompt. Note that a user performing the target action is automatically tracked through registering actions and does not require calling `registerReaction`. Tracking user's clicking on the notification however, requires calling `registerReaction`.

---
_Source: https://npm.io/package/@web3analytic/retargeting-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
