Clear widget context using runtime JS
To clear contextual information from a widget:
-
Add a
scriptblock in theheadtag above the Discover beacon.RequestResponse<script type="module"> // Widget context code goes here </script> -
Create an
updateContextobject and set the context you want to clear tonull. In the following code sample, thestore.idcontext is cleared.RequestResponseconst clearContext = { "widget": { "rfkids": [ "<rfkid 1>", "<rfkid 2>", ... ] }, "context": { "store": { "id": null } } }TipIf there are no other keys in
store, you can set the value ofstoretonull. In addition, if there are no other keys incontext, you can set the value ofcontexttonull. -
Push the
"updateContext"action and object(s) to Discover usingrfk.push().RequestResponsevar rfk = window.rfk = window.rfk || []; rfk.push(["updateContext", clearContext]);
If an object within context only contains null values, that object is removed from context.
For specific examples of how to use the updateContext action to clear context, refer to Examples: Clearing page and widget context.