Specifying widget context using Discover runtime JS

Note

Integration using Sitecore Discover runtime JS is deprecated.

We recommend that you use the Discover JS SDK to integrate your website or the Discover API for a website or application integration.

Context information enables Sitecore Discover to offer scalable custom widget behavior. In order for relevant products to be displayed to your users, you must ensure that context data is set correctly.

Widget context can be specified, changed, or cleared at runtime using updateContext.

There are a variety of reasons you might want to change the context at runtime. For example, if the user selects a locale, you can update the locale context to reflect that selection. Similarly, if the user selects their local store, you can update the store context. You might also want to update the context if the user selects a filter or category, or if the products displayed on the page change.

You might want to clear the context if the user logs out of their account, deselects filters or categories, and so on.

Important

Contextual information that is added at runtime does not persist from page to page. It must be added on every page where the change in context is required.

Using updateContext

To specify or clear context, use the rfk.push() function with the "updateContext" action. The basic format for this function call is as follows:

RequestResponse
rfk.push(["updateContext", <updateContext object 1>, <updateContext object 2>, ...]);

In this code sample, "updateContext" is a constant string and the updateContext object defines the widget(s) that the context applies to, the contexts to set, and the filter context to set.

Do you have some feedback for us?

If you have suggestions for improving this article,