Jack Ellis Member
16 days ago

Passing Cookie To Checkout



I am building an affiliate referal type of application. I am using a script tag to check for a parameter that a customer will arrive on the homepage using for example. mystore.com?aff=test

The value of aff is then stored as a cookie on the page and set to expire in 30 days time. The only problem is ideally I want this cookie to be passed to the checkout so that it is sent with the order webhook.

I was following this discussion up until it mentions saving the value as a cart attribute. I can't find anything online about how to create a cart attribute from the homepage. https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/way-to-access-a-1st-party-cookie-set-on-my-store-from-the-checkout-page-147944

I have looked at using the ?ref= parameter instead but the cookie used for it only lasts 8 hours and I'm not sure If i can change that.

Hope someone can help!

Regards, Jack



Jack Ellis Member
15 days ago

For those that stumble across this.

I used document.cookie standard javascript to create the cookie with a custom name. 

I then used this: 

 jQuery.post('/cart/update.js', { attributes: {trackingcode: cookieval}});

to post the tracking code to the checkout as an attribute. Took me a while to find that line of code but hope it helps someone!