Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
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.
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:
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
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.
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
... 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 🙂
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
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?