Initialization

The recommended initialization flow for the Salesforce Interactions SDK follows a general pattern.
1SalesforceInteractions.init({
2  consents: [...],
3  cookieDomain: '...'
4}).then(() => {
5  SalesforceInteractions.initSitemap({
6    global: { ... },
7    pageTypeDefault: { ... },
8    pageTypes: [...]
9  })
10})

This method initializes the Web SDK with Consent, Identity, and Sitemap features enabled.

Initialization Methods

1init(sdkConfig: SdkConfig): Promise<void>

Arguments:

Field Name Description
consents
Field Type
Consent[] Promise<Consent[]>
Description

Required.

A list of consent data values or a promise that resolves a list of consent data values.
cookieDomain
Field Type
string
Description
The domain to use for the first-party cookies that stores identity data. Defaults to the domain of the current site.
  • sdkConfig — An object with consent and cookieDomain fields.
1// initialize with consent provided by a user interaction
2SalesforceInteractions.init({
3  cookieDomain: 'domain.com',
4  consents: new Promise(resolve => {
5    // user clicks button that grants consent
6    document.getElementById('opt-in')
7      .addEventListener('click', () => {
8        resolve([{ 
9          provider: 'Test Provider', 
10          purpose: 'Tracking', 
11          status: SalesforceInteractions.ConsentStatus.OptIn 
12        }])
13      }, { once: true })
14
15    // user clicks button that revokes consent
16    document.getElementById('opt-out')
17      .addEventListener('click', () => {
18        resolve([{ 
19          provider: 'Test Provider', 
20          purpose: 'Tracking', 
21          status: SalesforceInteractions.ConsentStatus.OptOut 
22        }])
23      }, { once: true })
24  })
25})
26
27// initialize with consent preconfigured
28SalesforceInteractions.init({
29  cookieDomain: 'domain.com',
30  consents: [{ 
31    provider: 'Test Provider', 
32    purpose: 'Tracking', 
33    status: SalesforceInteractions.ConsentStatus.OptIn 
34  }]
35})
36
37// initialize with no consent
38SalesforceInteractions.init({
39  cookieDomain: 'domain.com',
40  consents: []
41})
1reinit(): void
Reinitializes the Web SDK and reevaluates which rules to apply from the configured sitemap.
1SalesforceInteractions.init({...}).then(() => {
2  let href = window.location.href
3  
4  // monitor the url for changes and reinitialize when detected
5   setInterval(() => {
6    if (href !== window.location.href) {
7      href = window.location.href
8       SalesforceInteractions.reinit()
9     }
10   }, 200)
11
12  SalesforceInteractions.initSitemap({...})
13})