From 0593682500603254791b4b7fd3a711434582d60c Mon Sep 17 00:00:00 2001 From: "promptless[bot]" <179508745+promptless[bot]@users.noreply.github.com> Date: Thu, 2 Oct 2025 17:35:59 +0000 Subject: [PATCH 1/3] Documentation updates from Promptless --- .../en/experiment-javascript.md | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/content/collections/experiment-sdks/en/experiment-javascript.md b/content/collections/experiment-sdks/en/experiment-javascript.md index f2b6e29bc..cf6be667a 100644 --- a/content/collections/experiment-sdks/en/experiment-javascript.md +++ b/content/collections/experiment-sdks/en/experiment-javascript.md @@ -261,6 +261,7 @@ Configure the SDK client once during initialization. | `exposureTrackingProvider` | Implement and configure this interface to track exposure events through the experiment SDK, either automatically or explicitly. | `null` | | `instanceName` | Custom instance name for experiment SDK instance. **The value of this field is case-sensitive.** | `null` | | `initialFlags` | A JSON string representing an initial array of flag configurations to use for local evaluation. | `undefined` | +| `consentOptions` | Configure cookie consent management. Set `status` to `ConsentStatus.GRANTED`, `ConsentStatus.PENDING`, or `ConsentStatus.REJECTED`. Go to [Consent Management](#consent-management) for more details. | `{ status: ConsentStatus.GRANTED }` | | `httpClient` | (Advanced) Use your own HTTP client implementation to handle network requests made by the SDK. | Default HTTP client | {{/partial:collapse}} @@ -361,6 +362,77 @@ const experiment = Experiment.initialize("DEPLOYMENT_KEY", { {{/partial:collapse}} +## Consent Management + +The Experiment JavaScript SDK supports cookie consent management. Configure consent behavior during initialization and update it dynamically as users interact with your consent banner. + +### Consent status values + +The SDK supports three consent status values: + +- **GRANTED (1)**: User has granted consent. The SDK uses browser localStorage and sessionStorage for persistence. +- **PENDING (2)**: Waiting for user consent decision. The SDK stores data in-memory only. When consent changes to GRANTED, the SDK persists in-memory data to browser storage. +- **REJECTED (0)**: User has rejected consent. The SDK doesn't initialize and stores no data. + +### Configure consent on initialization + +Set the initial consent status when you initialize the SDK: + +```js +import { Experiment, ConsentStatus } from '@amplitude/experiment-js-client'; + +const experiment = Experiment.initialize('DEPLOYMENT_KEY', { + consentOptions: { + status: ConsentStatus.PENDING + } +}); +``` + +If you set consent status to REJECTED, the SDK doesn't initialize. + +### Update consent status + +Update the consent status after initialization when users interact with your consent banner: + +```js +import { ConsentStatus } from '@amplitude/experiment-js-client'; + +// When user grants consent +experiment.setConsentStatus(ConsentStatus.GRANTED); + +// When user rejects consent +experiment.setConsentStatus(ConsentStatus.REJECTED); +``` + +When you change consent from PENDING to GRANTED, the SDK persists any in-memory data to browser storage. When you change to REJECTED, the SDK stops storing data. + +### Example integration with consent banner + +Integration with a consent management platform: + +```js +import { Experiment, ConsentStatus } from '@amplitude/experiment-js-client'; + +// Initialize with PENDING status +const experiment = Experiment.initializeWithAmplitudeAnalytics('DEPLOYMENT_KEY', { + consentOptions: { + status: ConsentStatus.PENDING + } +}); + +// Start fetching variants +await experiment.fetch(); + +// Update when user responds to consent banner +window.addEventListener('consentGranted', () => { + experiment.setConsentStatus(ConsentStatus.GRANTED); +}); + +window.addEventListener('consentRejected', () => { + experiment.setConsentStatus(ConsentStatus.REJECTED); +}); +``` + ## Fetch Fetches variants for a [user](/docs/feature-experiment/data-model#users) and store the results in the client for fast access. This function [remote evaluates](/docs/feature-experiment/remote-evaluation) the user for flags associated with the deployment used to initialize the SDK client. From 95dae2d8b4cac23ccc62db114a7f2b5e11bfce98 Mon Sep 17 00:00:00 2001 From: "promptless[bot]" <179508745+promptless[bot]@users.noreply.github.com> Date: Thu, 2 Oct 2025 20:26:39 +0000 Subject: [PATCH 2/3] Sync documentation updates from Promptless agent --- .../experiment-sdks/en/experiment-javascript.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/content/collections/experiment-sdks/en/experiment-javascript.md b/content/collections/experiment-sdks/en/experiment-javascript.md index cf6be667a..b9abbaf84 100644 --- a/content/collections/experiment-sdks/en/experiment-javascript.md +++ b/content/collections/experiment-sdks/en/experiment-javascript.md @@ -364,15 +364,15 @@ const experiment = Experiment.initialize("DEPLOYMENT_KEY", { ## Consent Management -The Experiment JavaScript SDK supports cookie consent management. Configure consent behavior during initialization and update it dynamically as users interact with your consent banner. +The Experiment JavaScript SDK supports cookie consent management. Consent status controls data storage persistence and exposure tracking. ### Consent status values The SDK supports three consent status values: -- **GRANTED (1)**: User has granted consent. The SDK uses browser localStorage and sessionStorage for persistence. -- **PENDING (2)**: Waiting for user consent decision. The SDK stores data in-memory only. When consent changes to GRANTED, the SDK persists in-memory data to browser storage. -- **REJECTED (0)**: User has rejected consent. The SDK doesn't initialize and stores no data. +- **GRANTED (1)**: User has granted consent. Uses browser localStorage and sessionStorage for persistence and tracks exposures immediately. +- **PENDING (2)**: Waiting for user consent decision. Stores data in-memory only and queues exposures without tracking them. When consent changes to GRANTED, persists in-memory data to browser storage and fires all queued exposures. +- **REJECTED (0)**: User has rejected consent. Doesn't initialize, store data, or track exposures. If transitioning from PENDING, deletes all queued exposures. ### Configure consent on initialization @@ -404,12 +404,10 @@ experiment.setConsentStatus(ConsentStatus.GRANTED); experiment.setConsentStatus(ConsentStatus.REJECTED); ``` -When you change consent from PENDING to GRANTED, the SDK persists any in-memory data to browser storage. When you change to REJECTED, the SDK stops storing data. +When you change consent from PENDING to GRANTED, the SDK persists in-memory data to browser storage and fires all queued exposures. When you change to REJECTED, the SDK stops storing data and deletes any queued exposures. ### Example integration with consent banner -Integration with a consent management platform: - ```js import { Experiment, ConsentStatus } from '@amplitude/experiment-js-client'; From d67ab54487b2782146626d1a28c4d1d20c41fab1 Mon Sep 17 00:00:00 2001 From: "promptless[bot]" <179508745+promptless[bot]@users.noreply.github.com> Date: Fri, 10 Oct 2025 17:38:06 +0000 Subject: [PATCH 3/3] Sync documentation updates from Promptless agent --- .../experiment-sdks/en/experiment-javascript.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/content/collections/experiment-sdks/en/experiment-javascript.md b/content/collections/experiment-sdks/en/experiment-javascript.md index b9abbaf84..9412783a2 100644 --- a/content/collections/experiment-sdks/en/experiment-javascript.md +++ b/content/collections/experiment-sdks/en/experiment-javascript.md @@ -404,7 +404,13 @@ experiment.setConsentStatus(ConsentStatus.GRANTED); experiment.setConsentStatus(ConsentStatus.REJECTED); ``` -When you change consent from PENDING to GRANTED, the SDK persists in-memory data to browser storage and fires all queued exposures. When you change to REJECTED, the SDK stops storing data and deletes any queued exposures. +When you change consent from `PENDING` to `GRANTED`, the SDK persists in-memory data to browser storage and fires all queued exposures. When you change consent to `REJECTED`, the SDK stops storing data and deletes all persisted data from browser storage, including: + +- Experiment storage (`localStorage`) - user information and flag variants +- User provider storage (`localStorage` and `sessionStorage`) - device and user IDs +- Unsent events (`localStorage`) - queued exposure events + +The SDK deletes this data when you call `setConsentStatus(ConsentStatus.REJECTED)` and during initialization if consent is already rejected. ### Example integration with consent banner