---

title: Stop promo, bonus, referral and trial abuse
description: Give one welcome code, bonus, referral reward or free trial per browser instead of per email, using the visitor id, its aliases, high_recall_id and the related reads.
---

## The threat

A welcome code, a signup bonus, a referral reward or a free trial is priced on the idea that each person claims it once. The people who abuse it claim it again and again: a fresh email for every claim (`deal@example.com`, `de.al@example.com`, `deal+3@example.com`), a private window or cleared cookies so the site forgets them, a VPN so the address changes, sometimes a second browser on the same machine. Referral abuse is the same person on both sides of the referral, or one person running a farm of referees to collect rewards.

An email address, a cookie or an IP address costs the abuser nothing to change. knownprint gives your backend a **visitor id** for the browser behind each claim, which stays the same across new emails and new accounts, and comes back in a private window or after cookies are cleared whenever knownprint is sure. Your code pays one reward per browser, not per email.

This guide covers:

- where in your flow to identify the visitor;
- which fields of the event to read, and what each one tells you;
- a decision table you can start from;
- a complete backend example for a promo code, a free trial and a referral reward;
- the mistakes that cost real customers their reward.

## Where to identify

Identify the visitor at the moment the reward is granted, not when the page loads. Typical points:

| Reward                     | Identify when                                                                              |
| -------------------------- | ------------------------------------------------------------------------------------------ |
| Welcome code or coupon     | The customer applies the code at checkout, or places the order that uses it                |
| Signup bonus               | The account is created, and again when the bonus is credited if that happens later         |
| Free trial or free credits | The trial starts, or the first credits are granted                                         |
| Referral reward            | The referee signs up (record the referee's browser), and again when the reward is paid out |
| Loyalty or cashback payout | The payout is requested                                                                    |

In the page, call `identify()` right before the request that claims the reward and send the request id with it. The agent must already be installed on the page ([Add the browser agent](/install/browser)); for a plain HTML form, [protect a form](/install/forms) writes the request id into a hidden field for you.

```js title="redeem.js"
// Once, when the page starts. Resolves null when the script is blocked or fails to load.
const agentReady = window.knownprint
  ? window.knownprint.load({ pk: 'pk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' }).catch(() => null)
  : Promise.resolve(null);

/** A fresh request id, or null when the agent is blocked, fails or takes longer than 3 seconds. */
function requestId(action) {
  const timeout = new Promise((resolve) => setTimeout(() => resolve(null), 3000));
  const attempt = agentReady
    .then((agent) => (agent === null ? null : agent.identify({ tags: { action } })))
    .then((result) => (result === null ? null : result.requestId))
    .catch(() => null);
  return Promise.race([attempt, timeout]);
}

async function redeem(code) {
  // null when blocked or failed: claim without one; the backend holds the claim as unknown.
  const kp_request_id = await requestId('promo_redeem');
  const res = await fetch('/promo/redeem', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ code, kp_request_id }),
  });
  return res.json();
}
```

Your backend then reads the event with the secret key, `GET /v1/events/{request_id}`, and decides. Never decide in the browser: anything the page decides, the abuser can change.

:::tip Tags
`tags` is an open map of your own values (strings, numbers or booleans) stored with the event. A tag such as `action: 'promo_redeem'` makes the event easy to find later. Keep tags free of personal data; see [Events](/events) for the limits.
:::

## Which fields to read

All of these are on the event your backend reads ([Events](/events) has the full reference).

| Field                                          | What it tells you for a reward                                                                            | How to use it                                                                                          |
| ---------------------------------------------- | --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| `visitor_id`                                   | The browser behind this claim                                                                             | The key you store with every reward granted, and check every new claim against                         |
| `confidence`                                   | How sure knownprint is that `visitor_id` is the right browser, from 0 to 1                                | Refuse automatically only above a level you choose; review below it                                    |
| `match_type`                                   | Whether knownprint recognised a browser it had seen before (`new` when it had not, as far as it can tell) | A `new` visitor cannot match a past claim by its own id; read `high_recall_id` too                     |
| `high_recall_id`                               | Another visitor this browser may also be, named beside the answer without being merged into it, or null   | A lead for review, never a refusal on its own                                                          |
| `high_recall_probability`                      | How likely the `high_recall_id` visitor is this browser, from 0 to 1; absent when there is no such number | Orders your review queue                                                                               |
| `anonymity_set_size`                           | The lookalike count: how many visitors of your environment look like this browser, at least 1             | Above 1, lookalikes exist; give `high_recall_id` less weight                                           |
| `signals.suspect_score.value`                  | 0 to 100: how much of the visit's signals your site should worry about                                    | One threshold for "look closer" ([Suspect score](/signals/suspect-score))                              |
| `signals.vpn`, `signals.proxy`, `signals.tor`  | The visit came through a VPN, a proxy or Tor                                                              | Context for review, not a reason to refuse on its own ([Network signals](/signals/network))            |
| `signals.incognito`                            | The visit came from a private window                                                                      | Context: a private window at a promo claim is common among abusers and ordinary shoppers alike         |
| `signals.virtual_machine`, `signals.tampering` | The browser runs in a virtual machine, or misreports what it is                                           | Strong context at a reward claim: tools for running many claims from one machine ([Signals](/signals)) |
| `integrity.replayed`                           | True when this identification was sent before                                                             | Refuse it: never pay out on a replayed request ([Integrity signals](/signals/integrity))               |

:::note Coming
Device clusters, which group different browsers on one device, are coming. Events carry `device_cluster_id` and `cluster_confidence` today, but both are null on new events, so a second browser on the same machine is not yet grouped with the first. Until then, the visitor id, `high_recall_id` and your linked ids are what connect claims. See [Device clusters](/visitors#device-clusters).
:::

### Visitor ids may merge

knownprint may find later that two visitor ids are one browser. It then merges them: the older id survives, the other becomes its **alias**, and `GET /v1/visitors/{visitor_id}` answers the surviving visitor for either id, with every merged id in `aliases`. Your claims table holds the ids you were given at the time, so check a new claim against the visitor **and all of its aliases**, not the single id on the event. The example below does this. [Visitors](/visitors) explains merges, and the [`visitor.merged` webhook](/webhooks#visitor-merged) tells you when one happens.

## Decision table

Start here and tune the thresholds on your own traffic. Thresholds are yours to choose; the values below are starting points, not knownprint defaults.

| What you see                                                                                      | Suggested action                                                              |
| ------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| No request id, or the event fails verification (unknown, stale, replayed, wrong origin)           | Hold the reward. A missing request id is unknown, not a pass                  |
| `signals.bot.value` is `bad`                                                                      | Refuse                                                                        |
| The visitor, or one of its aliases, already claimed this reward, and `confidence` is at least 0.9 | Refuse                                                                        |
| The visitor or an alias already claimed, and `confidence` is below 0.9                            | Review, or ask for something that costs the abuser (a verified phone, a card) |
| `high_recall_id` names a visitor (or an alias of one) that already claimed                        | Review; order the queue by `high_recall_probability`                          |
| `signals.suspect_score.value` at or above 70                                                      | Refuse or require extra verification                                          |
| `signals.suspect_score.value` from 40 to 69                                                       | Review                                                                        |
| A VPN or a private window alone, nothing else                                                     | Grant. On their own these describe many honest customers                      |
| None of the above                                                                                 | Grant, and record the claim                                                   |

For a referral reward, add:

| What you see                                                                                                    | Suggested action                                          |
| --------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
| The referee's visitor, or an alias of it, is one of the referrer's own browsers                                 | Refuse the referral reward (the signup itself can stand)  |
| The referee's account was used on one of the referrer's browsers (it is in the referrer's related `linked_ids`) | Refuse the referral reward                                |
| The referee's `high_recall_id` names one of the referrer's browsers                                             | Review                                                    |
| Many referees of one referrer share a visitor id                                                                | Refuse the rewards of the repeats and review the referrer |

## Backend example

A complete Express 5 handler for a promo code, in Node 22 with Postgres (Express 5 passes a rejected promise in a handler to your error handler). It verifies the event, resolves the visitor's aliases, applies the decision table, records the claim, and attaches your account id to the event so the account shows up in [linked ids](/accounts).

```js title="promo.js"
import express from 'express';
import pg from 'pg';

const API = process.env.KNOWNPRINT_API; // the API address that comes with your account
const SECRET = process.env.KNOWNPRINT_SECRET_KEY; // sk_live_...
const ORIGIN = 'https://shop.example'; // the origin your pages are served from

const db = new pg.Pool();
const app = express();
app.use(express.json());

// create table promo_claims (
//   promo_code text not null, account_id text not null, visitor_id text not null,
//   request_id text not null, created_at timestamptz default now());
// create table kp_used_request_ids (request_id text primary key, used_at timestamptz default now());

/** Calls the knownprint API; null on 404 (not found) and 409 (being deleted), throws on other errors. */
async function kp(path, init = {}) {
  const res = await fetch(`${API}${path}`, {
    ...init,
    headers: {
      Authorization: `Bearer ${SECRET}`,
      Accept: 'application/json',
      ...(init.body ? { 'Content-Type': 'application/json' } : {}),
    },
  });
  if (res.status === 404 || res.status === 409) return null;
  if (!res.ok) throw new Error(`knownprint ${res.status}`);
  return res.json();
}

/** The verified event of a request id, or null. Each request id is used once. */
async function verifiedEvent(requestId) {
  if (typeof requestId !== 'string' || !/^evt_[a-z2-7]{26}$/.test(requestId)) return null;
  const first = await db.query(
    'insert into kp_used_request_ids (request_id) values ($1) on conflict do nothing',
    [requestId],
  );
  if (first.rowCount === 0) return null; // already used
  const event = await kp(`/v1/events/${requestId}`);
  if (event === null) return null;
  const age = Date.now() - Date.parse(event.received_at);
  if (age > 10_000 || age < -60_000) return null; // stale
  if (event.integrity.replayed) return null;
  if (event.integrity.origin !== ORIGIN) return null;
  // Add the address and confidence checks of /install/server as your site needs them.
  return event;
}

/** The visitor id and every alias merged into it. */
async function idsOf(visitorId) {
  const visitor = await kp(`/v1/visitors/${visitorId}`);
  if (visitor === null) return [visitorId];
  return [visitor.visitor_id, ...visitor.aliases];
}

async function claimedBy(promo, ids) {
  const r = await db.query(
    'select 1 from promo_claims where promo_code = $1 and visitor_id = any($2) limit 1',
    [promo, ids],
  );
  return r.rowCount > 0;
}

async function decide(event, promo) {
  const s = event.signals;
  // A missing score is unknown, not zero: it never clears a claim on its own.
  const score = s.suspect_score?.value ?? null;
  if (s.bot?.value === 'bad') return { action: 'refuse', reason: 'bot' };

  if (await claimedBy(promo, await idsOf(event.visitor_id))) {
    return event.confidence >= 0.9
      ? { action: 'refuse', reason: 'same_browser' }
      : { action: 'review', reason: 'same_browser_unsure' };
  }
  if (score !== null && score >= 70) return { action: 'refuse', reason: 'suspect_score' };

  if (event.high_recall_id !== null) {
    if (await claimedBy(promo, await idsOf(event.high_recall_id))) {
      return {
        action: 'review',
        reason: 'likely_same_browser',
        priority: event.high_recall_probability ?? null,
      };
    }
  }
  if (score === null || score >= 40) return { action: 'review', reason: 'suspect_score' };
  return { action: 'grant' };
}

app.post('/promo/redeem', async (req, res) => {
  const account = req.user; // your own session
  const promo = String(req.body.code ?? '')
    .trim()
    .toUpperCase()
    .slice(0, 64); // a tag value holds at most 256 characters
  const event = await verifiedEvent(req.body.kp_request_id);
  if (event === null) return res.status(400).json({ ok: false, error: 'try_again' });

  // Record which of your accounts made this claim (scope events:write).
  await kp(`/v1/events/${event.request_id}`, {
    method: 'PATCH',
    // linked_id is a string of 1 to 128 characters; the tags given here replace the event's tags.
    body: JSON.stringify({
      linked_id: String(account.id),
      tags: { action: 'promo_redeem', promo },
    }),
  });

  const decision = await decide(event, promo);
  if (decision.action === 'grant') {
    await db.query(
      `insert into promo_claims (promo_code, account_id, visitor_id, request_id)
       values ($1, $2, $3, $4)`,
      [promo, String(account.id), event.visitor_id, event.request_id],
    );
    return res.json({ ok: true });
  }
  if (decision.action === 'review') {
    await queueForReview({ account, promo, event, decision }); // your review queue
    return res.json({ ok: false, error: 'pending_review' });
  }
  return res.json({ ok: false, error: 'not_available' }); // never say why: see Pitfalls
});
```

The secret key needs the `events:read` scope for the reads and `events:write` for the `PATCH`. Every route, its status codes and its limits are in the [API reference](/api); [Verify a request in your backend](/install/server) explains the verification steps in `verifiedEvent`.

:::note Coming
The Node SDK wraps these calls (reading and verifying an event, reading a visitor, the related reads and the event update) and is coming with the SDK release. Until then, call the routes directly as above. See [Node SDK](/sdks/node).
:::

### Free trials and free credits

The same handler works for a trial: use a fixed key such as `trial` in place of the promo code, and identify at the moment the trial starts. Check the visitor and its aliases against every trial ever granted, not against trials still running: the abuser's second trial usually starts after the first one ends.

### Referral rewards

Pay a referral reward only when the referee is not one of the referrer's own browsers. Your referrer is an account, so ask knownprint which browsers carried that account's linked id:

```bash
curl "$KNOWNPRINT_API/v1/linked/acct_8841/related" \
  -H "Authorization: Bearer $KNOWNPRINT_SECRET_KEY"
```

```json
{
  "visitors": [
    {
      "visitor_id": "v_k7q2mxa4pfz3bnw6tqyh5rd2xa",
      "evidence": [{ "kind": "linked_id", "detail": "acct_8841", "weight": 1 }]
    }
  ],
  "linked_ids": [
    {
      "linked_id": "acct_9310",
      "evidence": [{ "kind": "linked_id", "detail": "v_k7q2mxa4pfz3bnw6tqyh5rd2xa", "weight": 1 }]
    }
  ]
}
```

`visitors` lists the browsers that carried `acct_8841`; `linked_ids` lists your other accounts seen on those browsers, here `acct_9310`. A referee account that appears in the referrer's `linked_ids`, or a referee visitor that appears in its `visitors`, is the referrer referring themselves. The referee's account shows up in `linked_ids` only once its own events carry its account id, so attach it at the referee's signup (`PATCH /v1/events/{request_id}`) before you check.

```js title="referral.js"
async function selfReferral(referrerAccountId, refereeEvent, refereeAccountId) {
  const related = await kp(`/v1/linked/${encodeURIComponent(referrerAccountId)}/related`);
  if (related === null) return false; // the referrer was never seen with a linked id
  const refereeIds = new Set(await idsOf(refereeEvent.visitor_id));
  if (related.visitors.some((v) => refereeIds.has(v.visitor_id))) return true;
  return related.linked_ids.some((l) => l.linked_id === refereeAccountId);
}
```

For a referral farm, count the distinct visitor ids (resolved to their surviving ids) among one referrer's referees: ten referees on two browsers is two browsers' worth of people, not ten. The related reads return at most 50 entries per list, strongest first; [Linked ids API](/api/linked) documents both routes.

## Reviewing a held claim

A held claim needs a person to decide. Give the reviewer:

- the claim's event, with `confidence`, `high_recall_id` and `high_recall_probability`;
- the earlier claim it collided with, and when;
- `GET /v1/visitors/{visitor_id}/related`, which lists the other visitors and accounts related to this browser, each with the evidence that relates it.

When the reviewer decides, record it on the event with `POST /v1/events/{request_id}/feedback` and a `label` of `fraud` or `legit` ([Feedback](/feedback)). It keeps your own decisions next to the events that caused them.

## Pitfalls

- **Refusing on `high_recall_id` alone.** It names another visitor this browser may be, which knownprint was not sure enough to merge. That is a lead, and sometimes it is a stranger with a browser that looks the same. Review it; do not refuse it automatically.
- **Treating one browser as one person.** A family computer, a shared office machine or a library terminal puts different people on one browser. If your offer is per household, a refusal there is right; if it is per person, let a second member of the household reach a review or a verified phone rather than a flat refusal.
- **Ignoring the lookalike count.** When `anonymity_set_size` is above 1, other visitors look like this browser, which is common on popular phones. Lean on the visitor id and its confidence there, not on leads.
- **Checking only the id on the event.** After a merge, the same browser's earlier claim may be stored under an alias. Resolve with `GET /v1/visitors/{visitor_id}` and check every id in `aliases`.
- **Letting the page set the account.** A `linkedId` passed to `identify()` comes from the browser, which the abuser controls. Set the account from your backend with `PATCH /v1/events/{request_id}` after you know who is signed in, as in the example.
- **Refusing every VPN or private window.** Both are common among honest shoppers. Use them as context in review, or let the suspect score weigh them.
- **Paying out on a missing request id.** If the page sends no request id (a blocked script, a bot calling your endpoint directly), treat the claim as unknown and hold it. Paying out on "no data" is the hole abusers look for ([Handle a missing request id](/install/server#handle-a-missing-request-id)).
- **Telling the abuser why.** "This offer was already used on this browser" teaches them to switch browsers. A plain "This offer is not available" teaches nothing.
- **Keeping only knownprint's copy.** Events are kept for your account's event retention period and then deleted ([How long events are kept](/events#how-long-events-are-kept)). Store the visitor id with your own claim records, as the example does.

## Related pages

- [Visitors](/visitors): what a visitor id is, confidence, merges and aliases.
- [Accounts and linked ids](/accounts): attaching your account ids to events.
- [Stop fake signups](/guides/fake-signups): the same checks at account creation.
- [Keep banned users out](/guides/ban-evasion) and [Account sharing and multi-accounting](/guides/account-sharing).
