Use JavaScript in a web experiment

Abstract

How to insert dynamic data when using JavaScript in a web experiment (Sitecore Personalize).

Inserting dynamic data into JavaScript is often used to facilitate 1:1 personalization. On the Data tab, you can copy an attribute or path and paste it into the JavaScript editor.

To use JavaScript in a web experiment:

  1. On the Build screen, on the Personalization tile, click Add. The Create Variant sliding modal displays.

  2. Click the Add custom code link.

  3. In the template editor, on the JavaScript tab, enter any JavaScript that you want to use in the web experiment.

  4. To insert dynamic data into HTML, in the Data Selector search box, enter a guest's email address to search. This enables you to access data model attributes and paths.

    Tip

    If there is a guest whose data you often use when configuring or testing code, click the star icon to bookmark the guest so you no longer have to search for them.

  5. To include dynamic data from the decision model response, expand the Decision Model Response tree and click copy, Copy Path as Handlebars.

  6. To include dynamic data from the experiment response, expand the Experience Response tree and click copy, Copy Path as Handlebars.

  7. On the JavaScript tab, paste the data and click Save.

  8. Click Close. You return to the Build screen.

    You must also include the dynamic data when you compose the API response. This ensures that when the experiment executes, the server requests the dynamic data and passes it to the variant.