---
title: "Web personalization"
slug: "web-personalization"
abstract: "Understand running web experiences and experiments in your web app to show personalized content to each site visitor."
---
# Web personalization

You can use the Cloud SDK [`personalize`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-personalize.html "@sitecore-cloudsdk/personalize") package to run web personalizations ([web experiences](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/en/introduction-to-web-experiences-in-sitecore-personalize.html) and [web experiments](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/en/introduction-to-web-experiments-in-sitecore-personalize.html)). These personalizations are typically created by marketers in Sitecore Personalize using [web templates](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/en/web-templates.html). This type of personalization is used to show personalized content, offers, and operational messages to site visitors.

## Enabling web personalizations

When [initializing](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/getting-started/install-and-initialize-the-cloud-sdk.html "Install and initialize the Cloud SDK") the Cloud SDK, developers can [enable web personalizations](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-concepts/concepts-personalization/set-up-web-personalization.html#UUID-9a978cf0-f941-4f45-f6dc-9cbb9f49db2b_section-idm234432972624269 "Enable web personalizations") by initializing the `browser` module of the `events` and the `personalize` packages, and then setting the `language` in `webPersonalization` to `'en'` in the `addPersonalize` method:

```typescript
CloudSDK({
  /* Your initialization settings */
})
  .addEvents()
  .addPersonalize({ enablePersonalizeCookie: true, webPersonalization: { language: 'en' } })
  .initialize();
```

> [!important]
> Web personalizations require that both the `events` and the `personalize` packages are initialized.
>
> Web personalization is only available on the browser side, not on the server side.
>
> The `language` attribute was added to the `addPersonalize` method's `webPersonalization` property in Cloud SDK 0.5.6 to support languages for web personalization.

Behind the scenes, when web personalizations run, a `<script>` tag is inserted into the HTML document. This JavaScript contains the personalized content that will be displayed to site visitors. By default, the script loads in your app [with `async` but without `defer`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script). You can change how the script loads by updating the code that enables web personalizations, such as:

```typescript
webPersonalization: { async: true, defer: true, language: string }
```

After enabling web personalizations, they automatically run once when your app first loads.

## Rerunning web personalizations

When enabled, web personalizations run once when your app first loads, but they don't automatically run again on the same page. This means that you'll need to [rerun web personalizations](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-concepts/concepts-personalization/set-up-web-personalization.html#UUID-9a978cf0-f941-4f45-f6dc-9cbb9f49db2b_section-idm1903451934913614 "Rerun web personalizations (optional)") in, for example, the following scenarios:

- You want to run web personalizations multiple times on the same page, such as when the site visitor fills out a form field or clicks a button.
- You have a [single-page application (SPA)](https://developer.mozilla.org/en-US/docs/Glossary/SPA) and you need to run personalization after a client-side route change.

You can rerun web personalizations by running `window.scCloudSDK.personalize.triggerExperiences`, either in your source code or directly inside the JavaScript of the web experience in Sitecore Personalize. Before running `triggerExperiences`, decide when you want web experiences to run again and make sure that `scCloudSDK` is available on the `window` object.

## Capturing events in personalized content

You can run functions available in the Cloud SDK [`events`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-events.html "@sitecore-cloudsdk/events") package to capture events that occur inside a web personalization. For example, when a site visitor clicks a button in a personalized pop-up. To do this, you need to [run the event-capturing functions in the JavaScript](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-concepts/concepts-personalization/set-up-web-personalization.html#UUID-9a978cf0-f941-4f45-f6dc-9cbb9f49db2b_section-idm23451934971148 "Capture events in personalized content (optional)") inside your web experience or web experiment.

> [!note]
> After enabling web personalizations in your app, web experiences and web experiments based on the [out-of-the-box **Sitecore Library** templates](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/en/create-a-variant-for-a-web-experiment-using-a-web-template.html) automatically capture events, no coding required.