This is a demo enabled with Uniform Canvas, a Headless CMS and a Headless Commerce engine. The project is enabled for edge-side personalization and A/B testing, however it is not required.
- Contentful + BigCommerce
- Contentful + Commercetools
- Contentstack + BigCommerce
- Contentstack + Commercetools
- Sanity + BigCommerce
- [TODO] Sanity + Commercetools
- [TODO] SalesforceCMS + BigCommerce
- If you are using npm as your package manager, you have to upgrade to the latest release.
- Contentstack: image dimensions are not retrieved, so width and height cannot be set explicitly.
-
Set the
NPM_TOKEN
environment variable to the value provided by your Uniform account manager (see the.npmrc
file). -
Install dependencies
npm install # or yarn
-
Create a new project on uniform.app and configure your desired integrations (see the list of supported integrations above). Your Uniform account manager can help enable relevant integrations.
-
Create API keys under your team on uniform.app:
-
Create an API keys with the following permissions:
Read drafts
andRead intent manifest
Compositions:Read Draft
andCompositions:Read Published
-
Set the
UNIFORM_API_KEY
env var with this value. -
Create an API key for the CLI with wider permissions (must check all checkboxes under
Uniform Presentation Manager
) -
Set the
UPM_CLI_API_KEY
env var with this value.
-
-
Perform publish of optimize manifest by clicking the Publish button from your project's Personalization tab.
-
Copy
.env.example
as.env
. -
Setup your environment variables in
.env
file.# your project id inside uniform dashboard: UNIFORM_PROJECT_ID= ; # application api key (used for Optimize and Canvas) UNIFORM_API_KEY= ; # CLI key: needs all permissions enabled on the Canvas feature level UPM_CLI_API_KEY= ; # you can override where the canvas endpoint is hosted. ; # if value set to external enhancer proxy, all local enhancers will be disabled UNIFORM_PRESENTATION_API_HOST=https://uniform-enhancer-proxy.vercel.app
-
Add connection tokens for your specific system you are connecting to:
# BigCommerce BIGCOMMERCE_STORE_HASH= BIGCOMMERCE_TOKEN= # COMMERCETOOLS CTP_PROJECT_KEY= CTP_CLIENT_SECRET= CTP_CLIENT_ID= CTP_AUTH_URL= CTP_API_URL= # CONTENTFUL CONTENTFUL_SPACE_ID= CONTENTFUL_ENVIRONMENT= CONTENTFUL_CDA_ACCESS_TOKEN= CONTENTFUL_CPA_ACCESS_TOKEN= # CONTENTSTACK CONTENTSTACK_API_KEY= CONTENTSTACK_DELIVERY_TOKEN= CONTENTSTACK_ENVIRONMENT= # SANITY SANITY_PROJECT_ID= SANITY_TOKEN=
-
npm run push:<stack name>
to sync the component library and compositions from disk to your project.where
<stack name>
:contentful-bigcommerce
contentful-commercetools
contentstack-bigcommerce
contentstack-commercetools
sanity-bigcommerce
-
Publish your compositions under /Presentation tab.
The Modena demo site comes with some sample content that must be imported into your CMS. At this time, only the export dump for Contentful is available, content for other CMSs can be provided on demand.
-
Make sure you have an account with Contentful and an empty space (recommended). You can sign up for a free account at Contentful.com.
-
Login to Contentful via CLI:
contentful login
and follow the steps.
Check that you have access to your space via CLI:contentful space list
. -
Run
contentful space import --space-id <your-space-id> --content-file content/contentful-modena-export.json
to import the content (change space id to your Contentful space id).Learn more about Contentful export/import in the official docs here.
-
Create Content delivery / API key tokens in Contentful under
https://app.contentful.com/spaces/your-space/api/keys
. You would need the following values for later:- Space ID
- Content Delivery API - access token
- Content Preview API - access token
-
Run the following command:
npm run dev # or yarn dev
-
Open http://localhost:4120 with your browser to see the result.
-
Set
UNIFORM_NESI_ENABLED=true
in .env file to enable edge-side personalization execution mode. -
Run the following command:
npm run dev:all # or yarn dev:all
-
Open http://localhost:8787 with your browser to see the result.
To import data into Contentstack you must have an empty stack available and created a Management Token in that stack (You need BOTH your Management Token AND you Stack API key to do the import) the following commands can be used:
Login to you Contentstack:
csdx auth:login
With this command you WILL need your Management Token and you Stack API key. https://www.contentstack.com/docs/developers/cli/authenticate-with-the-cli/
csdx auth:tokens:add -m
You add a named token for importing data, assets and definitions into your stack on Contentstack.
To do the actual import:
csdx cm:import -a <The named token you added in above step> -d ./content/contentstack-modena-export
Done!
Remember to publish in Contentstack!
TODO: Coming soon
npm run dev
to start the project.- Open
http://localhost:4120/landing
This option allows to run the application with edge-side personalization capability.
-
Set
UNIFORM_NESI_ENABLED=true
in .env file to enable edge-side personalization execution mode. -
Run the following command:
npm run dev:all # or yarn dev:all
-
Open http://localhost:8787 with your browser to see the result.
If you are running a Jamstack-style deployment (kudos if you do :)) then you would need to kick off a site build when anything is changed within your project (whether it is a new intent added / changed, or a composition is created or updated).
Uniform allows you to configure webhooks allowing to trigger site builds (in Netlify, for example).
In order to create a new webhook:
- Navigate to
Your Project / Settings / Webhooks
- Create a new webhook with a memorable name.
- For the URL, use the webhook that your build system provided you with.
-
Run the following command:
npm run ci:build # or yarn ci:build
-
To test the statically exported site, run
npx serve out
and check if the site renders onlocalhost:5000
. -
To deploy, run the command required to transfer the contents of the
./out
directory to your hosting service.
-
Copy
wrangler.toml.example
aswrangler.toml
-
Populate
account_id
andzone_id
with values from your Cloudflare account. -
Enable edge-side personalization mode by setting this env var to true:
UNIFORM_NESI_ENABLED=true
-
Run the following command:
npm run yolo # or yarn yolo
At the end of this step, the app will be deployed to Worker Sites (static files and the worker code that run edge personalization and a/b testing).
-
Set the following env var values:
# set preview secret which will be appended to the `secret=` query string variable to activate the preview mode: UNIFORM_PREVIEW_SECRET=your-secret # Enable it to fetch pre-published content: UNIFORM_PREVIEW_ENABLED=true # Disable the edge-side personalization by setting this to false: UNIFORM_NESI_ENABLED=false
-
Run build:
npm run build
. -
Run start:
npm run start
. This will start the next.js server in preview onlocalhost:4120
-
Open the preview url by passing the following query string parameters:
slug
- the value of the slug of your compositionsecret
- the value of theUNIFORM_PREVIEW_SECRET
env var.
for example:
http://localhost:4120/api/preview?slug=/landing&secret=your-secret
This will enable preview mode, allowing you to change composition, save and see hot reloaded composition without refreshes or publishing.
-
Set the preview url under your project in uniform.app (
Settings
->Canvas settings
) and save. This will enable the "preview" button inside the composition editor.http://localhost:4120/api/preview?secret=your-secret
Are you doing multiple demos and want to be able to fairly quickly switch between different configurations. A set of ENV files have been created.
They are named .env_<PartOfEnvironmentThatFileConfigures>.example.
To use the files, rename them .NetlifyDeploy and fill in the relevant configuration. If you have configured your "normal" .Env file, it should be fairly selfexplanatory what goes where.
To control the Enviroment in Netlify from a Terminal install the Netlify CLI. https://docs.netlify.com/cli/get-started/
Setup a Netlify site, connected to you Modena code repo. Link your local repo to your Netlify Site by running - https://docs.netlify.com/cli/get-started/#link-and-unlink-sites:
netlify link
You can now use the scripts in package.json and create your own configurations as well. e.g.
npm run netlify:CF-BC-CFlare
# or
yarn netlify:CF-BC-CFlare
Which will configure your Netlify Environment with relevant variables to run Contentful, BigCommerce and Cloudflare
-
You may get the following error during next build/export if
UNIFORM_PREVIEW_ENABLED=true
. Set this value to false and re-run the build/export process.info - Launching 23 workers Error: Found pages with `fallback` enabled: /[id] Pages with `fallback` enabled in `getStaticPaths` can not be exported. See more info here: https://nextjs.org/docs/messages/ssg-fallback-true-export at C:\Users\alex\source\modena\node_modules\next\dist\export\index.js:25:196 at async Span.traceAsyncFn (C:\Users\alex\source\modena\node_modules\next\dist\telemetry\trace\trace.js:6:584)
-
If you are getting 404 when running
npm run dev
, make sure you publish the Optimize manifest from the dashboard / personalization tab at least once.$ uniform optimize manifest download --output ./lib/intentManifest.json ⚠ Error fetching intent manifest https://uniform.app/api/v1/manifest?projectId=f902c648-0a96-4874-890b-cf5670743f86 ❗ 404 Not Found, content No published data for provided API key; it may be invalid, or no publish has occurred since creating it.
Uniform presentation Manager directly support using Uniforms Testing and Personalization capabilites as well. You can easily configure a set of simple Intents and Signals for this demo as well.
We suggest configuring the following Intents in the /Personalization tab (Read about Intents here - https://docs.uniform.app/optimize/intro) each configured with one Query string signal:
- Men
- Women
- Men hipster
- Women Luxury
For each Intent, configure one signal:
- Type: Querystring
- Name: utm
- Querystring Parametername: utm_campaign
- Querystring value:
<same as Intentname - e.g. "Men">
- Leave other settings as
Default
Publish your Intents when done to make them avaible to your build.