この文章は Salesforce 機械翻訳システムを使用して翻訳されました。詳細はこちらをご参照ください。
英語に切り替える

初期化

Salesforce Interactions SDK の推奨初期化フローは一般的なパターンに従います。
1SalesforceInteractions.init({
2  consents: [...],
3  cookieDomain: '...'
4}).then(() => {
5  SalesforceInteractions.initSitemap({
6    global: { ... },
7    pageTypeDefault: { ... },
8    pageTypes: [...]
9  })
10})

このメソッドでは、同意、ID、およびサイトマップ機能を有効にした Web SDK を初期化します。

初期化メソッド

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

引数:

項目名 説明
consents
項目の型
Consent[] Promise<Consent[]>
説明

必須。

同意データ値のリスト、または同意データ値のリストを解決する Promise。
cookieDomain
項目の型
string
説明
ID データを保存するファーストパーティ Cookie で使用するドメイン。デフォルトでは現在のサイトのドメインになります。
  • sdkConfig — consent および cookieDomain 項目を持つオブジェクト。
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
Web SDK を再初期化し、設定済みのサイトマップから適用するルールを再評価します。
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})