join shopify orders to posthog sessions - #395
Merged
Merged
Conversation
Shopify and comma.ai are different origins, so an order arrives at PostHog from Shopify Flow with no browser context and lands unattributed: distinct_id: unidentified_order:gid://shopify/Order/7549299949631 joined: false The Flow already reads _ph_distinct_id off order.customAttributes and keys the event on it. Nothing was writing it: 0 of 250 recent orders carry the attribute, so every order_completed event is an orphan row. Copy the PostHog distinct id into the cart so it rides along to the order. That is the only value that cannot be recovered later - referrer, utm_source, session id and mc_cid are already on every pageview PostHog captures, so source and campaign are derivable from event history once the order joins to a person. Stamped at cart creation and re-stamped at checkout, because carts persist in localStorage for up to 6 days and can be created before PostHog loads. The Flow's existing joined flag is the deploy check - it is false on every order today and flips true once this ships.
sshane
force-pushed
the
posthog-order-join
branch
from
September 10, 2026 03:57
0b893da to
564eabf
Compare
Contributor
deployed preview: https://comma-web--pr395-2nzdzlix.web.appWelcome! Make sure to:
|
Stamping at checkout meant awaiting a Shopify mutation before window.open() destroyed the page. That put a round trip on the money path, and fetch has no default timeout - if Shopify accepted the connection and never answered, the await never settled and the checkout button hung forever. Do it where the cart note already does it, right after cartLinesAdd. Nothing is navigating there, so nothing is racing. An order cannot exist without a cart line, so coverage is unchanged. ShoppingCart.svelte is untouched again.
To debug why the preview deploy sent no attributes. Remove before merge.
This reverts commit 16dd5aa.
cartAttributesUpdate replaces the whole attribute list, so sending an empty one wipes ids written on an earlier visit. Carts live in localStorage for six days, so that is the same cart.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Copies the PostHog distinct id into the Shopify cart so an order can be joined back to the session that produced it.