fix(marketing): bootstrap hero experiment flag for instant, sticky assignment

Merged
SA
4mo ago
+132-2

Why

The landing-hero-positioning experiment evaluates its flag client-side after the /flags network round trip, so first-time visitors see the control hero flash before the variant swaps in, and events fired before the response lands don't carry the $feature property.

What

  • New hero-flag-bootstrap.ts: computes the variant synchronously at posthog.init using PostHog's cross-SDK deterministic assignment hash (sha1("<flag>.<distinct_id>variant") first 15 hex digits / 2^60-1, mapped over the 50/50 variant rollouts), seeded from the existing superset cookie identity — or a freshly generated UUID that posthog-js adopts via bootstrap.distinctID and persists, so refreshes always hash the same identity and can never flip buckets.
  • instrumentation-client.ts passes the bootstrap into posthog.init, so useFeatureFlagVariantKey resolves at hydration instead of after the network round trip.
  • HeroSection imports the flag key from the new module (single source of truth).

Verification

  • Assignment equivalence proven against production: 25+ random distinct_ids computed locally all matched the live us.i.posthog.com/flags response variant exactly.
  • bun run lint clean; turbo typecheck --filter=@superset/marketing clean.

Caveat

The variant order + 50/50 split are mirrored from the flag config (noted in a code comment). If the experiment's rollout changes, drift is safe — behavior falls back to today's swap-on-response — but the bootstrap constant should be updated alongside.

https://claude.ai/code/session_013HwZR8BoCF3QBis8b3x7pm


Summary by cubic

Bootstraps the landing-hero-positioning flag at posthog-js init so the hero renders the right variant during hydration. Removes the control-to-variant flash and ensures the first pageview includes $feature.

  • Bug Fixes

    • Computes the variant synchronously using PostHog’s deterministic hash (sha1("<flag>.<distinct_id>variant")), seeded from the superset cookie or a new UUID adopted via bootstrap.distinctID for sticky assignment.
    • Passes the bootstrap to posthog.init, and centralizes the flag key in hero-flag-bootstrap with HeroSection importing it as the single source of truth.
  • Migration

    • If the experiment’s rollout or variant order changes, update VARIANTS in hero-flag-bootstrap.ts to keep parity; otherwise behavior safely falls back to server-evaluated swapping.

Summary by CodeRabbit

  • New Features

    • Added consistent assignment for the landing page hero experience, supporting controlled variants such as Control and Capability Mac.
  • Bug Fixes

    • Improved hero experiment initialization so visitors receive a stable variant during page loading.