初期化
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>引数:
- sdkConfig - consent および cookieDomain 項目を持つオブジェクト。
| 項目名 | 項目の型 | 説明 |
|---|---|---|
| consents | Consent[] Promise<Consent[]> | 必須。同意データ値のリスト、または同意データ値のリストを解決する Promise。 |
| cookieDomain | string | ID データを保存するファーストパーティ Cookie で使用するドメイン。デフォルトでは現在のサイトのドメインになります。 |
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(): void1SalesforceInteractions.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})