Affiliate link and referral cookie flow
This guide explains how to integrate affiliate tracking with Upmind when building a custom client area. It covers:- Affiliate link visits
- Referral signups
- Referral orders
Core concept
referral_cookie is an opaque, encrypted string used by the affiliate abstraction layer. Your frontend should:
- Send it when available
- Store any updated value returned by the API
- Re-send it on registration and order conversion requests
referral_cookie; treat it as a transport value.
Post Affiliate Pro
When PAP is configured in your Brand’s settings, the click data will be sent to PAP’s tracking URL, and thereferral_cookie will contain the visitorId, which PAP uses to correlate link clicks with conversions. Typically, PAP affiliate links can be identified by the presence of an affiliate ID in the query string, e.g. ?aid=abc123.
End-to-end flow
- The visitor lands on an affiliate URL.
-
Frontend calls
POST /api/affiliate_link/visitwith visit metadata and existingreferral_cookie(if present). -
API responds with
redirect_urland optionally a refreshedreferral_cookie(+ max age). - Frontend sets/updates the browser cookie and redirects the visitor.
-
When the visitor registers (e.g.
/api/clients/register), sendreferral_cookie. -
When converting basket to invoice (
/api/orders/<order_id>/convert), sendreferral_cookieagain.
API 1: Track affiliate link visit
Endpoint:POST https://api.upmind.io/api/affiliate_link/visit
Origin: https://xyz.upmind.app
Request body fields:
-
visit_url(required): Full current browser URL, including query string and hash.-
To configure the onward redirect for Post Affiliate Pro links, it’s possible to add a &redirect=
parameter to affiliate links; ensure this is included in
visit_urlfor this to be returned asredirect_urlin the response. As long as the redirect URL is on the same domain as the visit URL or is added in your Upmind brand’s domain settings, it will be permitted as a redirect target; otherwise, your configured default redirect URL will be used; this is a security measure to prevent malicious redirects.
-
To configure the onward redirect for Post Affiliate Pro links, it’s possible to add a &redirect=
parameter to affiliate links; ensure this is included in
-
referrer_url(required): Browser referrer URL. -
user_agent(required): Browser user agent string. -
referral_cookie(optional): Existing referral cookie value, if already present.
-
If
data.referral_cookieexists, set/update a first-party cookie in the browser. -
Use
data.referral_cookie_max_ageas the cookie lifetime when present. -
Redirect the visitor to
data.redirect_url.
API 2: Send referral cookie during client registration
Supported registration endpoints:-
POST /api/clients/register- Standard client registration endpoint -
POST /api/clients/register/guest- Guest client creation endpoint for basket operations -
POST /api/clients/<client_id>/complete_registration- Guest registration completion endpoint
referral_cookie(optional): Pass the current cookie value from the browser.
API 3: Send referral cookie when converting basket to order invoice
Endpoint:PATCH /api/orders/<order_id>/convert
referral_cookie(optional): Pass the current cookie value so the order referral can be associated.
- The referral cookie is stored against the initial order invoice and later used to record the affiliate sale after payment is made.
Recommended integration pattern (Frontend)
-
On every page load where affiliate params may be present, call
/api/affiliate_link/visit. - Always include the current cookie value in that call when available.
- Persist returned cookie as a first-party cookie.
-
Include cookie value in:
-
/api/clients/registeror/api/clients/register/guestor/api/clients/<client_id>/complete_registration -
/api/orders/<order_id>/convert
-
- Do not attempt to modify cookie contents in frontend code.
Implementation checklist
-
Capture and send
visit_url,referrer_url,user_agenton link visit -
Persist returned
referral_cookie -
Pass
referral_cookieduring registration -
Pass
referral_cookieduring basket conversion - Allow graceful behavior if the cookie is absent

