fix: Add more A/B testing examples#1490
Open
arnavnagzirkar wants to merge 1 commit into
Open
Conversation
Contributor
|
@arnavnagzirkar is attempting to deploy a commit to the Vercel Examples Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
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.
Summary
Issue #27 requests A/B testing examples for several platforms (AB Tasty, Featureflow, LaunchDarkly, Optimizely, Split, Unleash). The repo had only two A/B testing examples:
ab-testing-simple(cookie-only) andab-testing-statsig(Statsig + Edge Config).Root cause
Issue #27 requests A/B testing examples for several platforms (AB Tasty, Featureflow, LaunchDarkly, Optimizely, Split, Unleash). The repo had only two A/B testing examples:
ab-testing-simple(cookie-only) andab-testing-statsig(Statsig + Edge Config). LaunchDarkly, Optimizely, and Split each had a feature-flag example but no dedicated A/B testing example. AB Tasty, Featureflow, and Unleash had no examples at all.What changed
Added
edge-middleware/ab-testing-launchdarkly/- a complete A/B testing example using LaunchDarkly's Vercel integration and Edge Config.Files created:
middleware.ts- initializes LaunchDarkly from Edge Config, assigns users to a bucket (controlorexperiment) viavariation(), rewrites/to/{bucket}. Wraps LaunchDarkly calls in try/catch so traffic falls back to the control bucket if initialization fails. Validates the returned flag value against known buckets before rewriting. Creates a fresh LaunchDarkly client per request (required in Edge Middleware -cache()is not available there).lib/constants.ts- cookie name, flag key, bucket names, and typespages/[bucket].tsx- statically generated page for each bucket; shows the assigned bucket and a reset button that clears the user ID cookiepages/_app.tsx- standard Next.js app wrapper using@vercel/examples-uipackage.json,tsconfig.json,turbo.json,vercel.json,tailwind.config.js,postcss.config.js,next-env.d.ts,.eslintrc.json,.gitignore,.npmrc,.env.example,README.mdThe example follows the same pattern as
ab-testing-statsig: middleware assigns a user ID cookie and rewrites to a statically generated bucket page. It uses@vercel/examples-uiv1 to match the other A/B testing examples.Issue
Fixes #27
Issue: #27
Diffstat
Testing
Ran the relevant tests and linter for the changed files while developing.
Kept the change minimal and focused on this one issue.
AI assistance
I used GitHub Copilot to help write parts of this change. I've reviewed and tested it myself, I understand what it does, and I'll follow up on any review feedback.