Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consent: Use Category ID i.e. Cookie Consent Group ID only #919

Merged
merged 9 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/big-coins-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@segment/analytics-consent-wrapper-onetrust': patch
---

Require category IDs for OneTrust mapping (e.g CAT0002, SEG0003), and do not accept category name any more. Reason: documentation is easier, and Segment currently has a 20 char limit on category IDs.
24 changes: 19 additions & 5 deletions packages/consent/consent-wrapper-onetrust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,23 @@ This package is for the OneTrust integration for analytics consent

# Quick Start

## Configure OneTrust + Segment
### Ensure that the OneTrust Banner SDK is loaded first
```html
<head>
<!-- This should be included before the Segment snippet -->
<script src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js" type="text/javascript" charset="UTF-8"
data-domain-script="0000-0000-000-test"></script>
```

### Ensure that consent is enabled and that you have created your Integration -> Consent Category Mappings
- Ensure that your integrations in the Segment UI have consent enabled, and that they map to your Consent Category IDs (also called Cookie Group IDs or Cookie Consent IDs).
The IDs look like "CAT0001", "CAT0002"and are configurable in OneTrust
![onetrust category ids](img/onetrust-cat-id.jpg)

## Install dependency
- Debugging: this library expects the [OneTrust Banner SDK](https://community.cookiepro.com/s/article/UUID-d8291f61-aa31-813a-ef16-3f6dec73d643?language=en_US) to be available in order interact with OneTrust. This library derives the group IDs that are active for the current user from the `window.OneTrustActiveGroups` object provided by the OneTrust SDK. [Read this for more information [community.cookiepro.com]](https://community.cookiepro.com/s/article/UUID-66bcaaf1-c7ca-5f32-6760-c75a1337c226?language=en_US).

## Install dependency

```sh
npm install @segment/analytics-consent-wrapper-onetrust
Expand All @@ -16,8 +31,8 @@ yarn add @segment/analytics-consent-wrapper-onetrust

## For `npm` library users

- Use the following initialization code

- Use the following initialization code
```ts
import { oneTrust } from '@segment/analytics-consent-wrapper-onetrust'
import { AnalyticsBrowser } from '@segment/analytics-next'
Expand All @@ -30,7 +45,7 @@ analytics.load({ writeKey: '<MY_WRITE_KEY'> })
```

## For snippet users (window.analytics) who _also_ use a bundler like webpack
### *NOTE:* a pre-bundled version that can be loaded through a `<script>` is on the roadmap, but _not_ supported at this point
### _NOTE:_ a pre-bundled version that can be loaded through a `<script>` is on the roadmap, but _not_ supported at this point

- Install the dependency (see directions)
- Delete the `analytics.load()` line from the snippet
Expand All @@ -39,12 +54,11 @@ analytics.load({ writeKey: '<MY_WRITE_KEY'> })
- analytics.load("<MY_WRITE_KEY>");
```

- Use the following initialization code
- Use the following initialization code

```ts
import { oneTrust } from '@segment/analytics-consent-wrapper-onetrust'

oneTrust(window.analytics)
window.analytics.load('<WRITE_KEY>')

```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ const throwNotImplemented = (): never => {
const grpFixture = {
StrictlyNeccessary: {
CustomGroupId: 'C0001',
GroupName: 'Strictly Neccessary Cookies',
},
Targeting: {
CustomGroupId: 'C0004',
GroupName: 'Targeting Cookies',
},
Performance: {
CustomGroupId: 'C0005',
GroupName: 'Performance Cookies',
},
}

Expand Down Expand Up @@ -112,11 +109,8 @@ describe('High level "integration" tests', () => {
// contain both consented and denied category
expect(categories).toEqual({
C0001: true,
'Strictly Neccessary Cookies': true,
C0004: false,
'Targeting Cookies': false,
C0005: false,
'Performance Cookies': false,
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ export const oneTrust = (
(acc, c) => {
return {
...acc,
[c.groupName]: true,
[c.customGroupId]: true,
[c.groupId]: true,
}
},
{}
Expand All @@ -57,8 +56,7 @@ export const oneTrust = (
(acc, c) => {
return {
...acc,
[c.groupName]: false,
[c.customGroupId]: false,
[c.groupId]: false,
}
},
{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,40 +49,31 @@ describe(getGroupData, () => {
Groups: [
{
CustomGroupId: 'C0001',
GroupName: 'Strictly Neccessary Cookies',
},
{
CustomGroupId: 'C0004',
GroupName: 'Targeting Cookies',
},
{
CustomGroupId: 'SOME_OTHER_GROUP',
GroupName: 'Some other group',
},
],
}),
}
const data = getGroupData()

expect(data.userSetConsentGroups).toMatchInlineSnapshot(`
Array [
Object {
"customGroupId": "C0001",
"groupName": "Strictly Neccessary Cookies",
},
Object {
"customGroupId": "C0004",
"groupName": "Targeting Cookies",
},
]
`)
expect(data.userDeniedConsentGroups).toMatchInlineSnapshot(`
Array [
Object {
"customGroupId": "SOME_OTHER_GROUP",
"groupName": "Some other group",
expect(data.userSetConsentGroups).toEqual([
{
groupId: 'C0001',
},
]
`)
{
groupId: 'C0004',
},
])

expect(data.userDeniedConsentGroups).toEqual([
{
groupId: 'SOME_OTHER_GROUP',
},
])
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const normalizeActiveGroupIds = (c: string): string[] =>

type GroupInfoDto = {
CustomGroupId: string
GroupName: string
}

/**
Expand Down Expand Up @@ -43,13 +42,11 @@ export const getConsentedGroupIds = (): string[] => {
}

export type GroupInfo = {
customGroupId: string
groupName: string
groupId: string
}

const normalizeGroupInfo = (groupInfo: GroupInfoDto): GroupInfo => ({
customGroupId: groupInfo.CustomGroupId.trim(),
groupName: groupInfo.GroupName.trim(), // should we allow groupName?
groupId: groupInfo.CustomGroupId.trim(),
})

/**
Expand All @@ -73,7 +70,7 @@ export const getGroupData = (): UserConsentGroupData => {
// partition all groups into "consent" or "deny"
const userConsentGroupData = getAllGroups().reduce<UserConsentGroupData>(
(acc, group) => {
if (userSetConsentGroupIds.includes(group.customGroupId)) {
if (userSetConsentGroupIds.includes(group.groupId)) {
acc.userSetConsentGroups.push(group)
} else {
acc.userDeniedConsentGroups.push(group)
Expand Down