Skip to main content

Shared User Stories

Cross-role journeys that span both Individual and Partner users.

1. Store Referral Attribution

A partner shares a referral link; an individual signs up via that link; the system attributes the signup to the partner’s store.

Actors

ActorRoleWhat They Do
Store partnerPartnerGenerates and shares referral link from /partners/dashboard Referrals tab
VisitorAnonymousClicks referral link, lands on public page
New userIndividual (after signup)Signs up via Clerk, becomes attributed to the store

End-to-End Flow

Step-by-Step

Partner side (before referral):
  1. Partner signs in at /partners/sign-in, lands on /partners/dashboard
  2. Opens Referrals tab → sees referral link with store-{slug}-{hex} code
  3. Copies link via copy button (fires AFFILIATE_REFERRAL_LINK_COPIED PostHog event)
  4. Shares on Instagram, email, in-store signage, etc.
Visitor/consumer side (during referral):
  1. Visitor clicks the shared link → lands on /?ref=store-chen-well-a1b2
  2. Landing page JS stores store-chen-well-a1b2 in a 30-day browser cookie
  3. Visitor browses the site (cookie persists across page navigation)
  4. Visitor clicks “Sign Up” → Clerk sign-up flow
  5. After Clerk auth completes, handle_referral_cookie() fires:
    • Reads ref cookie value
    • Validates format (^[a-zA-Z0-9_\-]+$, max 64 chars)
    • Persists to User.referral_source (generic tracking)
    • Detects store- prefix → calls record_referral_signup_sync()
    • Fires STORE_REFERRAL_SIGNUP PostHog event
  6. User lands on /shrine/dashboard as a normal individual user
Partner side (after referral):
  1. Partner refreshes /partners/dashboard → Referrals tab
  2. Stats update: total clicks, total signups, conversion rate, recent 30d signups
  3. Referred users list shows the new signup (anonymized by default)

Referral Code Convention

Store referral codes follow: store-{slug[:12]}-{4hex}
  • store- prefix discriminates store referrals from generic user referrals
  • Examples: store-chen-well-a1b2, store-vitaminwor-f3e4
  • Generic (non-store) referral codes have no prefix and use a different attribution path

Data Model

TableKey FieldsRole
Storereferral_code, clerk_owner_id, slugPartner’s store entity
StoreReferralstore_id, referral_code, status, referred_clerk_user_idPer-event referral record
User (Clerk metadata)referral_sourceGeneric referral tracking on the individual user

PostHog Events

EventWhenActor
AFFILIATE_REFERRAL_LINK_COPIEDPartner copies linkPartner
STORE_REFERRAL_LINK_CLICKEDVisitor lands with ?ref=store-*Visitor
REFERRAL_SIGNUP_COMPLETEDAny referral signup (generic)New user
STORE_REFERRAL_SIGNUPStore-prefixed referral signupNew user

Where Stats Are Consumed

ConsumerHowStatus
Partner portal (Referrals tab)PartnerPortalState computed varsConfig-gated (on hold per PRD-17)
Integration APIGET /api/v1/analytics/summaryPending (PRD-17 Phase 6)
External Shopify appConsumes Integration APIFuture

Edge Cases

ScenarioBehavior
Invalid referral code (!!!)Cookie not set (sanitized)
Non-store code (friend-code)Generic attribution only — no StoreReferral row
Expired/cleared cookieNo referral attribution
Same user signs up twice with same refOne StoreReferral row per user
Partner without Store entityFalls back to User.referral_code (generic)

2. Protocol Discovery & Adoption

An individual browses the public catalog, adopts a partner’s protocol, and the partner sees adoption metrics.
Documented in detail in:

3. Data Sharing Opt-In

An individual opts in to share adherence data with a partner; the partner sees anonymized feedback in the Lounge.
Documented in detail in: