|
1 |
| -This is a [Next.js](https://nextjs.org) project showcasing the integration between Optimizely CMS and Optimizely Feature Experimentation. |
| 1 | +This is a [Next.js](https://nextjs.org) project showcasing the integration between [Optimizely Content Management System (CMS)](https://docs.developers.optimizely.com/content-management-system/v1.0.0-CMS-SaaS/docs/overview-saas) and [Optimizely Feature Experimentation](https://docs.developers.optimizely.com/feature-experimentation/docs/introduction). |
2 | 2 |
|
3 | 3 | ## Getting Started
|
4 | 4 |
|
5 | 5 | You need a Optimizely CMS instance and Optimizely Feature Experimentation instance.
|
6 | 6 |
|
7 | 7 | ### Set up environment
|
8 | 8 |
|
9 |
| -Create an `.env` file with the following environment variables: |
| 9 | +Create an `.env` file with the following content. You will learn how to get the values for the variables in the next steps. |
10 | 10 |
|
11 | 11 | ```
|
12 | 12 | OPTIMIZELY_CMS_HOST=
|
13 | 13 | OPTIMIZELY_GRAPH_SINGLE_KEY=
|
14 | 14 | OPTIMIZELY_CMS_CLIENT_ID=
|
15 | 15 | OPTIMIZELY_CMS_CLIENT_SECRET=
|
| 16 | +
|
16 | 17 | OPTIMIZELY_FX_SDK_KEY=
|
| 18 | +OPTIMIZELY_FX_ACCESS_TOKEN= |
17 | 19 | ```
|
18 | 20 |
|
19 |
| -Run `npm run cms:push-config` to create the content types (defined under the directory `/src/components/`) |
| 21 | +### CMS credentials |
| 22 | + |
| 23 | +1. Put the URL of your CMS as the `OPTIMIZELY_CMS_HOST` variable. For example `https://app-1234.cms.optimizely.com/` |
| 24 | +2. Go to your CMS instance → Settings → API Keys. |
| 25 | +3. Under **Render Content**, the _Single Key_ variable, is the variable `OPTIMIZELY_GRAPH_SINGLE_KEY` |
| 26 | +4. In the same page, under **Manage Content**, click "Create API key". |
| 27 | +5. In the Create API dialog, give a name and click "Create API key" |
| 28 | +6. You will see Client ID and Client Secret. Those are the values for `OPTIMIZELY_CMS_CLIENT_ID` and `OPTIMIZELY_CMS_CLIENT_SECRET` variables respectively. |
| 29 | + |
| 30 | +### Feature Experimentation credentials |
| 31 | + |
| 32 | +In the Feature Experimentation app. |
| 33 | + |
| 34 | +1. Go to Settings → Environmnents. |
| 35 | +2. The SDK Key for your environment is the variable `OPTIMIZELY_FX_SDK_KEY`. |
| 36 | + |
| 37 | +> [!Note] |
| 38 | +> If the environment is _secured_, you will need an access token. Create it in the app and set it as the `OPTIMIZELY_FX_ACCESS_TOKEN` environment variable |
| 39 | +
|
| 40 | +## Push the content types model to the CMS |
| 41 | + |
| 42 | +1. Run `npm run cms:login` to test your connection against the Optimizely CMS |
| 43 | +2. Run `npm run cms:push-config` to create the content types defined under `src/components` to the Optimizely CMS. |
| 44 | + |
| 45 | +## Create variations in Feature Experimentation and CMS |
| 46 | + |
| 47 | +This sample site assumes: |
| 48 | + |
| 49 | +- There is a page under `/en/landing` that is running an experiment (i.e., different visitors will get different versions of the page) |
| 50 | +- The existance of a feature flag with the key `tv_genre` (the `tv_genre` contains the rules about which user will get which version) |
| 51 | +- Variations in Feature Experimentation have the same name as variations in CMS. |
| 52 | + |
| 53 | +To reproduce it: |
| 54 | + |
| 55 | +1. In Feature Experimentation, create a feature flag with key `tv_genre`. [Read the Feature Experimentation documentation](https://support.optimizely.com/hc/en-us/articles/38906082664077-Manage-flags) to be familiar with flags. |
| 56 | +2. In Feature Experimentation, create variations for the flag. [Read the Feature Experimentation docs to learn more about flag variations](https://support.optimizely.com/hc/en-us/articles/38676757193485-Create-flag-variations). |
| 57 | + |
| 58 | + For example, create the variations `k_drama`, `action` and `sports` |
| 59 | + |
| 60 | +3. In CMS, create a page with the content type `BlankExperience` with URL `landing`. |
| 61 | +4. In CMS, create variations for that page. You should use the names you used in FX to create variations in the CMS. |
| 62 | + |
| 63 | + In this example, create the variations `k_drama`, `action` and `sports` |
| 64 | + |
| 65 | +## Test your site |
| 66 | + |
| 67 | +1. Run `npm run dev` to start the app |
| 68 | +2. Go to `https://localhost:3000/en/landing`. You should see a variation of the page. |
| 69 | +3. Open the inspector, locate the cookies and remove the cookie `user_id`. |
| 70 | +4. Refresh the page. You might see a different page variation (depending on the variation rules you have defined) |
| 71 | + |
| 72 | +## Learn more about this sample site |
20 | 73 |
|
21 |
| -Run `npm run dev` to start the development server |
| 74 | +- Inspect the file [`/src/lib.fx.ts`](./src/lib/fx.ts) to see the code that uses the Feature Experimentation SDK |
| 75 | +- Inspect the file [`/src/app/en/[...slug]/page.tsx`](./src/app/en/[...slug]/page.tsx) to learn how to fetch a specific variation from your CMS |
22 | 76 |
|
23 |
| -### NPM scripts |
| 77 | +## Further reading |
24 | 78 |
|
25 |
| -- `npm run cms:login` to test your connection agains the Optimizely CMS |
26 |
| -- `npm run cms:push-config` to create the content types defined here in the Optimizely CMS |
| 79 | +- [Optimizely Feature Experimentation JavaScript SDK](https://docs.developers.optimizely.com/feature-experimentation/docs/javascript-sdk) |
| 80 | +- [Create content variations in the Optimizely CMS](https://docs.developers.optimizely.com/content-management-system/v1.0.0-CMS-SaaS/docs/create-content-variation) |
0 commit comments