From dd15b6d574940a051df37d77f5e88ecd3c3ef042 Mon Sep 17 00:00:00 2001 From: yavorsk Date: Mon, 4 Nov 2024 20:49:27 +0200 Subject: [PATCH 1/6] add new property enablePersonalizeCookie to personalize middleware configuration and pass it to csdk personalize --- docs/upgrades/22.x/22.2.md | 21 +++++++++++++++++++ .../src/lib/middleware/plugins/personalize.ts | 4 +++- .../src/middleware/personalize-middleware.ts | 6 +++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/upgrades/22.x/22.2.md b/docs/upgrades/22.x/22.2.md index c135874e7c..1994a3b179 100644 --- a/docs/upgrades/22.x/22.2.md +++ b/docs/upgrades/22.x/22.2.md @@ -124,6 +124,27 @@ export default BYOCInit; ``` +* Update `src/lib/middleware/plugins/personalize.ts` to pass the new `enablePersonalizeCookie` property to PersonalizeMiddleware: + * find the initialization of PersonalizeMiddleware and add to its configuration object the 'enablePersonalizeCookie' setting, so that A/B testing and personalization are enabled: + ```ts + ... + this.personalizeMiddleware = new PersonalizeMiddleware({ + // Configuration for your Sitecore Experience Edge endpoint + edgeConfig: { + ... + }, + // Configuration for your Sitecore CDP endpoint + cdpConfig: { + ... + }, + ... + // sets the enablePersonalizeCookie setting of cloud sdk personalize; + // set to true to enable A/B testing and personalization + enablePersonalizeCookie: true, + }); + ... + ``` + * If you have any other instances of using CloudSDK in your app, follow the CloudSDK 0.4.0 upgrade guide. * Remove any other `lib/context` import, if present. If you used `context.getSDK()` method, you can now use CloudSDK method calls directly. If `context` was used to retrieve other values, consider using `temp/config` instead. \ No newline at end of file diff --git a/packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/middleware/plugins/personalize.ts b/packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/middleware/plugins/personalize.ts index 56df575774..16fe1a9898 100644 --- a/packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/middleware/plugins/personalize.ts +++ b/packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/middleware/plugins/personalize.ts @@ -21,7 +21,6 @@ class PersonalizePlugin implements MiddlewarePlugin { order = 1; constructor() { - this.personalizeMiddleware = new PersonalizeMiddleware({ // Configuration for your Sitecore Experience Edge endpoint edgeConfig: { @@ -42,6 +41,9 @@ class PersonalizePlugin implements MiddlewarePlugin { }, // Optional Sitecore Personalize scope identifier. scope: process.env.NEXT_PUBLIC_PERSONALIZE_SCOPE, + // sets the enablePersonalizeCookie setting of cloud sdk personalize; + // set to true to enable A/B testing and personalization + enablePersonalizeCookie: true, // This function determines if the middleware should be turned off. // IMPORTANT: You should implement based on your cookie consent management solution of choice. // You may wish to keep it disabled while in development mode. diff --git a/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.ts b/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.ts index 3748eb7169..b83e3a3b14 100644 --- a/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.ts +++ b/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.ts @@ -45,6 +45,10 @@ export type PersonalizeMiddlewareConfig = MiddlewareBaseConfig & { * Configuration for your Sitecore CDP endpoint */ cdpConfig: CdpServiceConfig; + /** + * Flag to set the enablePersonalizeCookie setting of cloud sdk personalize; if omitted, defaults to false + */ + enablePersonalizeCookie?: boolean; /** * Optional Sitecore Personalize scope identifier allowing you to isolate your personalization data between XM Cloud environments */ @@ -127,7 +131,7 @@ export class PersonalizeMiddleware extends MiddlewareBase { cookieDomain: hostname, enableServerCookie: true, }) - .addPersonalize() + .addPersonalize({ enablePersonalizeCookie: this.config.enablePersonalizeCookie ?? false}) .initialize(); } From 4bcf58ff92517b995465a7c025c72d7e753ecee7 Mon Sep 17 00:00:00 2001 From: yavorsk Date: Mon, 4 Nov 2024 21:00:01 +0200 Subject: [PATCH 2/6] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a8a129d1c..7cfd25a067 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,6 +98,7 @@ Our versioning strategy is as follows: * `[templates/nextjs-xmcloud]` `@sitecore/components` dependency has been updated to 2.0.0 ([#1933](https://github.com/Sitecore/jss/pull/1933)) * `[templates/nextjs-xmcloud]` `lib/context` import has been removed. Values from `temp/config` can be used instead. ([#1933](https://github.com/Sitecore/jss/pull/1933)) * `[sitecore-jss-nextjs]` `Context` import and `@sitecore-jss/sitecore-jss-nextjs/context` submodule have been removed. ([#1933](https://github.com/Sitecore/jss/pull/1933)) +* `[sitecore-jss-nextjs]``[templates/nextjs-xmcloud]` add new property `enablePersonalizeCookie` to PersonalizeMiddlewareConfig and pass it to CloudSDK.addPersonalize() function; update personalize plugin to set it to true by default ([#1963](https://github.com/Sitecore/jss/pull/1963)) ## 22.1.4 From 7bc126477c1d226a14618b32045b4f0863eddaea Mon Sep 17 00:00:00 2001 From: yavorsk Date: Mon, 4 Nov 2024 21:08:52 +0200 Subject: [PATCH 3/6] fix lint error --- .../src/middleware/personalize-middleware.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.ts b/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.ts index b83e3a3b14..43eec6f952 100644 --- a/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.ts +++ b/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.ts @@ -131,7 +131,7 @@ export class PersonalizeMiddleware extends MiddlewareBase { cookieDomain: hostname, enableServerCookie: true, }) - .addPersonalize({ enablePersonalizeCookie: this.config.enablePersonalizeCookie ?? false}) + .addPersonalize({ enablePersonalizeCookie: this.config.enablePersonalizeCookie ?? false }) .initialize(); } From ccf8416b9550e17122015bb99da716055ce3e54b Mon Sep 17 00:00:00 2001 From: yavorsk Date: Mon, 4 Nov 2024 21:22:52 +0200 Subject: [PATCH 4/6] update enablePersonalizeCookie to default to true --- .../nextjs-xmcloud/src/lib/middleware/plugins/personalize.ts | 2 +- .../src/middleware/personalize-middleware.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/middleware/plugins/personalize.ts b/packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/middleware/plugins/personalize.ts index 16fe1a9898..b49cbc9631 100644 --- a/packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/middleware/plugins/personalize.ts +++ b/packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/middleware/plugins/personalize.ts @@ -41,7 +41,7 @@ class PersonalizePlugin implements MiddlewarePlugin { }, // Optional Sitecore Personalize scope identifier. scope: process.env.NEXT_PUBLIC_PERSONALIZE_SCOPE, - // sets the enablePersonalizeCookie setting of cloud sdk personalize; + // sets the enablePersonalizeCookie setting of cloud sdk personalize, which in turn sets the personalize cookie; // set to true to enable A/B testing and personalization enablePersonalizeCookie: true, // This function determines if the middleware should be turned off. diff --git a/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.ts b/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.ts index 43eec6f952..c09ee1c323 100644 --- a/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.ts +++ b/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.ts @@ -46,7 +46,7 @@ export type PersonalizeMiddlewareConfig = MiddlewareBaseConfig & { */ cdpConfig: CdpServiceConfig; /** - * Flag to set the enablePersonalizeCookie setting of cloud sdk personalize; if omitted, defaults to false + * Flag to set the enablePersonalizeCookie setting of cloud sdk personalize; if omitted, defaults to true */ enablePersonalizeCookie?: boolean; /** @@ -131,7 +131,7 @@ export class PersonalizeMiddleware extends MiddlewareBase { cookieDomain: hostname, enableServerCookie: true, }) - .addPersonalize({ enablePersonalizeCookie: this.config.enablePersonalizeCookie ?? false }) + .addPersonalize({ enablePersonalizeCookie: this.config.enablePersonalizeCookie ?? true }) .initialize(); } From 0ca95a048e04adae8031a4623608f3583a3d5c2e Mon Sep 17 00:00:00 2001 From: yavorsk Date: Mon, 4 Nov 2024 21:24:11 +0200 Subject: [PATCH 5/6] update ugrade entry --- docs/upgrades/22.x/22.2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/upgrades/22.x/22.2.md b/docs/upgrades/22.x/22.2.md index 1994a3b179..fd6ba0991b 100644 --- a/docs/upgrades/22.x/22.2.md +++ b/docs/upgrades/22.x/22.2.md @@ -138,7 +138,7 @@ ... }, ... - // sets the enablePersonalizeCookie setting of cloud sdk personalize; + // sets the enablePersonalizeCookie setting of cloud sdk personalize, which in turn sets the personalize cookie; // set to true to enable A/B testing and personalization enablePersonalizeCookie: true, }); From fdfe8eb92363299c0f2d4eca112914d1344b91f9 Mon Sep 17 00:00:00 2001 From: yavorsk Date: Mon, 4 Nov 2024 21:57:02 +0200 Subject: [PATCH 6/6] pass setPersonalizeCookie by default in personalize-middleware --- CHANGELOG.md | 2 +- docs/upgrades/22.x/22.2.md | 21 ------------------- .../src/lib/middleware/plugins/personalize.ts | 3 --- .../src/middleware/personalize-middleware.ts | 6 +----- 4 files changed, 2 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cfd25a067..6c3f323c1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,7 +98,7 @@ Our versioning strategy is as follows: * `[templates/nextjs-xmcloud]` `@sitecore/components` dependency has been updated to 2.0.0 ([#1933](https://github.com/Sitecore/jss/pull/1933)) * `[templates/nextjs-xmcloud]` `lib/context` import has been removed. Values from `temp/config` can be used instead. ([#1933](https://github.com/Sitecore/jss/pull/1933)) * `[sitecore-jss-nextjs]` `Context` import and `@sitecore-jss/sitecore-jss-nextjs/context` submodule have been removed. ([#1933](https://github.com/Sitecore/jss/pull/1933)) -* `[sitecore-jss-nextjs]``[templates/nextjs-xmcloud]` add new property `enablePersonalizeCookie` to PersonalizeMiddlewareConfig and pass it to CloudSDK.addPersonalize() function; update personalize plugin to set it to true by default ([#1963](https://github.com/Sitecore/jss/pull/1963)) +* `[sitecore-jss-nextjs]` update personalize-middleware for CloudSDK 0.4.0 - pass `enablePersonalizeCookie` to CloudSDK.addPersonalize() function ([#1963](https://github.com/Sitecore/jss/pull/1963)) ## 22.1.4 diff --git a/docs/upgrades/22.x/22.2.md b/docs/upgrades/22.x/22.2.md index fd6ba0991b..c135874e7c 100644 --- a/docs/upgrades/22.x/22.2.md +++ b/docs/upgrades/22.x/22.2.md @@ -124,27 +124,6 @@ export default BYOCInit; ``` -* Update `src/lib/middleware/plugins/personalize.ts` to pass the new `enablePersonalizeCookie` property to PersonalizeMiddleware: - * find the initialization of PersonalizeMiddleware and add to its configuration object the 'enablePersonalizeCookie' setting, so that A/B testing and personalization are enabled: - ```ts - ... - this.personalizeMiddleware = new PersonalizeMiddleware({ - // Configuration for your Sitecore Experience Edge endpoint - edgeConfig: { - ... - }, - // Configuration for your Sitecore CDP endpoint - cdpConfig: { - ... - }, - ... - // sets the enablePersonalizeCookie setting of cloud sdk personalize, which in turn sets the personalize cookie; - // set to true to enable A/B testing and personalization - enablePersonalizeCookie: true, - }); - ... - ``` - * If you have any other instances of using CloudSDK in your app, follow the CloudSDK 0.4.0 upgrade guide. * Remove any other `lib/context` import, if present. If you used `context.getSDK()` method, you can now use CloudSDK method calls directly. If `context` was used to retrieve other values, consider using `temp/config` instead. \ No newline at end of file diff --git a/packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/middleware/plugins/personalize.ts b/packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/middleware/plugins/personalize.ts index b49cbc9631..b41aafefa5 100644 --- a/packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/middleware/plugins/personalize.ts +++ b/packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/middleware/plugins/personalize.ts @@ -41,9 +41,6 @@ class PersonalizePlugin implements MiddlewarePlugin { }, // Optional Sitecore Personalize scope identifier. scope: process.env.NEXT_PUBLIC_PERSONALIZE_SCOPE, - // sets the enablePersonalizeCookie setting of cloud sdk personalize, which in turn sets the personalize cookie; - // set to true to enable A/B testing and personalization - enablePersonalizeCookie: true, // This function determines if the middleware should be turned off. // IMPORTANT: You should implement based on your cookie consent management solution of choice. // You may wish to keep it disabled while in development mode. diff --git a/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.ts b/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.ts index c09ee1c323..28927daf9c 100644 --- a/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.ts +++ b/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.ts @@ -45,10 +45,6 @@ export type PersonalizeMiddlewareConfig = MiddlewareBaseConfig & { * Configuration for your Sitecore CDP endpoint */ cdpConfig: CdpServiceConfig; - /** - * Flag to set the enablePersonalizeCookie setting of cloud sdk personalize; if omitted, defaults to true - */ - enablePersonalizeCookie?: boolean; /** * Optional Sitecore Personalize scope identifier allowing you to isolate your personalization data between XM Cloud environments */ @@ -131,7 +127,7 @@ export class PersonalizeMiddleware extends MiddlewareBase { cookieDomain: hostname, enableServerCookie: true, }) - .addPersonalize({ enablePersonalizeCookie: this.config.enablePersonalizeCookie ?? true }) + .addPersonalize({ enablePersonalizeCookie: true }) .initialize(); }