@sitecore-cloudsdk/core

0.5.2 • Public • Published

core

This package is for initializing the Cloud SDK and its other packages in your app.

Installation

npm install @sitecore-cloudsdk/core

To initialize other Cloud SDK packages, first install them:

npm install @sitecore-cloudsdk/events
npm install @sitecore-cloudsdk/personalize
npm install @sitecore-cloudsdk/search

Usage

  1. Import the modules of all installed Cloud SDK packages that you want to initialize.
  2. Initialize the Cloud SDK and its packages using the CloudSDK function, available in the core package.

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;
}

Documentation

Official Sitecore Cloud SDK documentation

Readme

Keywords

none

Package Sidebar

Install

npm i @sitecore-cloudsdk/core

Weekly Downloads

26,324

Version

0.5.2

License

Apache-2.0

Unpacked Size

181 kB

Total Files

111

Last publish

Collaborators

  • sitecorecorporation
  • sc-maximnakhod
  • appadmin-svc