@sitecore-cloudsdk/core
v0.6.1
Published
This package is for initializing the Cloud SDK and its other packages in your app.
Keywords
Readme
core
This package is for initializing the Cloud SDK and its other packages in your app.
Installation
npm install @sitecore-cloudsdk/coreTo initialize other Cloud SDK packages, first install them:
npm install @sitecore-cloudsdk/events
npm install @sitecore-cloudsdk/personalize
npm install @sitecore-cloudsdk/searchUsage
- Import the modules of all installed Cloud SDK packages that you want to initialize.
- Initialize the Cloud SDK and its packages using the
CloudSDKfunction, available in thecorepackage.
Code examples
Initialize the Cloud SDK and its packages on the browser side:
'use client';
import { useEffect } from 'react';
import { CloudSDK } from '@sitecore-cloudsdk/core/browser';
import '@sitecore-cloudsdk/events/browser';
import '@sitecore-cloudsdk/personalize/browser';
export default function Home() {
useEffect(() => {
CloudSDK({
sitecoreEdgeContextId: '<YOUR_CONTEXT_ID>',
siteName: '<YOUR_SITE_NAME>',
enableBrowserCookie: true
})
.addEvents() // Initialize the `events` package.
.addPersonalize({
enablePersonalizeCookie: true,
webPersonalization: true
}) // Initialize the `personalize` package and enable web personalization.
.addSearch() // Initialize the `search` package.
.initialize();
}, []);
return <></>;
}Initialize the Cloud SDK and its packages on the server side:
import type { NextRequest, NextResponse } from 'next/server';
import { CloudSDK } from '@sitecore-cloudsdk/core/server';
import '@sitecore-cloudsdk/events/server';
import '@sitecore-cloudsdk/personalize/server';
export async function middleware(request: NextRequest) {
const response = NextResponse.next();
await CloudSDK(request, response, {
sitecoreEdgeContextId: '<YOUR_CONTEXT_ID>',
siteName: '<YOUR_SITE_NAME>',
enableServerCookie: true
})
.addEvents() // Initialize the `events` package.
.addPersonalize({ enablePersonalizeCookie: true }) // Initialize the `personalize` package.
.addSearch() // Initialize the `search` package.
.initialize();
return response;
}