Pass user choices in query string
Last updated
Last updated
It's possible to pass user choices through query-string parameters, allowing the sharing of information across different pages or domains.
Here's a high-level overview of how this is done:
Generate a JSON-encoded format of the user choices.
Append the URL-encoded JSON user choices to a link on the page.
Configure the Didomi Web SDK to retrieve the user choices from the URL.
When passing user choices from one page to another in a query string, the purposes and vendors configured for the receiving page must be a subset of the purposes and vendors configured for the origin page that is collecting user choices. This will ensure that the receiver page gets all the user choices it requires and it will not need to re-collect user choices and show a consent notice again.
This section will guide you on how to set up an origin page (where users' choices are collected) and a receiver page (where these choices are read from the query-string parameters).
On the origin page, fetch the current user's choices from the Didomi Web SDK and encode them into JSON format:
The above code needs to run after the SDK is ready which is done by using the window.didomiOnReady
array.
If the receiver page does not require user choices for all the vendors from the origin page, you can filter the choices based on the vendor IDs:
This will reduce the amount of information passed in the query string.
Append the userStatusForQueryString
variable created in step 1 to the receiver page's URL in a query-string parameter named didomiConfig.user.externalConsent.value
.
For instance, if your receiver page URL is https://receiver.com/page.html
, the updated URL should appear like https://receiver.com/page.html?didomiConfig.user.externalConsent.value=%7B...%7D
.
For the Web SDK to read user choices from the query string, it must be appropriately configured since this behavior is disabled by default.
One way to do this is via the Didomi Console. Update the custom JSON of the consent notice embedded on the receiver page:
Alternatively, you can configure this setting directly on your receiver page by assigning window.didomiConfig
: