-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #408 from rudderlabs/production-staging
production-staging -> production
- Loading branch information
Showing
11 changed files
with
435 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { OneTrust } from "./OneTrust"; | ||
|
||
class CookieConsentFactory { | ||
static initialize(sourceConfig, cookieConsentOptions) { | ||
/** | ||
* | ||
* check which type of cookie consent manager needs to be called if enabled | ||
* for now we have only OneTrust. | ||
* But if new cookie consent manager options are implemented, | ||
* we need to make sure only one of them is enabled by the user in the | ||
* load options | ||
* | ||
*/ | ||
|
||
if (cookieConsentOptions?.oneTrust?.enabled) { | ||
// This is P1. When we have an ui in source side to turn on/off of cookie consent | ||
// if (sourceConfig && | ||
// sourceConfig.cookieConsentManager && | ||
// sourceConfig.cookieConsentManager.oneTrust && | ||
// sourceConfig.cookieConsentManager.oneTrustenabled) { | ||
|
||
return new OneTrust(); | ||
|
||
// } | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
export default CookieConsentFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import logger from "../../utils/logUtil"; | ||
|
||
/* eslint-disable class-methods-use-this */ | ||
class OneTrust { | ||
constructor(sourceConfig) { | ||
this.sourceConfig = sourceConfig; | ||
// If user does not load onetrust sdk before loading rudderstack sdk | ||
// we will not be filtering any of the destinations. | ||
if (!window.OneTrust || !window.OnetrustActiveGroups) { | ||
logger.debug( | ||
`Onetrust window objects not retrieved. Thus events are sent.` | ||
); | ||
return true; | ||
} | ||
// OneTrust Cookie Compliance populates a data layer object OnetrustActiveGroups with | ||
// the cookie categories that the user has consented to. | ||
// Eg: ',C0001,C0003,' | ||
// We split it and save it as an array. | ||
|
||
const userSetConsentGroupIds = window.OnetrustActiveGroups.split(","); // Ids user has consented | ||
|
||
// Get information about the cookie script - data includes, consent models, cookies in preference centre, etc. | ||
// We get the groups(cookie categorization), user has created in one trust account. | ||
|
||
const oneTrustAllGroupsInfo = window.OneTrust.GetDomainData().Groups; | ||
this.userSetConsentGroupNames = []; | ||
|
||
// Get the names of the cookies consented by the user in the browser. | ||
|
||
oneTrustAllGroupsInfo.forEach((group) => { | ||
const { CustomGroupId, GroupName } = group; | ||
if (userSetConsentGroupIds.includes(CustomGroupId)) { | ||
this.userSetConsentGroupNames.push(GroupName.toUpperCase().trim()); | ||
} | ||
}); | ||
} | ||
|
||
isEnabled(destConfig) { | ||
try { | ||
/** | ||
* Structure of onetrust consent group destination config. | ||
* | ||
* "oneTrustConsentGroup": [ | ||
{ | ||
"oneTrustConsentGroup": "Performance Cookies" | ||
}, | ||
{ | ||
"oneTrustConsentGroup": "Functional Cookies" | ||
}, | ||
{ | ||
"oneTrustConsentGroup": "" | ||
} | ||
] | ||
* | ||
*/ | ||
|
||
const { oneTrustCookieCategories } = destConfig; // mapping of the destination with the consent group name | ||
|
||
// If the destination do not have this mapping events will be sent. | ||
|
||
if (!oneTrustCookieCategories) { | ||
return true; | ||
} | ||
|
||
// Change the structure of oneTrustConsentGroup as an array and filter values if empty string | ||
// Eg: | ||
// ["Performance Cookies", "Functional Cookies"] | ||
|
||
const oneTrustConsentGroupArr = oneTrustCookieCategories | ||
.map((c) => c.oneTrustCookieCategory) | ||
.filter((n) => n); | ||
let containsAllConsent = true; | ||
|
||
// Check if all the destination's mapped cookie categories are consented by the user in the browser. | ||
containsAllConsent = oneTrustConsentGroupArr.every((element) => | ||
this.userSetConsentGroupNames.includes(element.toUpperCase().trim()) | ||
); | ||
|
||
return containsAllConsent; | ||
} catch (e) { | ||
logger.error(`Error during onetrust cookie consent management ${e}`); | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
export default OneTrust; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import OneTrust from "./browser"; | ||
|
||
export { OneTrust }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.