Set Up Dynamic Context Variables

Use dynamic context variables to send user-defined attributes to the Personalization service with every personalization request. These attributes help refine recommendation responses and enable advanced filtering logic in your recommenders. By using dynamic variables, you can reduce the number of recommenders needed to deliver your use cases. You can define context variables in the Interactions SDK sitemap globally or for specific page types.

A dynamic context variable contains two fields: a name and a value.

Field NameTypeRequiredDescription
nameStringYesThe name of the contextual attribute. For example, color.
valueString, Function, or PromiseYesThe value of the contextual attribute. This can be a static string, a function that returns a string, or a promise that resolves to a string. For example, if the name is color, the value could be blue.

You can define dynamic context variables in the Interactions SDK sitemap globally using the global configuration. Alternatively, you can define them for specific page types using the pageTypes configuration.

The Interactions SDK automatically sends a set of standard contextual attributes with every personalization request. You can override some of these attributes in your sitemap configuration, but if the SDK has a valid value for an attribute, it overwrites your custom value. Before overriding a reserved attribute, verify that your custom value takes precedence in your implementation and that it doesn’t interfere with expected personalization results.

AttributeDescriptionValue override allowed?Channel
dataspaceThe dataspace for the personalization request.NoWeb, Mobile
anchorIdThe identifier of the anchor item (for example, a product or content item) on the current page.YesWeb, Mobile
anchorTypeThe Data Model Object name associated with the anchor item.YesWeb, Mobile
individualIdUnique identifier of the website visitor, generated by the SDK. This typically corresponds to a device ID.NoWeb
channelThe channel from which the request originates, determined by the SDK in use. The SDK sends a fixed value of ‘Web’ or ‘Mobile’. For example, Web, Mobile, Flow, Email, SMS, WhatsApp, POS, ATM, Service Cloud, Sales Cloud, Agent, Server, OTT.NoWeb, Mobile
channelContextThe hostname for web, or the mobile app identifier for mobile. For example, salesforce.com.NoWeb, Mobile
localeThe locale used to filter and rank recommendations for multi-locale deployments. This value is not set automatically by the SDK. For example, en_US.YesWeb, Mobile
requestUrlThe URL from which the personalization request was made. For example, https://commercecloud.salesforce.com/s/nto/default/home.NoWeb
pageTypeThe page type from the sitemap where the personalization request originated. For example, Product.YesWeb
interactionThe interaction name from the page type where the personalization request originated.YesWeb
p13n_sys_requestTimeZoneThe browser’s time zone. For example, Europe/Vienna.NoWeb
utm_sourceUTM source parameter captured from the page URL.NoWeb
utm_campaignUTM campaign parameter captured from the page URL.NoWeb
utm_mediumUTM medium parameter captured from the page URL.NoWeb
utm_contentUTM content parameter captured from the page URL.NoWeb
utm_termUTM term parameter captured from the page URL.NoWeb

For more information on how to use these contextual attributes for advanced filtering, see Filter Recommendations Using Dynamic Context Variables.