I found the answer here: Shopify Permalink Cart Preloading
Using a permalink to create a cart with one or more items in it, extra parameters can be added to the URL that provide additional information (including shipping address, but especially including data such as an affiliate id).
For example,
example-store.myshopify.com/cart/variant_id:quantity?ref=external_referral_id
will result in a cart that, when checked out and completed, will store the referral ID with the order.
solved Pass data from Shopify URL to saved order [closed]