11import { SDKEventCustomFlags } from './sdkRuntimeModels' ;
2+ import Constants from './constants' ;
23import { IntegrationAttributes } from './store' ;
34import {
45 Dictionary ,
@@ -73,7 +74,7 @@ interface IntegrationIdMapping {
7374 [ key : string ] : IntegrationMappingItem ;
7475}
7576
76- const integrationMapping : IntegrationIdMapping = {
77+ const integrationMappingExternal : IntegrationIdMapping = {
7778 // Facebook / Meta
7879 fbclid : {
7980 mappedKey : 'Facebook.ClickId' ,
@@ -103,6 +104,25 @@ const integrationMapping: IntegrationIdMapping = {
103104 output : IntegrationOutputs . CUSTOM_FLAGS ,
104105 } ,
105106
107+ // TIKTOK
108+ ttclid : {
109+ mappedKey : 'TikTok.Callback' ,
110+ output : IntegrationOutputs . CUSTOM_FLAGS ,
111+ } ,
112+ _ttp : {
113+ mappedKey : 'tiktok_cookie_id' ,
114+ output : IntegrationOutputs . PARTNER_IDENTITIES ,
115+ } ,
116+
117+ // Snapchat
118+ // https://businesshelp.snapchat.com/s/article/troubleshooting-click-id?language=en_US
119+ ScCid : {
120+ mappedKey : 'SnapchatConversions.ClickId' ,
121+ output : IntegrationOutputs . CUSTOM_FLAGS ,
122+ } ,
123+ } ;
124+
125+ const integrationMappingRokt : IntegrationIdMapping = {
106126 // Rokt
107127 // https://docs.rokt.com/developers/integration-guides/web/advanced/rokt-id-tag/
108128 // https://go.mparticle.com/work/SQDSDKS-7167
@@ -121,23 +141,6 @@ const integrationMapping: IntegrationIdMapping = {
121141 output : IntegrationOutputs . INTEGRATION_ATTRIBUTES ,
122142 moduleId : 1277 ,
123143 } ,
124-
125- // TIKTOK
126- ttclid : {
127- mappedKey : 'TikTok.Callback' ,
128- output : IntegrationOutputs . CUSTOM_FLAGS ,
129- } ,
130- _ttp : {
131- mappedKey : 'tiktok_cookie_id' ,
132- output : IntegrationOutputs . PARTNER_IDENTITIES ,
133- } ,
134-
135- // Snapchat
136- // https://businesshelp.snapchat.com/s/article/troubleshooting-click-id?language=en_US
137- ScCid : {
138- mappedKey : 'SnapchatConversions.ClickId' ,
139- output : IntegrationOutputs . CUSTOM_FLAGS ,
140- } ,
141144} ;
142145
143146export default class IntegrationCapture {
@@ -146,9 +149,11 @@ export default class IntegrationCapture {
146149 public readonly filteredPartnerIdentityMappings : IntegrationIdMapping ;
147150 public readonly filteredCustomFlagMappings : IntegrationIdMapping ;
148151 public readonly filteredIntegrationAttributeMappings : IntegrationIdMapping ;
152+ public captureMode ?: valueof < typeof Constants . CaptureIntegrationSpecificIdsV2Modes > ;
149153
150- constructor ( ) {
154+ constructor ( captureMode : valueof < typeof Constants . CaptureIntegrationSpecificIdsV2Modes > ) {
151155 this . initialTimestamp = Date . now ( ) ;
156+ this . captureMode = captureMode ;
152157
153158 // Cache filtered mappings for faster access
154159 this . filteredPartnerIdentityMappings = this . filterMappings ( IntegrationOutputs . PARTNER_IDENTITIES ) ;
@@ -205,7 +210,8 @@ export default class IntegrationCapture {
205210 * Captures cookies based on the integration ID mapping.
206211 */
207212 public captureCookies ( ) : Dictionary < string > {
208- const cookies = getCookies ( Object . keys ( integrationMapping ) ) ;
213+ const integrationKeys = this . getAllowedKeysForMode ( ) ;
214+ const cookies = getCookies ( integrationKeys ) ;
209215 return this . applyProcessors ( cookies , getHref ( ) , this . initialTimestamp ) ;
210216 }
211217
@@ -221,8 +227,9 @@ export default class IntegrationCapture {
221227 * Captures local storage based on the integration ID mapping.
222228 */
223229 public captureLocalStorage ( ) : Dictionary < string > {
230+ const integrationKeys = this . getAllowedKeysForMode ( ) ;
224231 let localStorageItems : Dictionary < string > = { } ;
225- for ( const key in integrationMapping ) {
232+ for ( const key of integrationKeys ) {
226233 const localStorageItem = localStorage . getItem ( key ) ;
227234 if ( localStorageItem ) {
228235 localStorageItems [ key ] = localStorageItem ;
@@ -237,7 +244,8 @@ export default class IntegrationCapture {
237244 * @returns {Dictionary<string> } The query parameters.
238245 */
239246 public getQueryParams ( ) : Dictionary < string > {
240- return queryStringParser ( getHref ( ) , Object . keys ( integrationMapping ) ) ;
247+ const integrationKeys = this . getAllowedKeysForMode ( ) ;
248+ return queryStringParser ( getHref ( ) , integrationKeys ) ;
241249 }
242250
243251 /**
@@ -316,27 +324,52 @@ export default class IntegrationCapture {
316324 timestamp ?: number
317325 ) : Dictionary < string > {
318326 const processedClickIds : Dictionary < string > = { } ;
319-
327+ const integrationKeys = this . getActiveIntegrationMapping ( ) ;
328+
320329 for ( const key in clickIds ) {
321330 if ( clickIds . hasOwnProperty ( key ) ) {
322331 const value = clickIds [ key ] ;
323- const processor = integrationMapping [ key ] ?. processor ;
332+ const processor = integrationKeys [ key ] ?. processor ;
324333 processedClickIds [ key ] = processor ? processor ( value , url , timestamp ) : value ;
325334 }
326335 }
327-
328336 return processedClickIds ;
329337 }
330338
331339 private filterMappings (
332340 outputType : valueof < typeof IntegrationOutputs >
333341 ) : IntegrationIdMapping {
334342 const filteredMappings : IntegrationIdMapping = { } ;
335- for ( const key in integrationMapping ) {
336- if ( integrationMapping [ key ] . output === outputType ) {
337- filteredMappings [ key ] = integrationMapping [ key ] ;
343+ const integrationKeys = this . getActiveIntegrationMapping ( ) ;
344+ for ( const key in integrationKeys ) {
345+ if ( integrationKeys [ key ] . output === outputType ) {
346+ filteredMappings [ key ] = integrationKeys [ key ] ;
338347 }
339348 }
340349 return filteredMappings ;
341350 }
351+
352+ /**
353+ * Returns the allowed keys to capture based on the current mode.
354+ * For RoktOnly, limit capture to Rokt keys; for All, capture all mapped keys.
355+ */
356+ private getAllowedKeysForMode ( ) : string [ ] {
357+ return Object . keys ( this . getActiveIntegrationMapping ( ) ) ;
358+ }
359+
360+ /**
361+ * Selects the active integration mapping for the current captureMode.
362+ * - 'roktonly': only Rokt IDs are considered
363+ * - 'all': both External and Rokt IDs are considered
364+ * - else: returns an empty mapping and nothing will be captured
365+ */
366+ private getActiveIntegrationMapping ( ) : IntegrationIdMapping {
367+ if ( this . captureMode === Constants . CaptureIntegrationSpecificIdsV2Modes . RoktOnly ) {
368+ return integrationMappingRokt ;
369+ }
370+ if ( this . captureMode === Constants . CaptureIntegrationSpecificIdsV2Modes . All ) {
371+ return { ...integrationMappingExternal , ...integrationMappingRokt } ;
372+ }
373+ return { } ;
374+ }
342375}
0 commit comments