All articles

Shopify attribution

Shopify affiliate link tracking with cart attributes: a theme.liquid recipe

Read a ?ref parameter, save it as a Cart AJAX attribute, and let Shopify preserve it to the order so link visits attribute without a discount code.

Published · Last reviewed

Written by Attribloom Engineering · Reviewed by Attribloom Product · Last reviewed

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.

Sources and verification

Primary documentation last checked on 2026-07-20. Each source below links the exact page and its own last-checked date.

Next steps

Frequently asked

Where does the ref value end up on the order?

Shopify copies the Cart AJAX attribute to the order's note attributes, and Attribloom reads it from the signed paid-order webhook to credit the affiliate.

What happens if the discount code and the ref disagree?

Attribloom fails closed. A validated discount code takes precedence, and if the two still identify different affiliates the order is left unattributed to avoid crediting the wrong partner.

Where is the exact snippet to paste?

In the Shopify guide. It is the canonical, current copy, so use it rather than reproducing the script from memory.

In the glossary

Continue reading

App Store attribution

How to attribute App Store subscriptions to an affiliate

App Store attribution

Why iOS affiliate installs are invisible to web attribution tools

Shopify attribution

How to attribute Shopify sales to affiliates without third-party cookies

Pricing models

Commission-only vs revenue-share affiliate programs

App Store attribution

How to validate App Store attribution before release

Payouts

How commission holds and clawbacks protect an affiliate program

iOS program launch

How to start an affiliate program for an iOS app

Shopify program launch

How to launch a Shopify affiliate program

Program economics

Affiliate commission rates: 2026 benchmarks by industry and how to set yours

Program policy

Affiliate program agreement template (2026): full contract and clause guide

Creator strategy

AI UGC vs human creators for affiliate marketing

Custom attribution

How signed conversion postbacks and refunds work

App Store attribution

How to attribute App Store subscription renewals to an affiliate

App Store attribution

RevenueCat affiliate attribution for iOS subscriptions: a server-side pattern

App Store attribution

Affiliate-aware paywalls on iOS: pass referral context without fingerprinting

App Store attribution

iOS affiliate tracking without an SDK: StoreKit 2, appAccountToken, and server notifications

App Store attribution

SKAdNetwork vs affiliate attribution for iOS subscriptions

Shopify attribution

How to run a Shopify affiliate program without editing your theme

Compliance

FTC affiliate disclosure: the complete 2026 guide (rules, examples, placement)

Attribution concepts

What is deferred deep linking? A plain-English guide for attribution
Get startedSee pricingMore articles