@remkoj/optimizely-one-nextjs 6.0.0-pre8 → 6.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/LICENSE +12 -12
  2. package/README.md +168 -164
  3. package/dist/api/index.js +5 -3
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/client-types.d.ts +74 -3
  6. package/dist/client-types.js +5 -1
  7. package/dist/client-types.js.map +1 -1
  8. package/dist/components/context.d.ts +218 -64
  9. package/dist/components/context.js +159 -67
  10. package/dist/components/context.js.map +1 -1
  11. package/dist/components/index.d.ts +1 -0
  12. package/dist/components/optimizely-one-gadget/_notice.js +1 -0
  13. package/dist/components/optimizely-one-gadget/_notice.js.map +1 -1
  14. package/dist/components/optimizely-one-gadget/audiences-panel.js +1 -0
  15. package/dist/components/optimizely-one-gadget/audiences-panel.js.map +1 -1
  16. package/dist/components/optimizely-one-gadget/exp-panel.js +1 -0
  17. package/dist/components/optimizely-one-gadget/exp-panel.js.map +1 -1
  18. package/dist/components/optimizely-one-gadget/gadget.js +24 -16
  19. package/dist/components/optimizely-one-gadget/gadget.js.map +1 -1
  20. package/dist/components/optimizely-one-gadget/goals-panel.js +1 -0
  21. package/dist/components/optimizely-one-gadget/goals-panel.js.map +1 -1
  22. package/dist/components/optimizely-one-gadget/graph-panel.js +1 -0
  23. package/dist/components/optimizely-one-gadget/graph-panel.js.map +1 -1
  24. package/dist/components/optimizely-one-gadget/interests-panel.js +1 -0
  25. package/dist/components/optimizely-one-gadget/interests-panel.js.map +1 -1
  26. package/dist/components/optimizely-one-gadget/logo.js +1 -0
  27. package/dist/components/optimizely-one-gadget/logo.js.map +1 -1
  28. package/dist/components/optimizely-one-gadget/profile-panel.js +1 -0
  29. package/dist/components/optimizely-one-gadget/profile-panel.js.map +1 -1
  30. package/dist/components/page-activator.js +12 -31
  31. package/dist/components/page-activator.js.map +1 -1
  32. package/dist/components/service-filters.d.ts +46 -0
  33. package/dist/components/service-filters.js +56 -0
  34. package/dist/components/service-filters.js.map +1 -0
  35. package/dist/components/types.d.ts +2 -0
  36. package/dist/components/types.js +2 -0
  37. package/dist/components/types.js.map +1 -0
  38. package/dist/components/use-local-state.d.ts +24 -0
  39. package/dist/components/use-local-state.js +55 -0
  40. package/dist/components/use-local-state.js.map +1 -0
  41. package/dist/config.d.ts +119 -0
  42. package/dist/config.js +101 -2
  43. package/dist/config.js.map +1 -1
  44. package/dist/env-vars.d.ts +3 -0
  45. package/dist/env-vars.js +3 -0
  46. package/dist/env-vars.js.map +1 -1
  47. package/dist/products/content-recs/client.d.ts +10 -3
  48. package/dist/products/content-recs/client.js +38 -2
  49. package/dist/products/content-recs/client.js.map +1 -1
  50. package/dist/products/content-recs/snippet.js +16 -16
  51. package/dist/{api/content-goals.d.ts → products/content-recs/webservice-goals.d.ts} +1 -1
  52. package/dist/{api/content-goals.js → products/content-recs/webservice-goals.js} +4 -4
  53. package/dist/products/content-recs/webservice-goals.js.map +1 -0
  54. package/dist/{api/content-recs.d.ts → products/content-recs/webservice.d.ts} +1 -1
  55. package/dist/{api/content-recs.js → products/content-recs/webservice.js} +13 -12
  56. package/dist/products/content-recs/webservice.js.map +1 -0
  57. package/dist/products/data-platform/client.d.ts +11 -2
  58. package/dist/products/data-platform/client.js +52 -9
  59. package/dist/products/data-platform/client.js.map +1 -1
  60. package/dist/products/data-platform/snippet.js +3 -3
  61. package/dist/products/data-platform/snippet.js.map +1 -1
  62. package/dist/products/feature-experimentation/provider.d.ts +7 -0
  63. package/dist/products/feature-experimentation/provider.js +32 -0
  64. package/dist/products/feature-experimentation/provider.js.map +1 -0
  65. package/dist/products/web-experimentation/client.d.ts +5 -2
  66. package/dist/products/web-experimentation/client.js +21 -7
  67. package/dist/products/web-experimentation/client.js.map +1 -1
  68. package/dist/products/web-experimentation/snippet.js +17 -17
  69. package/dist/products/web-experimentation/snippet.js.map +1 -1
  70. package/dist/{api/experimentation-api.d.ts → products/web-experimentation/webservice.d.ts} +1 -1
  71. package/dist/{api/experimentation-api.js → products/web-experimentation/webservice.js} +2 -2
  72. package/dist/products/web-experimentation/webservice.js.map +1 -0
  73. package/dist/server-components/index.d.ts +3 -0
  74. package/dist/server-components/index.js +3 -0
  75. package/dist/server-components/index.js.map +1 -1
  76. package/dist/{components/optimizely-one-gadget/index.d.ts → server-components/optimizely-one-gadget.d.ts} +1 -1
  77. package/dist/{components/optimizely-one-gadget/index.js → server-components/optimizely-one-gadget.js} +4 -5
  78. package/dist/server-components/optimizely-one-gadget.js.map +1 -0
  79. package/dist/server-components/optimizely-one.d.ts +219 -0
  80. package/dist/server-components/optimizely-one.js +112 -0
  81. package/dist/server-components/optimizely-one.js.map +1 -0
  82. package/dist/server.d.ts +1 -2
  83. package/dist/server.js +1 -6
  84. package/dist/server.js.map +1 -1
  85. package/dist/styles.css +2 -2
  86. package/dist/utils/products.d.ts +92 -0
  87. package/dist/utils/products.js +84 -0
  88. package/dist/utils/products.js.map +1 -0
  89. package/package.json +25 -30
  90. package/dist/api/content-goals.js.map +0 -1
  91. package/dist/api/content-recs.js.map +0 -1
  92. package/dist/api/experimentation-api.js.map +0 -1
  93. package/dist/components/optimizely-one-gadget/index.js.map +0 -1
  94. package/dist/components/rsc.d.ts +0 -2
  95. package/dist/components/rsc.js +0 -3
  96. package/dist/components/rsc.js.map +0 -1
