From 2aef99ee223932d7e9af9d0df25ef67a99cee32b Mon Sep 17 00:00:00 2001 From: Illia Kovalenko <23364749+illiakovalenko@users.noreply.github.com> Date: Fri, 3 Mar 2023 18:32:35 +0200 Subject: [PATCH] [Nextjs][Personalize] Don't resolve site in CdpPageView when it's disabled (#1365) * [Nextjs][Personalize] Don't resolve site in CdpPageView when it's disabled * Simplify --- .../nextjs-personalize/src/components/CdpPageView.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/create-sitecore-jss/src/templates/nextjs-personalize/src/components/CdpPageView.tsx b/packages/create-sitecore-jss/src/templates/nextjs-personalize/src/components/CdpPageView.tsx index bf89a494b3..30b66012c6 100644 --- a/packages/create-sitecore-jss/src/templates/nextjs-personalize/src/components/CdpPageView.tsx +++ b/packages/create-sitecore-jss/src/templates/nextjs-personalize/src/components/CdpPageView.tsx @@ -20,9 +20,6 @@ const CdpPageView = (): JSX.Element => { sitecoreContext: { pageState, route, variantId, site }, } = useSitecoreContext(); - const siteName = site?.name || config.jssAppName; - const siteInfo = siteResolver.getByName(siteName); - /** * Creates a page view event using the Sitecore Engage SDK. */ @@ -72,10 +69,12 @@ const CdpPageView = (): JSX.Element => { if (disabled()) { return; } + + const siteInfo = siteResolver.getByName(site?.name || config.jssAppName); const language = route.itemLanguage || config.defaultLanguage; const pageVariantId = CdpHelper.getPageVariantId(route.itemId, language, variantId as string); createPageView(route.name, language, siteInfo, pageVariantId); - }, [pageState, route, variantId, siteInfo]); + }, [pageState, route, variantId, site]); return <>; };