This is StarterKit/Example of Next.js project with direct integration of Uniform Context with Contentstack via Uniform Context app
First, you need provide API keys to connect with empty Uniform App project and empty Stack in Contentstack:
Copy .env.example
into .env
and fill all the keys, for example:
UNIFORM_API_KEY='aaaabbbbccc'
UNIFORM_PROJECT_ID='a99887b0-9e34-4f73-b30a-738118c67ebc'
IMPORTANT: run slug generation script to enable SSR or SSG - npm run generate:slug-page
The API key must have all the write permissions for Uniform Context in order to complete the setup below.
-
npm install
-
Start by running import the Uniform Context definitions from local disk (
/data/context
) into your Uniform project by running this command:npm run push:context
-
Publish the manifest via GUI by clicking the Publish button on the Personalization tab.
-
If the command above is successful, now let's pull the newly imported Context definitions into a local manifest stored in
/lib/context-manifest.json
by running this command:npm run pull:manifest
-
Check
/lib/context-manifest.json
and ensure the manifest is not empty, you should be able to see this in there:{ "project": { "pz": { "agg": { "submitCallForPapers": { "inputs": [ { "dim": "callForPapers" } ] }, "nonTechies": { "inputs": [ { "dim": "1_mkt" } ] }, "techies": { "inputs": [ { "dim": "1_dev" } ] } }, "enr": { "1": { "cap": 100 } }, "sig": { "registrationComplete": { "str": 50, "cap": 100, "dur": "p", "crit": { "op": "&", "type": "G", "clauses": [ { "type": "CK", "match": { "cs": false, "op": "=", "rhs": "true" }, "cookieName": "unfrmconf_registered" } ] } }, "callForPapers": { "str": 50, "cap": 100, "dur": "p", "crit": { "op": "&", "type": "G", "clauses": [ { "type": "QS", "match": { "cs": false, "op": "=", "rhs": "unfrmconf" }, "queryName": "utm_campaign" } ] } } } }, "test": { "whyAttendTest": {} } } }
Follow these steps in order to import the content for this showcase app into your own Contentstack Stack.
-
Create an empty stack in your Contentstack account.
-
Generate the following for your stack
Settings->Tokens
:Stack API key
,Delivery Token
, andManagement Token
and save them in a handy place. -
Install Context App from the Contentstack marketplace (important to do it before import script!)
-
Since Contentstack uses unique per stack UIDs for App Extensions, we need to extract the extension UID before we can import our content. This value will be used for Enrichment Tags and Personalize Criteria fields.
-
Run this API request:
GET https://api.contentstack.io/v3/extensions?include_branch=true&include_marketplace_extensions=true Accept: application/json api_key: <YOUR_STACK_API_KEY> authorization: <YOUR_API_MANAGEMENT_KEY>
The response should return 4 field widgets.
-
Take the value of
uid
property from the object with "Uniform Context - Personalization Criteria" title:{ "uid": "blta7dce40b45a35da1", ... "title": "Uniform Context - Personalization Criteria", ... },
-
Perform value replacement of the
extension_uid
field inside content type export files under./data/contentstack/content_types
with the value extracted in the previous step. In this example, it isblta7dce40b45a35da1
but your value will be different. For convenience, find all instances ofREPLACE_ME_SEE_README_context_personalization_criteria
and replace them with the value ofuid
extracted in the previous step.For this step, replace the
extension_uid
field only within the object that have"uid": "context_personalization_criteria"
:{ "display_name": "Context Personalization Criteria", "extension_uid": "blta7dce40b45a35da1", "field_metadata": { "extension": true }, "uid": "context_personalization_criteria", ... }
-
Repeat the same for the "Uniform Context - Enrichment Tag" field. The value for the
extension_uid
field will need to be extracted from another object in the response:{ "uid": "blt755d67d7dfd462de", ... "title": "Uniform Context - Enrichment Tag", ... },
For this step, replace the
extension_uid
field only within the object that have"uid": "context_enrichment_tags"
. For convenience, find all instances ofREPLACE_ME_SEE_README_context_enrichment_tags
and replace them with the value ofuid
extracted in the previous step:{ "display_name": "Context Enrichment Tags", "extension_uid": "blt755d67d7dfd462de", ... "uid": "context_enrichment_tags", }
-
These two operations This should result in replacements in the the following files:
- hero.json - schema.json - talk.json - talks_list.json
-
Install Contentstack CLI if you haven't done already with
npm install -g @contentstack/cli
-
Run
csdx config:set:region
to set your region, for example:csdx config:set:region NA
-
Create a management token alias via the
csdx auth:tokens:add -m
flow (learn more here). At the end you will get a value you can use in command below. -
Now we are ready to import. Run the following command:
csdx cm:import -a <YOUR_API_MANAGEMENT_TOKEN_ALIAS> -d ./data/contentstack/main
App configurations encryption key: context
Run dev server:
npm run dev
Or run production:
npm run build
npm run start
Open http://localhost:3000 with your browser to see the result.
Export latest Contentstack content model and content (you may need to login into Contentstack CLI first):
```
csdx cm:export -a <YOUR MANAGEMENT TOKEN ALIAS> -d ./data/contentstack
```
Export Uniform Dev
```
npm run pull:context
```
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.