window.Engage.triggerExperiences()
The triggerExperiences()
function reruns every web experience and web experiment that's live in Sitecore Personalize. This function is particularly useful if you want to run personalization, for example:
-
In a multi-page application, on the same page in response to user input.
-
In a single-page application (SPA), when the user navigates between routes.
You can only use this function if you previously set the webPersonalization
attribute to true
in the settings object in the Engage.init()
function, on the client side of your app.
Here's an example of how to use the triggerExperiences()
function to make sure that web experiences and web experiments always run on the /contact
route of a SPA app.
import { init } from "@sitecore/engage";
let engage;
const loadEngage = async () => {
engage = await init({
// ...
webPersonalization: true
});
// Make sure web experiences and web experiments always run in SPA apps:
if (window.location.pathname.includes("/contact")) {
window.Engage.triggerExperiences();
}
};