Consent

The Salesforce Interactions SDK is designed to fully respect user privacy and doesn’t store or transmit any collected data until it has been granted explicit consent. If your site has existing consent management features, you must integrate them with the SDK to signal the user’s consent status.

The SDK waits for a valid Opt In signal before beginning data collection.

Provide User Consent to the SDK 

There are two primary ways to provide or update the user’s consent status in the SDK:

  • During Initialization for first load
  • Using updateConsents() for real-time changes

The recommended approach is to provide a JavaScript Promise for the consent object within the SalesforceInteractions.init() configuration. The SDK waits for the Promise to resolve before it starts collecting data. The Promise must resolve with an array of consent data objects, as shown in this example.

1SalesforceInteractions.init({
2  consents: new Promise((resolve) => {
3    // This function will resolve the Promise when the user takes an action.
4
5    // Example: User clicks the button that grants consent
6    document.getElementById("opt-in").addEventListener(
7      "click",
8      () => {
9        resolve([
10          {
11            provider: "Test Provider",
12            purpose: SalesforceInteractions.ConsentPurpose.Tracking,
13            status: SalesforceInteractions.ConsentStatus.OptIn,
14          },
15        ]);
16      },
17      { once: true },
18    );
19
20    // Example: User clicks the button that revokes consent
21    document.getElementById("opt-out").addEventListener(
22      "click",
23      () => {
24        resolve([
25          {
26            provider: "Test Provider",
27            purpose: SalesforceInteractions.ConsentPurpose.Tracking,
28            status: SalesforceInteractions.ConsentStatus.OptOut,
29          },
30        ]);
31      },
32      { once: true },
33    );
34  }),
35});

Consent Methods 

getConsents() 

Use the getConsents() method to retrieve the current consent state. This method returns the currently stored consent statuses along with metadata about when the status was last updated and when it was last included in a transmitted event.

The syntax for this method is getConsents(): ConsentWithMetadata[].

Here’s an example of using the getConsents() method.

1const currentConsent = SalesforceInteractions.getConsents();
2// currentConsent => [{ consent: {...}, lastUpdatedTime: Date, lastSentTime: Date }]

For details on the structure of the Consent and ConsentWithMetadata objects, see Consent Data.

updateConsents() 

Use the updateConsents() method to update a user’s consent status at any time after the initial SDK configuration. For example, when a user changes their consent preferences mid-session.

The syntax for updating consent using this method is SalesforceInteractions.updateConsents(consents: Consent | Consent[]): void. The updateConsents method accepts either a single Consent object or an array of Consent objects and does not return a value.

Here’s an example of calling the updateConsents() method directly from a third-party consent management provider’s event handler.

1// Example: Calling directly from your OneTrust or custom consent management provider's code
2// When the user opts in
3SalesforceInteractions.updateConsents({
4  purpose: SalesforceInteractions.ConsentPurpose.Tracking,
5  provider: "OneTrust",
6  status: SalesforceInteractions.ConsentStatus.OptIn,
7});
8
9// When the user opts out and revokes tracking
10SalesforceInteractions.updateConsents({
11  purpose: SalesforceInteractions.ConsentPurpose.Tracking,
12  provider: "OneTrust",
13  status: SalesforceInteractions.ConsentStatus.OptOut,
14});