Example marketing site showcasing Personalization features.
Powered by Next.js (App Router) and Hygraph (formerly known as GraphCMS).
Styled with Tailwind CSS and Radix UI components.
For a detailed guide on the content variant setup, see docs.md.
- Goal: Demonstrate a simple, pragmatic pattern to personalize a marketing site using Hygraph content variants.
- Audience targeting:
- Provide a segment via URL:
?segment={slug}or via cookie:segment={slug}. - Optionally force a specific variant via URL:
?variant={id}(overrides segment matching when present). - Or use the "Segment Simulator" dropdown at the bottom right-hand corner to set the cookie via frontend.
- Provide a segment via URL:
- Fetching strategy:
- Queries request base content plus
variantsfiltered by segment or variant id:- See
lib/home-queries.tsandlib/article-queries.tswherevariants(where: { OR: [{ segments_some: { slug: $segment } }, { id: $variantId }] })is used.
- See
- Queries request base content plus
- Overlay strategy:
lib/utils.tsprovidesapplyVariant(base)which merges the first matched variant into the base object.- Inputs are derived via
getSegment(searchParams)(URL orsegmentcookie) andgetVariantId(searchParams)(URL only). - Example flow:
const segment = await getSegment(searchParams); const variantId = await getVariantId(searchParams); const home = await getHomePageData(segment, variantId); const personalized = applyVariant(home);
- Try it locally:
- Start the dev server, then open:
http://localhost:3434/?segment=<segment-slug>http://localhost:3434/?variant=<variant-id>
- Or set a cookie in the browser console:
document.cookie = 'segment=<segment-slug>; path=/';
- Or use the "Segment Simulator" dropdown at the bottom right-hand corner to set the cookie via frontend.
- Start the dev server, then open:
- Note: The overlay currently applies the first matched variant. Extend
applyVariantif you need multi-variant resolution.
- Framework: Next.js 15, React 19
- Styling: Tailwind CSS (+
@tailwindcss/typography) - UI: Radix UI, Lucide Icons
- CMS: Hygraph (GraphCMS)
- Package manager: pnpm
- Clone the repo and install dependencies:
pnpm install- Create a
.env.localat the project root and add your Hygraph credentials:
# Required
HYGRAPH_API_URL="https://<your-hygraph-endpoint>/graphql"
# Optional (needed for private or draft content)
HYGRAPH_API_TOKEN="<permanent-auth-token>"Example endpoint structure: https://{region-cluster}.cdn.hygraph.dev/content/{projectId}/{environment}/graphql
For example: https://eu-central-1-dev-1.cdn.hygraph.dev/content/cmecsfqn0005o07vp4gc3dqxu/master/graphql.
3. Run the app in development:
pnpm devThe app will start on http://localhost:3434.
pnpm dev # Start Next.js dev server (port 3434)
pnpm build # Production build
pnpm start # Run built app
pnpm lint # Lint with Next.js ESLintapp/: App Router routes, layouts, and pagescomponents/: Reusable UI componentslib/: Data layer and utilities (e.g.,graphql-client.ts, queries)hooks/: Custom React hookspublic/: Static assetsstyles/: Global stylestailwind.config.ts: Tailwind configuration
- GraphQL requests are handled in
lib/graphql-client.tsand revalidated every 60s for ISR. - Set
HYGRAPH_API_URLand (optionally)HYGRAPH_API_TOKENin.env.local. - See
docs.mdanddocs_simplyfied.mdfor notes on variant overlays and querying examples.
- Recommended: Vercel
- Add
HYGRAPH_API_URLandHYGRAPH_API_TOKENas project Environment Variables - Build command:
pnpm build - Start command:
pnpm start(if not using Vercel’s default)
- Add
next.config.mjsis configured to ignore TypeScript and ESLint errors during builds and to use unoptimized images; adjust for stricter CI if needed.- Package manager is pinned to pnpm in
package.json. Use pnpm to avoid lockfile churn.