Skip to content

join shopify orders to posthog sessions - #395

Merged
sshane merged 10 commits into
masterfrom
posthog-order-join
Sep 10, 2026
Merged

sshane merged 10 commits into
masterfrom
posthog-order-join

Conversation

@sshane

@sshane sshane commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Copies the PostHog distinct id into the Shopify cart so an order can be joined back to the session that produced it.

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.
@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

deployed preview: https://comma-web--pr395-2nzdzlix.web.app

Welcome! Make sure to:

  • read the contributing guidelines
  • mark your PR as a draft until it's ready to review
  • post the preview on Discord; feedback from users will speedup the PR review

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.
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.
@sshane
sshane merged commit d3c961f into master Sep 10, 2026
3 checks passed
@sshane
sshane deleted the posthog-order-join branch September 10, 2026 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant