Associate web session to webhook

LeadDynoMike
Tourist
5 0 3

I am developing an app for shopify and I have a requirement to be able to know which web session matches an order that sends a webhook. I have been digging into the cookies that shopify sets, and I do see one called 'cart' that matches the 'cart_token' webhook field, but the client only gets a 'cart' cookie after they add an item to a cart. I would like something a bit more firm, if possible. There is a _session_id and also a _shopify_s cookie, but neither of these are present in the webhook (registered for order/* events).

The webhook field client_details.session_hash looked promising, but this ID isnt present on the client browser. Other than unreliable IP address or user agent matching, is there a more definitive way of associating the web session to a webhook?

Even if I could somehow add a custom field to the order that shows up in the webhook, that would work too, but I don't see a way to do that either.

Replies 6 (6)

Chris_Saunders
Shopify Staff
591 0 53

Does it really matter to know your customers session information before the manipulate their cart? Even if a user adds something to their cart and abandons it before clicking checkout, you won't get order creation webhooks before then.

The checkout flow works as follows:

  1. Customer adds item(s) to the cart
  2. When customer is ready they click checkout
  3. Customer is presented with shipping information screen and enters their address information -> This creates a checkout object
  4. Customer is presented with payment screen and enters their billing details
  5. Order is finished and customer is shown order success page -> This creates the order object

If you want to know about the creation of checkouts you can subscribe to the checkout/* events which *will* provide you with the cart_token that you might be able to use.

Chris | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

LeadDynoMike
Tourist
5 0 3

It actually does matter to me. My app records data about a user when they first land on the site (even before adding the first item to the cart) and I need to associate that all the way through to checkout for analytical reasons. 

Chris_Saunders
Shopify Staff
591 0 53

You are going to need to figure out a way pass some kind of information off to your own server then.  We don't provide anything useful in the session, nor in the webhooks.

If you want to be able to get a cart for each viewer, add a hidden item to the cart so you can generate a cart token and then find a way to pass that off to your server so you can do the association later.

Chris | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

HunkyBill
Shopify Expert
4850 60 557

... and don't forget to remove the hidden item you added to the cart, to generate the cart token, because checkout does not go so well with hidden items in the cart 🙂

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com

Chris_Saunders
Shopify Staff
591 0 53

Indeed! I meant to say that 😛

Chris | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Allan_Gourdie
Shopify Partner
20 0 1

Bill/Chris, if I am adding hidden item like 

<input type="hidden" name="attributes[myval]" value="my val is 5" />

and leaving it in the cart, is that going to cause problems on checkout?  Don't hidden attributes get passed in webhooks?