@remkoj/optimizely-one-nextjs 5.1.4 → 5.1.5
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.
- package/LICENSE +12 -12
- package/README.md +163 -163
- package/dist/products/content-recs/snippet.js +16 -16
- package/dist/products/web-experimentation/snippet.js +15 -15
- package/package.json +3 -3
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,164 @@
|
|
|
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
|
-
|
|
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
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.
|
|
@@ -2,22 +2,22 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
/* eslint @next/next/no-before-interactive-script-outside-document: 0 */
|
|
3
3
|
import Script from 'next/script';
|
|
4
4
|
export const OptimizelyContentRecsTrackingScript = ({ client: client_id, delivery: delivery_id, domain = 'idio.co' }) => {
|
|
5
|
-
return _jsx(Script, { id: 'content-recs-script', strategy: 'beforeInteractive', children: `
|
|
6
|
-
// Set client and delivery
|
|
7
|
-
_iaq = [
|
|
8
|
-
['client', ${JSON.stringify(client_id)}],
|
|
9
|
-
['delivery', ${JSON.stringify(delivery_id)}]
|
|
10
|
-
];
|
|
11
|
-
|
|
12
|
-
// Include Content Analytics
|
|
13
|
-
!function(d,s){
|
|
14
|
-
var ia=d.createElement(s);
|
|
15
|
-
ia.async=1;
|
|
16
|
-
ia.id='content-recs-snippet';
|
|
17
|
-
ia.src='//s.${domain}/ia.js';
|
|
18
|
-
s=d.getElementById('content-recs-script');
|
|
19
|
-
s.parentNode.insertBefore(ia,s)
|
|
20
|
-
}(document,'script');
|
|
5
|
+
return _jsx(Script, { id: 'content-recs-script', strategy: 'beforeInteractive', children: `
|
|
6
|
+
// Set client and delivery
|
|
7
|
+
_iaq = [
|
|
8
|
+
['client', ${JSON.stringify(client_id)}],
|
|
9
|
+
['delivery', ${JSON.stringify(delivery_id)}]
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
// Include Content Analytics
|
|
13
|
+
!function(d,s){
|
|
14
|
+
var ia=d.createElement(s);
|
|
15
|
+
ia.async=1;
|
|
16
|
+
ia.id='content-recs-snippet';
|
|
17
|
+
ia.src='//s.${domain}/ia.js';
|
|
18
|
+
s=d.getElementById('content-recs-script');
|
|
19
|
+
s.parentNode.insertBefore(ia,s)
|
|
20
|
+
}(document,'script');
|
|
21
21
|
` });
|
|
22
22
|
};
|
|
23
23
|
export default OptimizelyContentRecsTrackingScript;
|
|
@@ -8,21 +8,21 @@ export const OptimizelyWebExperimentationScript = ({ projectId, allowProjectOver
|
|
|
8
8
|
`https://cdn.optimizely.com/js/${pid}.js`;
|
|
9
9
|
}
|
|
10
10
|
return _jsxs(_Fragment, { children: [_jsx(Script, { id: 'web-experimentation-startup', strategy: 'beforeInteractive', children: `window["optimizely"] = window["optimizely"] || [];` }), allowProjectOverride ?
|
|
11
|
-
_jsx(Script, { id: 'web-experimentation-project', strategy: 'beforeInteractive', children: `
|
|
12
|
-
((w,d,l) => {
|
|
13
|
-
const localProject = l.getItem('_pid');
|
|
14
|
-
const queryProject = (new URLSearchParams(w.location.search)).get('pid');
|
|
15
|
-
const currentProject = queryProject || localProject || '${projectId}';
|
|
16
|
-
if (currentProject != localProject)
|
|
17
|
-
l.setItem('_pid', currentProject)
|
|
18
|
-
|
|
19
|
-
let wx = d.createElement('script');
|
|
20
|
-
wx.fetchpriority = 'high';
|
|
21
|
-
wx.src='${buildUrl('\'+ currentProject +\'')}';
|
|
22
|
-
wx.id='web-experimentation-snippet';
|
|
23
|
-
let s=d.getElementById('web-experimentation-project');
|
|
24
|
-
s.parentNode.insertBefore(wx,s);
|
|
25
|
-
})(window,document,localStorage)
|
|
11
|
+
_jsx(Script, { id: 'web-experimentation-project', strategy: 'beforeInteractive', children: `
|
|
12
|
+
((w,d,l) => {
|
|
13
|
+
const localProject = l.getItem('_pid');
|
|
14
|
+
const queryProject = (new URLSearchParams(w.location.search)).get('pid');
|
|
15
|
+
const currentProject = queryProject || localProject || '${projectId}';
|
|
16
|
+
if (currentProject != localProject)
|
|
17
|
+
l.setItem('_pid', currentProject)
|
|
18
|
+
|
|
19
|
+
let wx = d.createElement('script');
|
|
20
|
+
wx.fetchpriority = 'high';
|
|
21
|
+
wx.src='${buildUrl('\'+ currentProject +\'')}';
|
|
22
|
+
wx.id='web-experimentation-snippet';
|
|
23
|
+
let s=d.getElementById('web-experimentation-project');
|
|
24
|
+
s.parentNode.insertBefore(wx,s);
|
|
25
|
+
})(window,document,localStorage)
|
|
26
26
|
` }) :
|
|
27
27
|
_jsx(Script, { id: 'web-experimentation-project', strategy: 'beforeInteractive', src: buildUrl(projectId) })] });
|
|
28
28
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remkoj/optimizely-one-nextjs",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "5.1.
|
|
4
|
+
"version": "5.1.5",
|
|
5
5
|
"repository": "https://github.com/remkoj/optimizely-dxp-clients.git",
|
|
6
6
|
"author": "Remko Jantzen <693172+remkoj@users.noreply.github.com>",
|
|
7
7
|
"homepage": "https://github.com/remkoj/optimizely-dxp-clients",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@headlessui/react": "^2.2.5",
|
|
43
43
|
"@headlessui/tailwindcss": "^0.2.2",
|
|
44
44
|
"@heroicons/react": "^2.2.0",
|
|
45
|
-
"@remkoj/optimizely-graph-client": "^5.1.
|
|
45
|
+
"@remkoj/optimizely-graph-client": "^5.1.5",
|
|
46
46
|
"@types/node": "^22.16.5",
|
|
47
47
|
"@types/react": "^18.3.23",
|
|
48
48
|
"@types/react-dom": "18.3.7",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"@headlessui/react": "^2",
|
|
64
64
|
"@heroicons/react": "^2",
|
|
65
|
-
"@remkoj/optimizely-graph-client": "^5.1.
|
|
65
|
+
"@remkoj/optimizely-graph-client": "^5.1.5",
|
|
66
66
|
"next": "^14",
|
|
67
67
|
"react": "^18",
|
|
68
68
|
"react-dom": "^18",
|