When you need link attribution
Link attribution credits a visit that came from an affiliate URL without asking the shopper to enter a discount code. It is the optional second path in a Shopify program: more reach than codes alone, at the cost of one small storefront change. This recipe summarizes the mechanism. The exact, current snippet lives in the Shopify guide, which is the canonical copy to paste.
The mechanism
A landing URL carries the affiliate's referral code as ?ref=<code>. A small script in theme.liquid reads that parameter and writes it as a Cart AJAX attribute through Shopify's cart update endpoint. Shopify then preserves that cart attribute to the order as a note attribute, which Attribloom reads from the paid-order webhook to credit the affiliate.
- Read ?ref from the URL and validate it before trusting it.
- Write it as a cart attribute named ref via cart/update.js.
- Shopify carries the cart attribute to the order note attributes.
- Attribloom reads the preserved ref from the signed paid-order webhook.
Validation and conflict handling
Validate the ref before saving it. The shipped recipe accepts only a conservative character set and length, so a malformed or overlong value is ignored rather than written to the cart. This keeps junk and injection attempts out of the order.
A discount code and a preserved ref can disagree. When they identify different affiliates, Attribloom fails closed: the validated discount code takes precedence, and if the two still conflict the order is left unattributed rather than credited to the wrong partner. Note that Attribloom's own /r/<code> redirect does not append ?ref=, so link attribution needs a landing URL that already carries the parameter.