-
Notifications
You must be signed in to change notification settings - Fork 0
/
onetrust.js
78 lines (64 loc) · 2.11 KB
/
onetrust.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
window.onload = function() {
window.OptanonWrapper = function() {
console.log('OptanonWrapper fired');
}
};
async function fetchDestinationForWriteKey(writeKey) {
var res = await window.fetch(
`https://cdn.segment.com/v1/projects/${writeKey}/integrations`
);
const destinations = await res.json();
for (const destination of destinations) {
destination.id = destination.creationName;
delete destination.creationName;
}
return destinations;
}
fetchDestinationForWriteKey('ReFiwPrbWdGBhNpcBOHMN5F42SxoIXT5').then((enabledIntegrations)=>{
const oneTrustGroupIds = oneTrustUtil.getConsentGroupIds();
const consentedIntegrations = getConsentedIntegrations(
enabledIntegrations,
oneTrustGroupIds
);
console.log(enabledIntegrations);
console.log(consentedIntegrations);
});
const oneTrustUtil = {
getConsentGroupIds() {
const groupIds = (window.OnetrustActiveGroups
? window.OnetrustActiveGroups.split(',')
: []
).filter(a => a);
return groupIds;
},
};
const ONE_TRUST_SEGMENT_MAPPING = {
/* Strictly Necessary Cookies */
C0001: null, // These do not map to any categories in segment.
/* Performance Cookies */
C0002: 'Analytics',
/* Functional Cookies*/
C0003: 'A/B Testing',
/* Targeting Cookies */
C0004: null, // Not mapped currently.
/* Social Media Cookies */
C0005: null, // Not mapped currently.
/* Custom Cookie Category */
C006: null, // Not mapped currently.
};
function getConsentedIntegrations(enabledIntegrations, oneTrustGroupIds) {
// Get consented segment categories.
const segmentCategories = oneTrustGroupIds
.map(oneTrustGroupId => ONE_TRUST_SEGMENT_MAPPING[oneTrustGroupId])
.filter(segmentCategory => segmentCategory); // Filter out `null` mappings.
// Filter enabled integrations by consented segment categories.
const consentedIntegrations = enabledIntegrations.filter(
enabledIntegration => {
const isConsented = segmentCategories.includes(
enabledIntegration.category
);
return isConsented;
}
);
return consentedIntegrations;
}