package/LICENSE CHANGED
@@ -1,13 +1,13 @@
1
- Copyright 2024 Remko Jantzen
2
-
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
1
+ Copyright 2024 Remko Jantzen
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
13
  limitations under the License.
package/README.md CHANGED
@@ -1,164 +1,168 @@
1
- # Next.JS Optimizely One toolkit <!-- omit in toc -->
2
- React components (both client & server) to integrate the browser-side products from Optimizely (Web Experimentation, Data Platform & Content Analytics / Recommendations)
3
-
4
- ## Table of Contents <!-- omit in toc -->
5
- - [1. Requirements](#1-requirements)
6
- - [2. Installation \& Configuration](#2-installation--configuration)
7
- - [2.1. Add API Routes](#21-add-api-routes)
8
- - [2.2. Add Provider \& PageTracker to your layout](#22-add-provider--pagetracker-to-your-layout)
9
- - [2.3. Instrument your site with additional events](#23-instrument-your-site-with-additional-events)
10
- - [2.4. Enable session cookie for Visitor ID](#24-enable-session-cookie-for-visitor-id)
11
- - [2.5. Configuration](#25-configuration)
12
- - [2.5.1. Prevent key leakage and unauthorized access](#251-prevent-key-leakage-and-unauthorized-access)
13
- - [2.5.2. List of supported environment variables](#252-list-of-supported-environment-variables)
14
- - [3. Usage](#3-usage)
15
- - [3.1. Optimizely One Gadget](#31-optimizely-one-gadget)
16
- - [3.2. Selecting the Web Experimentation project in browser](#32-selecting-the-web-experimentation-project-in-browser)
17
-
18
-
19
- ## 1. Requirements
20
- - Next.JS 14.2+
21
- - TypeScript 5+
22
- - Access to the Optimizely One Products
23
-
24
- ## 2. Installation & Configuration
25
-
26
- Start by adding the package to your project:
27
- `yarn add @remkoj/optimizely-one-nextjs`
28
-
29
- ### 2.1. Add API Routes
30
- Then make the service endpoints available by creating a new API route within Next.JS. For the app router this is done by creating this file:
31
-
32
- `app/api/me/[[...path]]/route.ts`
33
-
34
- Put the following code in this file to use the API Route handler from the package:
35
-
36
- ```typescript
37
- import { createOptimizelyOneApi } from '@remkoj/optimizely-one-nextjs/api';
38
-
39
- const handler = createOptimizelyOneApi()
40
-
41
- export const GET = handler
42
- export const POST = handler
43
- export const runtime = 'nodejs' // 'nodejs' (default) | 'edge'
44
- export const dynamic = 'force-dynamic'
45
- export const dynamicParams = true
46
- export const fetchCache = 'default-no-store'
47
- ```
48
-
49
- ### 2.2. Add Provider & PageTracker to your layout
50
- Within the global layout (or your ["third party providers component"](https://vercel.com/guides/react-context-state-management-nextjs#rendering-third-party-context-providers-in-server-components), whatever applies best), add the Optimizely One Scripts (`Scripts.Header` & `Scripts.Footer`), Context Provider (`OptimizelyOneProvider`), Page Activator (`PageActivator`), and - if you want to - the demo gadget (`OptimizelyOneGadget`).
51
-
52
- ```typescript
53
- import { Scripts } from '@remkoj/optimizely-one-nextjs/server'
54
- import { OptimizelyOneProvider, PageActivator, OptimizelyOneGadget } from '@remkoj/optimizely-one-nextjs/client'
55
-
56
- export type RootLayoutProps = {
57
- children: React.ReactNode
58
- }
59
-
60
- export default function RootLayout({ children }: RootLayoutProps)
61
- {
62
- return <html>
63
- <head>
64
- <Scripts.Header />
65
- </head>
66
- <body>
67
- <OptimizelyOneProvider value={{ debug: true }}>
68
- <PageActivator />
69
- { children }
70
- <OptimizelyOneGadget servicePrefix='/api/me' refreshInterval={ 2000 } />
71
- </OptimizelyOneProvider>
72
- <Scripts.Footer />
73
- </body>
74
- </html>
75
- }
76
- ```
77
-
78
- ### 2.3. Instrument your site with additional events
79
- Whenever you want to track additional events, use the provided hook to get to the context and send events.
80
-
81
- ```typescript
82
- 'use client'
83
- import React, { type FunctionComponent } from 'react'
84
- import { useOptimizelyOne } from '@remkoj/optimizely-one-nextjs/client'
85
-
86
- export const YourComponent : FunctionComponent<{}> = props => {
87
- const opti = useOptimizelyOne()
88
-
89
- function handler()
90
- {
91
- opti?.track({ event: "name", action: "action" })
92
- }
93
-
94
- return <button onClick={() => handler()}>Output</button>
95
- }
96
- ```
97
-
98
- ### 2.4. Enable session cookie for Visitor ID
99
- Within your middleware (`src/middleware.ts`), use the Session to make sure each visitor gets a unique Visitor ID. Either create this middleware within your project or add this logic to it.
100
-
101
- ```typescript
102
- import { NextResponse, type NextRequest } from "next/server"
103
- import { Session } from '@remkoj/optimizely-one-nextjs/api'
104
-
105
- export function middleware(request: NextRequest)
106
- {
107
- // Get the response
108
- const response = NextResponse.next()
109
-
110
- // Inject the Visitor ID cookie, with a sliding expiry
111
- const visitorId = Session.getOrCreateVisitorId(request)
112
- Session.addVisitorId(response, visitorId)
113
-
114
- // Return the response
115
- return response
116
- }
117
-
118
- export const config = {
119
- matcher: [
120
- // Skip all internal paths and paths with a '.'
121
- '/((?!.*\\.|ui|api|assets|_next\\/static|_next\\/image|_vercel).*)',
122
- ]
123
- }
124
- ```
125
-
126
- ### 2.5. Configuration
127
- The Optimizely One Integration is configured by setting the appropriate environment variables.
128
-
129
- #### 2.5.1. Prevent key leakage and unauthorized access
130
- These environment variables must ***never*** be, consider them compromised when
131
- 1. Comitted into your source control system. Set them using the method available on your hosting environment.
132
- 2. Configured to be exposed to the browser
133
-
134
- Locally, you may use a `.env.local` file, which must be added to the ignore list of you source control system.
135
-
136
- #### 2.5.2. List of supported environment variables
137
- | Product | Environment Variable | Default Value | Purpose |
138
- | - | - | - | - |
139
- | *Global* | OPTIMIZELY_ONE_HELPER | 0 | Set to "1" to enable the Optimizely One Demo tools.<br/>- Allow overriding of the WebEx project ID through the 'pid' query string parameter <br/>- Enable the `<OptimizelyOneGadget />` component.
140
- | *Global* | OPTIMIZELY_DEBUG | 0 | Set to "1" to enable debugging output. ***Note:*** This setting is shared across the different packages - it will enable debug mode for all of them |
141
- | *Global* | OPTIMIZELY_FRONTEND_COOKIE | visitorId | The cookie used to track the current Visitor ID |
142
- | Data Platform | OPTIMIZELY_DATAPLATFORM_ID | | The public or private key of your ODP instance, use the private key to enable fetching of visitor behaviour / profile information |
143
- | Data Platform | OPTIMIZLEY_DATAPLATFORM_ENDPOINT | https://api.zaius.com/ | The endpoint used to read data from ODP |
144
- | Data Platform | OPTIMIZELY_DATAPLATFORM_BATCH_SIZE | 25 | The maximum number of items to fetch in one request, if there are more results, paging will be used to get the full data set |
145
- | Content Intelligence & Recommendations | OPTIMIZELY_CONTENTRECS_CLIENT | | The client ID for Content Intelligence & Recommendations |
146
- | Content Intelligence & Recommendations | OPTIMIZELY_CONTENTRECS_DELIVERY | 0 | The Delivery ID setup in the main tracking script |
147
- | Content Intelligence & Recommendations | OPTIMIZELY_CONTENTRECS_DELIVERY_KEY | | The Delivery Key used to fetch visitor topic and goal information |
148
- | Content Intelligence & Recommendations | OPTIMIZELY_CONTENTRECS_DOMAIN | idio.co | The main domain used for the Content Recs instance, without the prefix (such as "manager", "s", "api", etc...) |
149
- | Web Experimentation | OPTIMIZELY_WEB_EXPERIMENTATION_PROJECT | | The project identifier of the Web Experimentation Project |
150
-
151
- ## 3. Usage
152
- When leveraging the components and structure from the installation, everything should work immediately.
153
-
154
- ### 3.1. Optimizely One Gadget
155
- The OptimizelyOneGadget will only show if the following two criteria have been met, this ensures that the gadget is only available when it has intentionally ben enabled:
156
- 1. The environment variable `OPTIMIZELY_ONE_HELPER` has been set to "1"
157
- 2. A test-cookie has been added to the browser using the 'Add test cookie' feature of the [Optimizely Assistant Chrome Add-On](https://support.optimizely.com/hc/en-us/articles/4410289500301-Optimizely-Experimentation-Assistant-Chrome-extension)
158
-
159
- Using the Optimizely One Gadget it is possible to demonstrate the in-session behaviour tracking and analysis performed by the configured Optimizely products.
160
-
161
- ### 3.2. Selecting the Web Experimentation project in browser
162
- When the `OPTIMIZELY_ONE_HELPER` is set to "1" - or the Scripts.Header component has been instructed to do so explicitly - it is possible to change the Optimizely Web Experimentation project on the fly. This is done by adding a query string parameter `?pid=`, with the new project id.
163
-
164
- The project id is persisted in localStorage with the key `_pid` and needs to be removed manually to revert back to the configured Web Experimentation project.
1
+ # Next.JS Optimizely One toolkit <!-- omit in toc -->
2
+
3
+ > [!WARNING]
4
+ > There'll be an update of Optimizely SaaS CMS that is incompatible with all SDK versions prior to 5.1.6. If you don't upgrade, you will see empty pages (main website) and "Component not found" messages (preview).
5
+
6
+ React components (both client & server) to integrate the browser-side products from Optimizely (Web Experimentation, Data Platform & Content Analytics / Recommendations)
7
+
8
+ ## Table of Contents <!-- omit in toc -->
9
+ - [1. Requirements](#1-requirements)
10
+ - [2. Installation \& Configuration](#2-installation--configuration)
11
+ - [2.1. Add API Routes](#21-add-api-routes)
12
+ - [2.2. Add Provider \& PageTracker to your layout](#22-add-provider--pagetracker-to-your-layout)
13
+ - [2.3. Instrument your site with additional events](#23-instrument-your-site-with-additional-events)
14
+ - [2.4. Enable session cookie for Visitor ID](#24-enable-session-cookie-for-visitor-id)
15
+ - [2.5. Configuration](#25-configuration)
16
+ - [2.5.1. Prevent key leakage and unauthorized access](#251-prevent-key-leakage-and-unauthorized-access)
17
+ - [2.5.2. List of supported environment variables](#252-list-of-supported-environment-variables)
18
+ - [3. Usage](#3-usage)
19
+ - [3.1. Optimizely One Gadget](#31-optimizely-one-gadget)
20
+ - [3.2. Selecting the Web Experimentation project in browser](#32-selecting-the-web-experimentation-project-in-browser)
21
+
22
+
23
+ ## 1. Requirements
24
+ - Next.JS 14.2+
25
+ - TypeScript 5+
26
+ - Access to the Optimizely One Products
27
+
28
+ ## 2. Installation & Configuration
29
+
30
+ Start by adding the package to your project:
31
+ `yarn add @remkoj/optimizely-one-nextjs`
32
+
33
+ ### 2.1. Add API Routes
34
+ Then make the service endpoints available by creating a new API route within Next.JS. For the app router this is done by creating this file:
35
+
36
+ `app/api/me/[[...path]]/route.ts`
37
+
38
+ Put the following code in this file to use the API Route handler from the package:
39
+
40
+ ```typescript
41
+ import { createOptimizelyOneApi } from '@remkoj/optimizely-one-nextjs/api';
42
+
43
+ const handler = createOptimizelyOneApi()
44
+
45
+ export const GET = handler
46
+ export const POST = handler
47
+ export const runtime = 'nodejs' // 'nodejs' (default) | 'edge'
48
+ export const dynamic = 'force-dynamic'
49
+ export const dynamicParams = true
50
+ export const fetchCache = 'default-no-store'
51
+ ```
52
+
53
+ ### 2.2. Add Provider & PageTracker to your layout
54
+ Within the global layout (or your ["third party providers component"](https://vercel.com/guides/react-context-state-management-nextjs#rendering-third-party-context-providers-in-server-components), whatever applies best), add the Optimizely One Scripts (`Scripts.Header` & `Scripts.Footer`), Context Provider (`OptimizelyOneProvider`), Page Activator (`PageActivator`), and - if you want to - the demo gadget (`OptimizelyOneGadget`).
55
+
56
+ ```typescript
57
+ import { Scripts } from '@remkoj/optimizely-one-nextjs/server'
58
+ import { OptimizelyOneProvider, PageActivator, OptimizelyOneGadget } from '@remkoj/optimizely-one-nextjs/client'
59
+
60
+ export type RootLayoutProps = {
61
+ children: React.ReactNode
62
+ }
63
+
64
+ export default function RootLayout({ children }: RootLayoutProps)
65
+ {
66
+ return <html>
67
+ <head>
68
+ <Scripts.Header />
69
+ </head>
70
+ <body>
71
+ <OptimizelyOneProvider value={{ debug: true }}>
72
+ <PageActivator />
73
+ { children }
74
+ <OptimizelyOneGadget servicePrefix='/api/me' refreshInterval={ 2000 } />
75
+ </OptimizelyOneProvider>
76
+ <Scripts.Footer />
77
+ </body>
78
+ </html>
79
+ }
80
+ ```
81
+
82
+ ### 2.3. Instrument your site with additional events
83
+ Whenever you want to track additional events, use the provided hook to get to the context and send events.
84
+
85
+ ```typescript
86
+ 'use client'
87
+ import React, { type FunctionComponent } from 'react'
88
+ import { useOptimizelyOne } from '@remkoj/optimizely-one-nextjs/client'
89
+
90
+ export const YourComponent : FunctionComponent<{}> = props => {
91
+ const opti = useOptimizelyOne()
92
+
93
+ function handler()
94
+ {
95
+ opti?.track({ event: "name", action: "action" })
96
+ }
97
+
98
+ return <button onClick={() => handler()}>Output</button>
99
+ }
100
+ ```
101
+
102
+ ### 2.4. Enable session cookie for Visitor ID
103
+ Within your middleware (`src/middleware.ts`), use the Session to make sure each visitor gets a unique Visitor ID. Either create this middleware within your project or add this logic to it.
104
+
105
+ ```typescript
106
+ import { NextResponse, type NextRequest } from "next/server"
107
+ import { Session } from '@remkoj/optimizely-one-nextjs/api'
108
+
109
+ export function middleware(request: NextRequest)
110
+ {
111
+ // Get the response
112
+ const response = NextResponse.next()
113
+
114
+ // Inject the Visitor ID cookie, with a sliding expiry
115
+ const visitorId = Session.getOrCreateVisitorId(request)
116
+ Session.addVisitorId(response, visitorId)
117
+
118
+ // Return the response
119
+ return response
120
+ }
121
+
122
+ export const config = {
123
+ matcher: [
124
+ // Skip all internal paths and paths with a '.'
125
+ '/((?!.*\\.|ui|api|assets|_next\\/static|_next\\/image|_vercel).*)',
126
+ ]
127
+ }
128
+ ```
129
+
130
+ ### 2.5. Configuration
131
+ The Optimizely One Integration is configured by setting the appropriate environment variables.
132
+
133
+ #### 2.5.1. Prevent key leakage and unauthorized access
134
+ These environment variables must ***never*** be, consider them compromised when
135
+ 1. Comitted into your source control system. Set them using the method available on your hosting environment.
136
+ 2. Configured to be exposed to the browser
137
+
138
+ Locally, you may use a `.env.local` file, which must be added to the ignore list of you source control system.
139
+
140
+ #### 2.5.2. List of supported environment variables
141
+ | Product | Environment Variable | Default Value | Purpose |
142
+ | - | - | - | - |
143
+ | *Global* | OPTIMIZELY_ONE_HELPER | 0 | Set to "1" to enable the Optimizely One Demo tools.<br/>- Allow overriding of the WebEx project ID through the 'pid' query string parameter <br/>- Enable the `<OptimizelyOneGadget />` component.
144
+ | *Global* | OPTIMIZELY_DEBUG | 0 | Set to "1" to enable debugging output. ***Note:*** This setting is shared across the different packages - it will enable debug mode for all of them |
145
+ | *Global* | OPTIMIZELY_FRONTEND_COOKIE | visitorId | The cookie used to track the current Visitor ID |
146
+ | Data Platform | OPTIMIZELY_DATAPLATFORM_ID | | The public or private key of your ODP instance, use the private key to enable fetching of visitor behaviour / profile information |
147
+ | Data Platform | OPTIMIZLEY_DATAPLATFORM_ENDPOINT | https://api.zaius.com/ | The endpoint used to read data from ODP |
148
+ | Data Platform | OPTIMIZELY_DATAPLATFORM_BATCH_SIZE | 25 | The maximum number of items to fetch in one request, if there are more results, paging will be used to get the full data set |
149
+ | Content Intelligence & Recommendations | OPTIMIZELY_CONTENTRECS_CLIENT | | The client ID for Content Intelligence & Recommendations |
150
+ | Content Intelligence & Recommendations | OPTIMIZELY_CONTENTRECS_DELIVERY | 0 | The Delivery ID setup in the main tracking script |
151
+ | Content Intelligence & Recommendations | OPTIMIZELY_CONTENTRECS_DELIVERY_KEY | | The Delivery Key used to fetch visitor topic and goal information |
152
+ | Content Intelligence & Recommendations | OPTIMIZELY_CONTENTRECS_DOMAIN | idio.co | The main domain used for the Content Recs instance, without the prefix (such as "manager", "s", "api", etc...) |
153
+ | Web Experimentation | OPTIMIZELY_WEB_EXPERIMENTATION_PROJECT | | The project identifier of the Web Experimentation Project |
154
+
155
+ ## 3. Usage
156
+ When leveraging the components and structure from the installation, everything should work immediately.
157
+
158
+ ### 3.1. Optimizely One Gadget
159
+ The OptimizelyOneGadget will only show if the following two criteria have been met, this ensures that the gadget is only available when it has intentionally ben enabled:
160
+ 1. The environment variable `OPTIMIZELY_ONE_HELPER` has been set to "1"
161
+ 2. A test-cookie has been added to the browser using the 'Add test cookie' feature of the [Optimizely Assistant Chrome Add-On](https://support.optimizely.com/hc/en-us/articles/4410289500301-Optimizely-Experimentation-Assistant-Chrome-extension)
162
+
163
+ Using the Optimizely One Gadget it is possible to demonstrate the in-session behaviour tracking and analysis performed by the configured Optimizely products.
164
+
165
+ ### 3.2. Selecting the Web Experimentation project in browser
166
+ When the `OPTIMIZELY_ONE_HELPER` is set to "1" - or the Scripts.Header component has been instructed to do so explicitly - it is possible to change the Optimizely Web Experimentation project on the fly. This is done by adding a query string parameter `?pid=`, with the new project id.
167
+
168
+ The project id is persisted in localStorage with the key `_pid` and needs to be removed manually to revert back to the configured Web Experimentation project.
package/dist/api/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import 'server-only';
2
2
  import { NextResponse } from 'next/server';
3
3
  import { cookies } from 'next/headers';
4
+ // General services
4
5
  import ProfileApiService from './profile-api-service';
5
6
  import GraphInfoApiService from './graph-info-service';
6
- import ExperimentationApiService from './experimentation-api';
7
- import ContentRecsApiService from './content-recs';
8
- import ContentRecsGoalsService from './content-goals';
7
+ // Product specific services
8
+ import ExperimentationApiService from '../products/web-experimentation/webservice';
9
+ import ContentRecsApiService from '../products/content-recs/webservice';
10
+ import ContentRecsGoalsService from '../products/content-recs/webservice-goals';
9
11
  export function createOptimizelyOneApi(config) {
10
12
  const pathParameterName = config?.pathParameterName ?? 'path';
11
13
  const services = [
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AACpB,OAAO,EAAoB,YAAY,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,iBAAiB,MAAM,uBAAuB,CAAA;AACrD,OAAO,mBAAmB,MAAM,sBAAsB,CAAA;AACtD,OAAO,yBAAyB,MAAM,uBAAuB,CAAA;AAC7D,OAAO,qBAAqB,MAAM,gBAAgB,CAAA;AAClD,OAAO,uBAAuB,MAAM,iBAAiB,CAAA;AAkBrD,MAAM,UAAU,sBAAsB,CAAC,MAAwC;IAC7E,MAAM,iBAAiB,GAAG,MAAM,EAAE,iBAAiB,IAAI,MAAM,CAAA;IAC7D,MAAM,QAAQ,GAAG;QACf,GAAG,CAAC,MAAM,EAAE,QAAQ,IAAI,EAAE,CAAC;QAC3B,iBAAiB;QACjB,mBAAmB;QACnB,yBAAyB;QACzB,qBAAqB;QACrB,uBAAuB;KACxB,CAAA;IAED,wDAAwD;IACxD,SAAS,YAAY,CAAC,IAAY,EAAE,IAAY,EAAE,UAA6B;QAC7E,OAAO,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,IAAI,CAAC,WAAW,EAAE;YACxD,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,IAAI,CAAC,WAAW,EAAE,CAAA;IACv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AAc,EAAE,WAAW,CAAC,CAAA;QAE1C,qBAAqB;QACrB,IAAI,OAAO,QAAQ,IAAI,QAAQ;YAC7B,OAAO,IAAI,YAAY,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAA;QACpE,OAAO,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAA;IACrE,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC"}
@@ -5,10 +5,31 @@ declare global {
5
5
  optimizely?: OptimizelyWebExperimentationApi;
6
6
  }
7
7
  }
8
- export interface OptimizelyOneService<T = any> {
8
+ /**
9
+ * Contract implemented by Optimizely One client services.
10
+ *
11
+ * A service can expose one or more optional capabilities (activation, tracking,
12
+ * profile updates/discovery) and provides access to an underlying browser API.
13
+ *
14
+ * @typeParam T The concrete browser API client type exposed by the service.
15
+ * @typeParam SC The service code type used to identify the service.
16
+ */
17
+ export interface OptimizelyOneService<T = any, SC = string> {
18
+ /**
19
+ * Sort order for service execution. Lower values run first.
20
+ */
9
21
  order: Readonly<number>;
22
+ /**
23
+ * Indicates whether the service is currently active.
24
+ */
10
25
  isActive: Readonly<boolean>;
11
- code: Readonly<string>;
26
+ /**
27
+ * Stable service identifier used to locate a service by code.
28
+ */
29
+ code: Readonly<SC>;
30
+ /**
31
+ * Enables or disables debug logging for this service instance.
32
+ */
12
33
  debug: boolean;
13
34
  /**
14
35
  * Perform any actions that must be done to apply the capabilities of this
@@ -27,11 +48,37 @@ export interface OptimizelyOneService<T = any> {
27
48
  * @returns void
28
49
  */
29
50
  trackPage?: (path: string) => void;
51
+ /**
52
+ * Tracks a custom event through this service.
53
+ *
54
+ * @param event The event payload.
55
+ * @returns void
56
+ */
30
57
  trackEvent?: (event: OptimizelyOneEvent) => void;
58
+ /**
59
+ * Updates profile data known to this service.
60
+ *
61
+ * @param profileData Complete new profile
62
+ * @returns void
63
+ */
31
64
  updateProfile?: (profileData: OptimizelyOneProfileData) => void;
32
- discoverProfileData?: (signal?: AbortSignal | null) => Promise<OptimizelyOneProfileData>;
65
+ /**
66
+ * Discovers profile data from this service.
67
+ *
68
+ * @param signal Optional abort signal used to cancel discovery.
69
+ * @returns A partial profile payload discovered by this service.
70
+ */
71
+ discoverProfileData?: (signal?: AbortSignal | null) => Promise<Partial<OptimizelyOneProfileData>>;
72
+ /**
73
+ * Retrieves the underlying browser API client for this service.
74
+ *
75
+ * @returns The browser API instance, or `undefined` when unavailable.
76
+ */
33
77
  getBrowserApi: () => T | undefined;
34
78
  }
79
+ export type OptimizelyOneServiceWithCapability<T = any, SC extends string = string, K extends keyof OptimizelyOneService = keyof OptimizelyOneService> = Omit<OptimizelyOneService<T, SC>, K | 'active'> & Required<Pick<OptimizelyOneService<T, SC>, K> & {
80
+ active: true;
81
+ }>;
35
82
  export type OptimizelyOneEvent = NavigationSearchEvent | {
36
83
  event: string;
37
84
  action: string;
@@ -43,9 +90,33 @@ type NavigationSearchEvent = {
43
90
  search_term: string;
44
91
  };
45
92
  export type OptimizelyOneProfileData = {
93
+ /**
94
+ * The Pseudo ID used by Optimizely Feature experimentation
95
+ */
96
+ feature_experimentation_id?: string;
97
+ /**
98
+ * The Pseudo ID used by Optimizely Content Recommendations
99
+ * and intelligence
100
+ */
46
101
  content_intelligence_id?: string;
102
+ /**
103
+ * Any other ID tracked within the profile, these IDs are
104
+ * considered PII and thus should not be sent to systems
105
+ * that may not process PII.
106
+ */
107
+ ids: Record<string, string>;
108
+ /**
109
+ * Any custom field to be tracked within the profile, the
110
+ * values here may not be PII.
111
+ */
47
112
  custom: Record<string, string | number | boolean>;
113
+ /**
114
+ * Any custom field to be tracked within the profile, the
115
+ * values here may or may not be PII
116
+ */
117
+ customPII: Record<string, string | number | boolean>;
48
118
  };
119
+ export declare const DefaultProfileData: OptimizelyOneProfileData;
49
120
  export type OptimizelyDataPlatformApi = {
50
121
  event: (name: string, data?: {
51
122
  [param: string]: any;
@@ -1,2 +1,6 @@
1
- export {};
1
+ export const DefaultProfileData = {
2
+ custom: {},
3
+ customPII: {},
4
+ ids: {}
5
+ };
2
6
  //# sourceMappingURL=client-types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client-types.js","sourceRoot":"","sources":["../src/client-types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"client-types.js","sourceRoot":"","sources":["../src/client-types.ts"],"names":[],"mappings":"AAqIA,MAAM,CAAC,MAAM,kBAAkB,GAA8B;IAC3D,MAAM,EAAE,EAAE;IACV,SAAS,EAAE,EAAE;IACb,GAAG,EAAE,EAAE;CACR,CAAA"}