Integrates Eppo with Contentful's Next.JS Blog Starter Template (pages-router version). Use the changes in this repository to help guide your own integration with Eppo's Contentful marketplace app.
Before applying changes to your codebase, follow this guide to install Eppo's Contentful marketplace app and configure the app for your Contentful space.
The example in this codebase shows how we can display variations of a "Hero image" for a blog post. This assumes that you have an eppoExperiment
field attached to every page - Blog post
content type, and that you are allowing component - Rich image
to be assigned as variations for your experiment. Follow this guide to configure your Contentful space.
These instructions assume your codebase started with Contentful's Next.JS Blog Starter Template (pages-router version)
- Run
yarn add @eppo/node-server-sdk@3.4.0
to add or upgrade@eppo/node-server-sdk
. The version must be at least3.4.0
. - Create or update your
.env
file to includeEPPO_SDK_KEY
, along with any other necessary environment variables defined in the .env.example.
- Create an
EppoExperimentFields
GraphQL fragment. See src/lib/graphql/eppoExperimentFields.graphql. - Update your
pageBlogPost
query to include a newPageBlogPostWithExperimentFields
fragment. Seesrc/lib/graphql/pageBlogPost.graphql
in this changeset. - Run
yarn graphql-codegen:generate
to generate your models.
- Create a new "Eppo Client" helper to easily integrate with Eppo. See src/pages/utils/eppo-client.ts.
- Update your blog page with the code needed to override the "hero image" of a blog post. See
src/pages/[slug].page.tsx
in this changeset. Make sure thatgetStaticPaths
is changed togetServerSideProps
.
Run yarn dev
to test out your changes!