Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AB#6495 Integrate Sitecore CDP with basic page view logs #115

Merged
merged 7 commits into from Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env
Expand Up @@ -87,6 +87,12 @@ DAM_SearchPage=
DAM_ExternalRedirectKey=
DAM_ExternalRedirectKey=Sitecore

# CDP
CDP_PROXY_HOST=cdp.edge.localhost
CDP_API_TARGET_ENDPOINT=
CDP_CLIENT_KEY=
CDP_API_TOKEN=

# Environment Variables for XM
XE_DELIVERY_ENDPOINT=
XE_AUTHORITY=
Expand Down
3 changes: 3 additions & 0 deletions Website/src/rendering/next-env.d.ts
@@ -1,3 +1,6 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
505 changes: 352 additions & 153 deletions Website/src/rendering/package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Website/src/rendering/package.json
Expand Up @@ -37,12 +37,12 @@
"@fortawesome/free-regular-svg-icons": "^5.15.3",
"@fortawesome/free-solid-svg-icons": "^5.15.3",
"@fortawesome/react-fontawesome": "^0.1.14",
"@next/bundle-analyzer": "^11.0.1",
"@next/bundle-analyzer": "^11.1.1",
"@sitecore-jss/sitecore-jss-nextjs": "^18.0.0-canary.1",
"@sitecore-jss/sitecore-jss-tracking": "^18.0.0-canary.1",
"graphql": "~15.4.0",
"graphql-tag": "^2.11.0",
"next": "^11.0.0",
"next": "^11.1.2",
"next-localization": "^0.10.0",
"nprogress": "~0.2.0",
"postcss-import": "^14.0.2",
Expand Down Expand Up @@ -82,7 +82,7 @@
"constant-case": "^3.0.4",
"cross-env": "~6.0.3",
"eslint": "^7.23.0",
"eslint-config-next": "^11.0.0",
"eslint-config-next": "^11.1.2",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.21.5",
Expand Down
6 changes: 6 additions & 0 deletions Website/src/rendering/src/Layout.tsx
Expand Up @@ -7,6 +7,7 @@ import {
LayoutServicePageState,
} from '@sitecore-jss/sitecore-jss-nextjs';
import { SitecoreContextValue } from 'lib/component-props'; // DEMO TEAM CUSTOMIZATION - Different type name
import { logViewEvent } from './services/BoxeverService'; // DEMO TEAM CUSTOMIZATION - CDP integration

// Prefix public assets with a public URL to enable compatibility with Sitecore Experience Editor.
// If you're not supporting the Experience Editor, you can remove this.
Expand All @@ -25,6 +26,11 @@ const Layout = ({ context }: LayoutProps): JSX.Element => {
// Note the context object type here matches the initial value in [[...path]].tsx.
useEffect(() => {
updateSitecoreContext && updateSitecoreContext(context);

// DEMO TEAM CUSTOMIZATION - Log page views in CDP
const { route } = context;
logViewEvent(route);
// END CUSTOMIZATION
}, [context, updateSitecoreContext]); // DEMO TEAM CUSTOMIZATION - Missing effect parameter to fix linting error

const { route } = context;
Expand Down
7 changes: 7 additions & 0 deletions Website/src/rendering/src/lib/util.ts
Expand Up @@ -5,3 +5,10 @@
export const getPublicUrl = (): string => {
return process.env.PUBLIC_URL || '';
};

/**
* Throws an error when the parameter is omitted.
*/
export function required(): undefined {
throw new Error('Missing parameter');
}
29 changes: 28 additions & 1 deletion Website/src/rendering/src/pages/_app.tsx
Expand Up @@ -4,13 +4,18 @@ import { useEffect } from 'react';
// END CUSTOMIZATION
import { I18nProvider } from 'next-localization';
import Head from 'next/head';
import Script from 'next/script';
import NProgress from 'nprogress';
import {
isCdpConfigured,
CDP_API_TARGET_ENDPOINT,
CDP_CLIENT_KEY,
} from 'src/services/BoxeverService';

// Using nprogress are completely optional.
// nprogress provides a loading indicator on page/route changes.
// Remove it in package.json as well if removed here.
import 'nprogress/nprogress.css';
// TODO: Import Material UI here
import 'assets/css/main.css';

NProgress.configure({ showSpinner: false, trickleSpeed: 100 });
Expand Down Expand Up @@ -41,6 +46,24 @@ function App({ Component, pageProps, router }: AppProps): JSX.Element {

const { dictionary, ...rest } = pageProps;

// DEMO TEAM CUSTOMIZATION - CDP integration
const cdpScripts = isCdpConfigured ? (
<>
<Script id="cdpSettings">{`
// Define the Boxever queue
var _boxeverq = _boxeverq || [];

// Define the Boxever settings
_boxever_settings = {
client_key: '${CDP_CLIENT_KEY}',
target: '${CDP_API_TARGET_ENDPOINT}',
cookie_domain: '.edge.localhost',
};`}</Script>
<Script src="https://d1mj578wat5n4o.cloudfront.net/boxever-1.4.8.min.js"></Script>
</>
) : undefined;
// END CUSTOMIZATION

// DEMO TEAM CUSTOMIZATION - Add head section
return (
<>
Expand All @@ -59,6 +82,10 @@ function App({ Component, pageProps, router }: AppProps): JSX.Element {
<I18nProvider lngDict={dictionary} locale={pageProps.locale}>
<Component {...rest} />
</I18nProvider>

{/* DEMO TEAM CUSTOMIZATION - CDP integration */}
{cdpScripts}
{/* END CUSTOMIZATION*/}
</>
);
// END CUSTOMIZATION
Expand Down
2 changes: 2 additions & 0 deletions Website/src/rendering/src/pages/_document.tsx
@@ -1,3 +1,5 @@
// TODO: Remove the below eslint disable when eslint-config-next is updated to support tsx files for that validation
// eslint-disable-next-line @next/next/no-document-import-in-page
import Document, { Html, Head, Main, NextScript } from 'next/document';

class MyDocument extends Document {
Expand Down