Carry the visit token into your product
Keep the visit token from a Handline page through sign-up and store it with the new account, so outcomes trace back to the ad that brought the visitor.
Do this once, when your product starts running campaigns through Handline. It is the first of the two things your product does; the second is to report outcomes. Together they take about an hour.
How the token reaches you#
A visitor clicks a call to action on a Handline page. If the link leads to your product's site, or to a destination allowed in the product's page settings, Handline adds ?hl_v=<token> to it.
The token names the product and the visit, and is signed by Handline. It carries nothing that identifies a person. It is valid for 180 days. It looks like v1.<payload>.<signature>, in URL-safe characters.
Keep it through sign-up#
Read the token on arrival
In the browser or on your server, read
hl_vfrom the address the visitor arrived on.Keep it while the visitor browses
Store it in session storage, a cookie or your own session, and add it to links inside your product if the visitor may browse before signing up.
Send it with the sign-up form
Put it in a hidden field, so your sign-up handler receives it.
Store it with the new account
Save the token on the account. Report the sign-up with it, and keep it for later stages.
With the helper package:
import { readToken, keepToken, carryToken } from '@handline/handoff'; const token = readToken(location.href);if (token) keepToken(token, sessionStorage); // A link inside your product, if the visitor browses before signing uplink.href = carryToken(link.href, sessionStorage.getItem('hl_v')); // The sign-up formform.elements.hl_v.value = sessionStorage.getItem('hl_v') ?? '';Without it, read the parameter yourself:
const token = new URL(location.href).searchParams.get('hl_v');if (token && /^v1\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(token)) sessionStorage.setItem('hl_v', token);Verify it on your server#
Verifying is optional: the outcomes API checks every token itself, and an outcome with a token that fails is still recorded, untraced. Verify if you want to store only real tokens.
The helper's verifyToken returns the product id, visit id and dates, or null for a forged, expired or malformed token:
import { verifyToken } from '@handline/handoff'; const visit = await verifyToken(req.body.hl_v, { productId: process.env.HANDLINE_PRODUCT_ID });await db.accounts.update(user.id, { handlineToken: visit ? req.body.hl_v : null });Without the helper, verify the Ed25519 signature with Handline's public keys, published at https://app.handline.io/.well-known/handline-visit-keys as { "keys": [ { "kty": "OKP", "crv": "Ed25519", "x": "…", "kid": "…" } ] }. The payload is base64url JSON with p (product id), v (visit id), iat and exp (unix seconds) and k (the key id). The signature covers v1.<payload>.
export async function verifyVisitToken(token: string, productId: string) { const [version, payload, signature] = token.split('.'); if (version !== 'v1' || !payload || !signature) return null; const claims = JSON.parse(Buffer.from(payload, 'base64url').toString('utf8')); const res = await fetch('https://app.handline.io/.well-known/handline-visit-keys'); const { keys } = await res.json(); const jwk = keys.find((k: { kid: string }) => k.kid === claims.k); if (!jwk) return null; const key = await crypto.subtle.importKey('jwk', { kty: 'OKP', crv: 'Ed25519', x: jwk.x }, { name: 'Ed25519' }, false, ['verify']); const ok = await crypto.subtle.verify({ name: 'Ed25519' }, key, Buffer.from(signature, 'base64url'), new TextEncoder().encode(`${version}.${payload}`)); if (!ok || claims.exp * 1000 < Date.now() || claims.p !== productId) return null; return { visitId: claims.v as string };}Cache the keys for about an hour rather than fetching them on every sign-up.
Test the hand-off#
- On Set-up, open the test link. It is a page address with
?hl_test=1, and its visits are tests. - Sign up in your product.
- Report the outcome with the token your product kept and
"test": true.
The Set-up checklist marks the hand-off done when a test outcome comes back traced to a test visit. Test visits and outcomes never appear in results and are never sent to an ad platform.
If outcomes arrive untraced#
- The token never reached the sign-up handler: check the hidden field, and that links inside your product carry it.
- The link left the allowed destinations: Handline adds the token only to links to your product's site and the destinations in its page settings.
- The token was cut or changed: store it exactly as received, up to 400 characters.
Report every outcome even when it has no token. Results shows the traced share by day; a sudden drop means the hand-off broke, and Handline opens a work item.
Was this page helpful?