-
Notifications
You must be signed in to change notification settings - Fork 318
Add Statsig-driven marketing hero layouts with query overrides #2937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /** `hero_layout` experiment: `0` aside dashboard, `1` bottom + multi-line title, `2` bottom + single-line title. */ | ||
| export type HeroLayoutVariant = 0 | 1 | 2; | ||
|
|
||
| export function normalizeHeroLayout(raw: unknown, fallback: HeroLayoutVariant): HeroLayoutVariant { | ||
| if (typeof raw === 'number' && (raw === 0 || raw === 1 || raw === 2)) { | ||
| return raw; | ||
| } | ||
| const n = parseInt(String(raw).trim(), 10); | ||
| if (n === 0 || n === 1 || n === 2) { | ||
| return n; | ||
| } | ||
| return fallback; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { normalizeHeroLayout, type HeroLayoutVariant } from './hero-layout'; | ||
|
|
||
| /** Query overrides for marketing hero experiments (Statsig parity for local QA). */ | ||
|
|
||
| export const HERO_LAYOUT_QUERY_KEY = 'hero_layout'; | ||
| export const HERO_SUBTITLE_QUERY_KEY = 'hero_subtitle'; | ||
| export const HERO_TITLE_QUERY_KEY = 'hero_title'; | ||
|
|
||
| const MAX_SUBTITLE_LEN = 560; | ||
| const MAX_TITLE_LEN = 160; | ||
|
|
||
| export type HeroQueryBaseline = { | ||
| heroLayout: HeroLayoutVariant; | ||
| heroSubtitle: string; | ||
| heroTitle: string; | ||
| }; | ||
|
|
||
| export type HeroQueryResolved = HeroQueryBaseline; | ||
|
|
||
| export function hasHeroExperimentQueryOverrides(params: URLSearchParams): boolean { | ||
| return ( | ||
| params.has(HERO_LAYOUT_QUERY_KEY) || | ||
| params.has(HERO_SUBTITLE_QUERY_KEY) || | ||
| params.has(HERO_TITLE_QUERY_KEY) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Applies `hero_layout`, `hero_subtitle`, and `hero_title` search params when present. | ||
| * Values are clamped; unknown `hero_layout` values keep the baseline layout. | ||
| */ | ||
| export function resolveHeroQueryOverrides( | ||
| params: URLSearchParams, | ||
| baseline: HeroQueryBaseline | ||
| ): HeroQueryResolved { | ||
| return { | ||
| heroLayout: readHeroLayoutOverride(params, baseline.heroLayout), | ||
| heroSubtitle: readHeroSubtitleOverride(params, baseline.heroSubtitle), | ||
| heroTitle: readHeroTitleOverride(params, baseline.heroTitle) | ||
| }; | ||
| } | ||
|
|
||
| function readHeroLayoutOverride( | ||
| params: URLSearchParams, | ||
| fallback: HeroLayoutVariant | ||
| ): HeroLayoutVariant { | ||
| if (!params.has(HERO_LAYOUT_QUERY_KEY)) return fallback; | ||
| return normalizeHeroLayout(params.get(HERO_LAYOUT_QUERY_KEY), fallback); | ||
| } | ||
|
|
||
| function readHeroSubtitleOverride(params: URLSearchParams, fallback: string): string { | ||
| if (!params.has(HERO_SUBTITLE_QUERY_KEY)) return fallback; | ||
| const raw = params.get(HERO_SUBTITLE_QUERY_KEY); | ||
| if (raw == null) return fallback; | ||
| const t = raw.replace(/\s+/g, ' ').trim(); | ||
| if (t.length === 0) return fallback; | ||
| return t.length > MAX_SUBTITLE_LEN ? t.slice(0, MAX_SUBTITLE_LEN) : t; | ||
| } | ||
|
|
||
| function readHeroTitleOverride(params: URLSearchParams, fallback: string): string { | ||
| if (!params.has(HERO_TITLE_QUERY_KEY)) return fallback; | ||
| const raw = params.get(HERO_TITLE_QUERY_KEY); | ||
| if (raw == null) return fallback; | ||
| const t = raw.replace(/\s+/g, ' ').trim(); | ||
| if (t.length === 0) return fallback; | ||
| return t.length > MAX_TITLE_LEN ? t.slice(0, MAX_TITLE_LEN) : t; | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?hero_titleand?hero_subtitleare processed server-side in+page.server.tsviaresolveHeroQueryOverrides(url.searchParams, ...)and baked into SSR HTML. A shareable URL likehttps://appwrite.io/?hero_title=Your+account+has+been+compromised.+Reset+your+password+nowwill render arbitrary attacker-controlled text as the<h1>on Appwrite's branded homepage — a classic URL-reflection phishing vector. TheMAX_TITLE_LEN = 160/MAX_SUBTITLE_LEN = 560limits still allow ample deceptive copy.Consider gating
hero_titleandhero_subtitlequery overrides to non-production environments (e.g.!building && ENV.PREVIEW) on the server load, while keepinghero_layoutopen if visual QA on production is intentional.