# Add Track Link to your app Track Link turns a URL into a short link that records every open — city, device, browser, referrer, UTM tags — and can attribute a sale back to the click that caused it. Tracked links are served from `https://gtlk.link/`. There is no SDK and nothing to embed to make link tracking work: a tracked link records clicks the moment it exists. What you integrate is one of four things. Pick one below before writing code. - **A. Read links and analytics from your backend** — REST. Works on every plan. - **B. Attribute signups or sales on your own site** — a script tag or one POST. Free on every plan. - **C. Let an AI agent manage links in conversation** — the MCP server. - **D. Scripts, cron and CI** — the CLI. --- ## Read this first — the plan decides what your code may do Getting this wrong is the usual reason a Track Link integration ships broken. - **Reading is open to every plan**: links, clicks, stats, usage, conversions. - **Creating, editing or deleting a link through the API needs AGENCY or BUSINESS.** On FREE, STARTER or PRO, `POST`/`PATCH`/`DELETE /v1/links` returns `403`, and a write-scoped key cannot even be minted. If the user is not on Agency or Business, do not write code that creates links through the API — have them create links in the dashboard and read them from your code, or tell them an upgrade is required. Ask the user which plan they are on, or call `GET /v1/me` and read `plan`. - **Click history is clamped to the plan's retention window** (FREE is 7 days). Omitting `start_date` does *not* mean "all time" — it means "as far back as this plan can see". If your integration reports "no clicks", check this before checking your code. - **Conversion recording is free on every plan.** Forwarding conversions to an ad network is PRO+. Ask the user for their plan if you don't know it. Don't guess, and don't write code for an endpoint the plan will refuse. --- ## 1. Get an API key Keys are minted by the account owner at **https://gettrack.link/developers** and shown once. Have the user create one; you cannot create it for them. A key looks like `tl_live_` followed by 32 characters. Scopes are `read` (any plan) or `read,write` (Agency and Business only). Put it in the environment. Never commit it, and never ship it to a browser or a mobile app — the key can read every link and click in the account. ```bash # .env (add .env to .gitignore) TRACKLINK_API_KEY=tl_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxx ``` --- ## 2A. REST — read and manage links from your backend Base URL: `https://api.gettrack.link/api/v1` Send the key as a bearer token (or as `X-API-Key`, if a bearer header is awkward in your stack): ```bash curl https://api.gettrack.link/api/v1/links \ -H "Authorization: Bearer $TRACKLINK_API_KEY" ``` Every response is wrapped in `data`, and every list carries `pagination`: ```json { "data": [ { "id": "c7f1a0e2-5b3d-4a91-8f2c-0d6e7b4a1c99", "name": "Summer promo", "slug": "summer", "short_url": "https://gtlk.link/summer", "type": "redirect", "destination": "https://example.com/promo", "is_active": true, "is_locked": false, "color": null, "campaign_id": null, "total_clicks": 1842, "unique_clicks": 1511, "clicks_last_7d": 96, "created_at": "2026-09-02T11:04:18.000Z", "updated_at": "2026-10-19T08:22:40.000Z", "paid_at": null } ], "pagination": { "total": 37, "limit": 50, "offset": 0, "has_more": false } } ``` `total_clicks` and `unique_clicks` are lifetime. `clicks_last_7d` is the rolling week. A link with `is_locked: true` still redirects but cannot be edited — the account went over its plan's link cap after a downgrade. A minimal typed client, with the two mistakes that matter already handled: ```ts // track-link.ts — Node 18+, no dependencies const BASE = "https://api.gettrack.link/api/v1"; const key = process.env.TRACKLINK_API_KEY; if (!key) throw new Error("TRACKLINK_API_KEY is not set"); async function tl(path: string, init: RequestInit = {}): Promise { const res = await fetch(BASE + path, { ...init, headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json", ...init.headers, }, }); if (res.status === 429) { // Fixed one-minute window. Wait it out rather than retrying immediately. const retry = Number(res.headers.get("retry-after") ?? 60); throw new Error(`Rate limited; retry in ${retry}s`); } if (!res.ok) { const body = await res.text(); throw new Error(`Track Link ${res.status}: ${body}`); } return res.json() as Promise; } export const listLinks = (search?: string) => tl<{ data: Link[]; pagination: Pagination }>( `/links?limit=100${search ? `&search=${encodeURIComponent(search)}` : ""}`, ); // Clicks are capped by the plan's retention window, so ask for an explicit // range: an omitted start_date is NOT "all time". export const listClicks = (linkId: string, startDate: string) => tl<{ data: Click[]; pagination: Pagination }>( `/clicks?link_id=${linkId}&start_date=${startDate}&limit=100`, ); // Agency and Business only — see the plan section above. export const createLink = (name: string, destination: string, slug?: string) => tl<{ data: Link }>("/links", { method: "POST", body: JSON.stringify({ name, destination, slug }), }); ``` ### Endpoints | Method | Path | Plan | Notes | |---|---|---|---| | `GET` | `/v1/me` | any | The key's account, email, plan and workspace. Call this to discover the plan. | | `GET` | `/v1/usage` | any | Plan limits and consumption: links, clicks this month, retention days. | | `GET` | `/v1/links` | any | `limit` (≤100, default 50), `offset`, `search`. | | `GET` | `/v1/links/:id` | any | | | `POST` | `/v1/links` | **Agency+** | `name` required; `destination`, `slug`, `type` (`redirect`\|`pixel`\|`geo`), `color`. | | `PATCH` | `/v1/links/:id` | **Agency+** | | | `DELETE` | `/v1/links/:id` | **Agency+** | A paid Pinpoint link also needs `?confirm=`. | | `GET` | `/v1/clicks` | any | `link_id`, `start_date`, `end_date`, `limit` (≤100), `offset`. Clamped to plan retention. | | `GET` | `/v1/stats` | any | Aggregated totals, same filters. Clamped to plan retention. | | `GET` | `/v1/conversions` | any | `link_id`, `status`, `event`, `start_date`, `end_date`, `limit`, `offset`. | | `GET` | `/v1/conversions/unmatched` | any | Sales whose click ID matched no click, kept 90 days. | There is no write endpoint for conversions. Conversions arrive from the tag or a postback — see 2B. A click object carries `country`, `country_code`, `city`, `device_type`, `os`, `browser`, `referrer`, `utm_source`, `utm_medium`, `utm_campaign`, `is_unique` and `created_at`. It never carries an IP address or a fingerprint. ### Rate limits Per key, per minute, as a fixed window: **FREE 60, STARTER 120, PRO 300, AGENCY 600, BUSINESS unlimited.** Every response carries `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset`; a `429` also carries `Retry-After` in seconds. Back off on that header rather than retrying immediately, and batch your reads — one `GET /v1/links?limit=100` beats a hundred `GET /v1/links/:id`. ### Errors ```json { "statusCode": 403, "message": "...", "error": "Forbidden" } ``` `401` — key missing, invalid, revoked or expired. `403` — the plan or the key's scope forbids it. This is what a write on a non-Agency plan returns. `404` — no such link in this workspace. `429` — rate limited. --- ## 2B. Conversions — attribute a signup or sale on your own site Two moving parts: the click ID reaches your page, and your page reports back what happened. **Step 1 — the click ID arrives.** When a visitor opens a tracked link, Track Link appends `?utm_click=` to the destination. If your destination URL already contains the `{click_id}` placeholder, it is substituted there instead and nothing is appended. **Step 2 — report the outcome.** Either drop in the tag, or POST from your server. ### The tag (browser) ```html ``` It reads `utm_click` from the URL and keeps it in `localStorage` under `link_track_id`, so the visit survives a signup flow across pages. Then, at the moment the thing you care about happens: ```js // a sale window.trackConversion({ value: 49.99, currency: "USD", id: "ord_987" }); // or a named event window.track("signup", { email: "buyer@example.com" }); ``` The tag carries no API key and is safe in a browser. It clears the stored ID once a conversion is accepted, so one click is not counted twice. ### From your server Better when the sale is confirmed server-side (webhooks from Stripe, your own checkout). Pass through the `utm_click` value your front end captured: ```bash curl -X POST https://api.gettrack.link/api/conversions \ -H "Content-Type: application/json" \ -d '{ "click_id": "AB12CD34EF56GH", "event_type": "purchase", "order_id": "ord_987", "value": 49.99, "currency": "USD" }' ``` This endpoint needs no API key, and **it always answers `{"success": true}`** — by design it never reveals whether the click existed or whether anything was recorded. Do not branch on the response body; it is not a receipt. To confirm a conversion landed, read `GET /v1/conversions`, and check `GET /v1/conversions/unmatched` for IDs that matched nothing. If the traffic comes from an affiliate network rather than your own site, don't use either of these — put `{click_id}` into the network's sub-ID field and use the postback URL at https://gettrack.link/docs/conversions instead. --- ## 2C. MCP — let an AI agent manage links in conversation Add the server to the host's MCP config (Claude Desktop, Claude Code, Cursor, or any MCP client): ```json { "mcpServers": { "tracklink": { "command": "npx", "args": ["-y", "@tracklink/mcp"], "env": { "TRACKLINK_API_KEY": "tl_live_..." } } } } ``` Tools: `list_links`, `get_link`, `create_link`, `update_link`, `delete_link`, `list_clicks`, `get_stats`, `get_usage`, `list_conversions`, `list_unmatched_sales`, `list_webhooks`. The write tools obey the same plan gate as the REST API: on anything below Agency they return the `403`, so an agent on a FREE account should stay on the read tools. `TRACKLINK_API_URL` overrides the base URL if you run a self-hosted instance. --- ## 2D. CLI — scripts, cron and CI ```bash npm i -g @tracklink/cli tl auth login # or: export TRACKLINK_API_KEY=tl_live_... tl links ls ``` Installed as `tl` (also `tracklink`). In CI, set `TRACKLINK_API_KEY` in the environment — it wins over the stored config, so no `auth login` step is needed. ```bash tl links ls --search summer tl stats --from 7d tl clicks --link abc123 --from 24h --json | jq -r '.data[].country' tl conversions ls --status approved --from 30d tl conversions unmatched tl usage ``` `--json` on any command gives raw JSON for piping. Exit codes are stable, so scripts can branch without parsing text: **0** ok, **1** error, **2** usage, **4** auth, **5** rate limited. --- ## Rules - **Never put a `tl_live_` key in client-side code**, a mobile app, or a repo. It reads every link and click in the account. The conversion tag is the only piece that belongs in a browser, and it carries no key. - **Don't write link-creating code for a plan that can't use it.** Check `GET /v1/me` first; below Agency, read-only is all you get. - **Always pass an explicit `start_date`** to `/v1/clicks` and `/v1/stats`. The default floor is the plan's retention window, not the beginning of time. - **Don't treat `POST /api/conversions` as a confirmation.** It answers `success` whatever happens; verify through `GET /v1/conversions`. - **Don't poll.** Rate limits are per minute and low on small plans; if you need push, use webhooks (Agency+) at https://gettrack.link/docs/api/webhooks. - **Pinpoint GPS links require the visitor's explicit consent** and are for cases where someone agrees to share their location. Covert location tracking is prohibited and reportable. ## Full documentation - API reference and auth — https://gettrack.link/docs/api/authentication - Links — https://gettrack.link/docs/api/links - Conversions — https://gettrack.link/docs/api/conversions - Webhooks — https://gettrack.link/docs/api/webhooks - CLI — https://gettrack.link/docs/api/cli - MCP — https://gettrack.link/docs/api/mcp - Plans and limits — https://gettrack.link/pricing