@@ -13,10 +13,17 @@ import (
13
13
)
14
14
15
15
type ConsentManagementInfo struct {
16
- AllowedConsentIDs []string `json:"allowedConsentIds"`
17
- DeniedConsentIDs []string `json:"deniedConsentIds"`
18
- Provider string `json:"provider"`
19
- ResolutionStrategy string `json:"resolutionStrategy"`
16
+ AllowedConsentIDs []string
17
+ DeniedConsentIDs []string
18
+ Provider string
19
+ ResolutionStrategy string
20
+ }
21
+
22
+ type EventConsentManagementInfo struct {
23
+ AllowedConsentIDs interface {} `json:"allowedConsentIds"`
24
+ DeniedConsentIDs []string `json:"deniedConsentIds"`
25
+ Provider string `json:"provider"`
26
+ ResolutionStrategy string `json:"resolutionStrategy"`
20
27
}
21
28
22
29
type GenericConsentManagementProviderData struct {
@@ -220,28 +227,56 @@ func getGenericConsentManagementData(dest *backendconfig.DestinationT) (ConsentP
220
227
}
221
228
222
229
func getConsentManagementInfo (event types.SingularEventT ) (ConsentManagementInfo , error ) {
230
+ consentManagementInfoFromEvent := EventConsentManagementInfo {}
223
231
consentManagementInfo := ConsentManagementInfo {}
224
232
if consentManagement , ok := misc .MapLookup (event , "context" , "consentManagement" ).(map [string ]interface {}); ok {
225
233
consentManagementObjBytes , mErr := jsonrs .Marshal (consentManagement )
226
234
if mErr != nil {
227
235
return consentManagementInfo , fmt .Errorf ("error marshalling consentManagement: %v" , mErr )
228
236
}
229
237
230
- unmErr := jsonrs .Unmarshal (consentManagementObjBytes , & consentManagementInfo )
238
+ unmErr := jsonrs .Unmarshal (consentManagementObjBytes , & consentManagementInfoFromEvent )
231
239
if unmErr != nil {
232
240
return consentManagementInfo , fmt .Errorf ("error unmarshalling consentManagementInfo: %v" , unmErr )
233
241
}
234
242
243
+ consentManagementInfo .DeniedConsentIDs = consentManagementInfoFromEvent .DeniedConsentIDs
244
+ consentManagementInfo .Provider = consentManagementInfoFromEvent .Provider
245
+ consentManagementInfo .ResolutionStrategy = consentManagementInfoFromEvent .ResolutionStrategy
246
+
247
+ // This is to support really old version of the JS SDK v3 that sent this data as an object
248
+ // for OneTrust provider.
249
+ // Handle AllowedConsentIDs based on its type (array or map)
250
+ switch val := consentManagementInfoFromEvent .AllowedConsentIDs .(type ) {
251
+ case []interface {}:
252
+ // Convert []interface{} to []string
253
+ consentManagementInfo .AllowedConsentIDs = make ([]string , 0 , len (val ))
254
+ for _ , v := range val {
255
+ if strVal , ok := v .(string ); ok {
256
+ consentManagementInfo .AllowedConsentIDs = append (consentManagementInfo .AllowedConsentIDs , strVal )
257
+ }
258
+ }
259
+ case []string :
260
+ // Already a string array
261
+ consentManagementInfo .AllowedConsentIDs = val
262
+ case map [string ]interface {}:
263
+ // Use keys from the map (legacy OneTrust format)
264
+ consentManagementInfo .AllowedConsentIDs = lo .Keys (val )
265
+ default :
266
+ consentManagementInfo .AllowedConsentIDs = []string {}
267
+ }
268
+
235
269
// Ideally, the clean up and filter is not needed for standard providers
236
270
// but useful for custom providers where users send this data directly
237
271
// to the SDKs.
238
- cleanupPredicate := func (consent string , _ int ) ( string , bool ) {
239
- return strings .TrimSpace (consent ), consent != ""
272
+ sanitizePredicate := func (consent string , _ int ) string {
273
+ return strings .TrimSpace (consent )
240
274
}
241
275
242
- consentManagementInfo .AllowedConsentIDs = lo .FilterMap (consentManagementInfo .AllowedConsentIDs , cleanupPredicate )
243
- consentManagementInfo .DeniedConsentIDs = lo .FilterMap (consentManagementInfo .DeniedConsentIDs , cleanupPredicate )
276
+ consentManagementInfo .AllowedConsentIDs = lo .Map (consentManagementInfo .AllowedConsentIDs , sanitizePredicate )
277
+ consentManagementInfo .DeniedConsentIDs = lo .Map (consentManagementInfo .DeniedConsentIDs , sanitizePredicate )
244
278
279
+ // Filter out empty values
245
280
filterPredicate := func (consent string , _ int ) (string , bool ) {
246
281
return consent , consent != ""
247
282
}
0 commit comments