diff --git a/packages/create-sitecore-jss/src/templates/nextjs-personalize/.env b/packages/create-sitecore-jss/src/templates/nextjs-personalize/.env index ce5a3956cb..6ebaff0a5a 100644 --- a/packages/create-sitecore-jss/src/templates/nextjs-personalize/.env +++ b/packages/create-sitecore-jss/src/templates/nextjs-personalize/.env @@ -1,5 +1,14 @@ -BOXEVER_CLIENT_KEY= -BOXEVER_API= -BOXEVER_TARGET_URL= -BOXEVER_SCRIPT_URL= -CDP_POINTOFSALE= +# Your Sitecore CDP REST API base URL +NEXT_PUBLIC_CDP_API_URL=https://api.boxever.com + +# Your Sitecore CDP client key +NEXT_PUBLIC_CDP_CLIENT_KEY= + +# Your Sitecore CDP target URL +NEXT_PUBLIC_CDP_TARGET_URL=https://api.boxever.com/v1.2 + +# Your Sitecore CDP JavaScript library URL +NEXT_PUBLIC_CDP_SCRIPT_URL=https://d1mj578wat5n4o.cloudfront.net/boxever-1.4.8.min.js + +# Sitecore CDP point of sale +NEXT_PUBLIC_CDP_POINTOFSALE= diff --git a/packages/create-sitecore-jss/src/templates/nextjs-personalize/src/components/CdpIntegrationScript.tsx b/packages/create-sitecore-jss/src/templates/nextjs-personalize/src/components/CdpIntegrationScript.tsx index 6ecc6b5e18..c533b0f072 100644 --- a/packages/create-sitecore-jss/src/templates/nextjs-personalize/src/components/CdpIntegrationScript.tsx +++ b/packages/create-sitecore-jss/src/templates/nextjs-personalize/src/components/CdpIntegrationScript.tsx @@ -1,6 +1,7 @@ import { useSitecoreContext } from '@sitecore-jss/sitecore-jss-nextjs'; import Script from 'next/script'; import { useEffect } from 'react'; +import config from 'temp/config'; declare const _boxeverq: { (): void }[]; declare const Boxever: Boxever; @@ -21,7 +22,8 @@ interface BoxeverViewEventArgs { function createPageView(locale: string, routeName: string) { // POS must be valid in order to save events (domain name might be taken but it must be defined in CDP settings) - const pointOfSale = process.env.CDP_POINTOFSALE || window.location.host.replace(/^www\./, ''); + const pointOfSale = + process.env.NEXT_PUBLIC_CDP_POINTOFSALE || window.location.host.replace(/^www\./, ''); _boxeverq.push(function () { const pageViewEvent: BoxeverViewEventArgs = { @@ -44,7 +46,9 @@ function createPageView(locale: string, routeName: string) { } const CdpIntegrationScript = (): JSX.Element => { - const { pageEditing, route } = useSitecoreContext(); + const { + sitecoreContext: { pageEditing, route }, + } = useSitecoreContext(); useEffect(() => { // Do not create events in editing mode @@ -52,12 +56,12 @@ const CdpIntegrationScript = (): JSX.Element => { return; } - createPageView(route.itemLanguage, route.name); + route && createPageView(route.itemLanguage || config.defaultLanguage, route.name); }); // Boxever is not needed during page editing if (pageEditing) { - return null; + <>; } return ( @@ -70,14 +74,14 @@ const CdpIntegrationScript = (): JSX.Element => { var _boxeverq = _boxeverq || []; var _boxever_settings = { - client_key: '${process.env.BOXEVER_CLIENT_KEY}', - target: '${process.env.BOXEVER_TARGET_URL}', + client_key: '${process.env.NEXT_PUBLIC_CDP_CLIENT_KEY}', + target: '${process.env.NEXT_PUBLIC_CDP_TARGET_URL}', cookie_domain: '' }; `, }} /> -