1. Getting started

Install and initialize the Cloud SDK

Version:

Before you can start using the Cloud SDK, you have to install and initialize all the SDK packages you want to use, and then import their modules. For more information, see Initializing the Cloud SDK.

In this topic, you install and initialize all SDK packages on the browser side in a JSS Next.js app (JSS version 22.7).

JSS Next.js apps already initialize the Cloud SDK core and events packages on the browser side, in Bootstrap.tsx, with no coding required. If you don't want to use other SDK packages in your app, you don't need to complete this walkthrough.

Only complete this walkthrough if you want to use other SDK packages on the browser side, such as the personalize package.

Before you begin
  • Make sure you're ready to start development with the Cloud SDK.

  • In production, only initialize the Cloud SDK and set cookies if your site visitor grants consent. See also a code example to check if your site visitor accepts cookies.

To install and initialize the Cloud SDK on the browser side:

  1. In your code editor, open your JSS Next.js app folder. This is the folder where you added environment variables when you set up your local development environment.

  2. Open package.json and check that the following SDK packages are installed in your project:

    • @sitecore-cloudsdk/core
    • @sitecore-cloudsdk/events
  3. Open the terminal and install any other SDK packages you want to use by running the following command:

    npm install @sitecore-cloudsdk/personalize
    npm install @sitecore-cloudsdk/search
  4. Open Bootstrap.tsx. This component already initializes the Cloud SDK and the events package. You'll update the component code in the next step to initialize other SDK packages, such as personalize.

  5. At the top of the file, directly below the CloudSDK import statement, import the browser module of the packages you installed in a previous step:

    // ...
    import "@sitecore-cloudsdk/personalize/browser";
    import "@sitecore-cloudsdk/search/browser";
  6. In the Effect Hook, in the CloudSDK function, directly before the initialize method, paste the following code, then save your changes:

    // ...
    .addPersonalize({ enablePersonalizeCookie: true, webPersonalization: { language: 'en' } })
    .addSearch()
    // ...

    This code initializes the personalize and the search packages and enables the cookie required for personalization. It also enables Sitecore Personalize web personalizations. If you don't want to enable web personalizations, set webPersonalization: false.

    Note

    The language parameter was added to the addPersonalize method's webPersonalization property in Cloud SDK 0.5.6 to support languages for web personalization.

  7. In your terminal, enter npm run start:production to start your JSS Next.js app.

  8. In your web browser, navigate to your JSS Next.js app, typically at http://localhost:3000.

  9. In your web browser console, enter window.scCloudSDK. If an object returns, you have successfully initialized the SDK.

    Tip

    This object lists all the packages you have initialized and their version. Use this in any future implementations to quickly verify that the SDK is correctly initialized.

  10. Optionally, in your web browser's developer tools, in Cookies, find at least one cookie that starts with sc_. This is another way to verify that you've successfully initialized the Cloud SDK.

    You can now run other browser-side SDK code in the rest of your app.

:::

You've now successfully installed and initialized the Cloud SDK. You are now ready to set up the following Cloud SDK capabilities to ensure that your web app uses the full potential of Sitecore DXP products:

We also recommend that you:

If you have suggestions for improving this article, let us know!