> ## Documentation Index
> Fetch the complete documentation index at: https://developer.cashbackhive.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Tracking

> Cashback Hive SDK tracking API reference: build tracked retailer URLs with trackingUrl() and open them with openOffer(), including click IDs and sub-IDs.

See [Click tracking](https://developer.cashbackhive.com/guides/click-tracking.md) for guidance on when to use each method and how attribution works.

## `openOffer()`

Build a tracked URL for an offer, record the click, and open the retailer.

```ts theme={null}
openOffer(offer: string | Offer, options?: OpenOfferOptions): void
```

**offer** `string | Offer` *required*

An [`Offer`](https://developer.cashbackhive.com/reference/types#offer) object, or the slug of an offer previously returned by `offers.list()` or `offers.get()`.

**options.clickId** `string`

Your identifier for this click. Defaults to a random UUID.

**options.subId** `string` (default: "")

Free-form attribution label for your reporting.

**options.deeplink** `string`

Retailer URL to land on. Only applied when `offer.supportsDeeplinking` is `true`.

**options.newTab** `boolean` (default: true)

`true` opens the URL with `window.open(url, "_blank", "noopener")`. `false` navigates the current tab with `location.assign(url)`.

**Side effects**, in order:

1. Emits the [`click`](https://developer.cashbackhive.com/reference/events#click) event with `{ slug, url }`.
2. Sends an `offer_click` analytics beacon with `{ slug, subId }`.
3. Opens the URL.

**Throws** synchronously if the SDK isn't initialised, if a slug isn't in the offer cache, or if the offer has no `clickUrl`. See [Errors](https://developer.cashbackhive.com/reference/errors.md#sdk-errors).

```ts theme={null}
sdk.openOffer(offer, { subId: "sidebar", deeplink: "https://www.nike.com/t/air-max-90" });
```

## `trackingUrl()`

Build a tracked URL without opening it or recording a client-side click.

```ts theme={null}
trackingUrl(offer: string | Offer, options?: TrackingOptions): string
```

Accepts the same `offer`, `clickId`, `subId` and `deeplink` parameters as `openOffer()` (there is no `newTab`).

**Returns** the fully substituted tracked URL. Following this URL still records the click server-side at Cashback Hive; only the SDK's `click` event and `offer_click` beacon are skipped.

**Throws** under the same conditions as `openOffer()`.

```ts theme={null}
const href = sdk.trackingUrl(offer, { subId: "newsletter" });
link.href = href;
link.target = "_blank";
link.rel = "noopener";
```

## How the URL is built

Each offer's `clickUrl` is a template containing placeholders. `trackingUrl()` substitutes them, URL-encoding each value:

| Placeholder | Replaced with |
| - | - |
| `{PublisherClickID}` | `options.clickId`, or a random UUID |
| `{SubId}` | `options.subId`, or `""` |
| `{DeepLink}` | `options.deeplink` if `offer.supportsDeeplinking`, else `""` |

The resulting URL points at `https://shop.cashbackhive.com/click/…` (or `https://click.invalid/…` in mock mode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.