# Pass user choices in query string

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.

## Setup

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).

<figure><img src="/files/8RtVvtwXSZeb9pP2td9Q" alt="Sequence diagram showing flow of data between origin and receiver page when passing purposes and vendors from one to the other"><figcaption></figcaption></figure>

### Step 1 - Creation of the query-string parameter

On the origin page, encode the subset of consent values you need to pass in JSON format:

```javascript
window.didomiOnReady = window.didomiOnReady || [];
window.didomiOnReady.push(function (Didomi) {
  // Build the value for the query string parameter with a subset of the consent values
  const userStatusForQueryString = encodeURIComponent(
    JSON.stringify({
      purposes: {
        consent: {
          enabled: ["cookies", "select_basic_ads"],
          disabled: [],
        },
        legitimate_interest: { enabled: [], disabled: [] },
      },
      vendors: {
        consent: {
          enabled: ["google", "c:googleana-4TXnJigR"], // SDK ID
          disabled: [],
        },
        legitimate_interest: { enabled: [], disabled: [] },
      },
    }),
  );
});
```

The above code needs to run after the SDK is ready which is done by using the [`window.didomiOnReady` array](https://developers.didomi.io/cmp/web-sdk/reference/api#didomi-ready).

### Step 2 - Append the query-string parameter to the URL of the receiver page

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`.

### Step 3 - Configure the Didomi Web SDK on the receiver page

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](https://console.didomi.io/). Update the custom JSON of the consent notice embedded on the receiver page:

```json
{
  "user": {
    "externalConsent": {
      "enabled": true
    }
  }
}
```

Alternatively, you can configure this setting directly on your receiver page by assigning `window.didomiConfig`:

```js
window.didomiConfig = {
  "user": {
    "externalConsent": {
      "enabled": true
    }
  }
};
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.didomi.io/cmp/web-sdk/pass-choices-in-query-string.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
