@ht-sdks/consent-manager 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +45 -0
- package/README.md +851 -0
- package/commonjs/__tests__/consent-manager-builder/analytics.test.js +250 -0
- package/commonjs/__tests__/consent-manager-builder/fetch-destinations.test.js +155 -0
- package/commonjs/__tests__/consent-manager-builder/index.todo.js +327 -0
- package/commonjs/__tests__/consent-manager-builder/preferences.test.js +129 -0
- package/commonjs/__tests__/index.test.js +57 -0
- package/commonjs/consent-manager/banner.js +89 -0
- package/commonjs/consent-manager/buttons.js +18 -0
- package/commonjs/consent-manager/cancel-dialog.js +76 -0
- package/commonjs/consent-manager/categories.js +29 -0
- package/commonjs/consent-manager/container.js +169 -0
- package/commonjs/consent-manager/dialog.js +129 -0
- package/commonjs/consent-manager/font-styles.js +10 -0
- package/commonjs/consent-manager/index.js +244 -0
- package/commonjs/consent-manager/preference-dialog.js +178 -0
- package/commonjs/consent-manager-builder/analytics.js +76 -0
- package/commonjs/consent-manager-builder/fetch-destinations.js +104 -0
- package/commonjs/consent-manager-builder/index.js +330 -0
- package/commonjs/consent-manager-builder/preferences.js +82 -0
- package/commonjs/index.js +39 -0
- package/commonjs/standalone.js +86 -0
- package/commonjs/types.js +3 -0
- package/esm/__tests__/consent-manager-builder/analytics.test.js +245 -0
- package/esm/__tests__/consent-manager-builder/fetch-destinations.test.js +150 -0
- package/esm/__tests__/consent-manager-builder/index.todo.js +322 -0
- package/esm/__tests__/consent-manager-builder/preferences.test.js +124 -0
- package/esm/__tests__/index.test.js +55 -0
- package/esm/consent-manager/banner.js +65 -0
- package/esm/consent-manager/buttons.js +12 -0
- package/esm/consent-manager/cancel-dialog.js +52 -0
- package/esm/consent-manager/categories.js +26 -0
- package/esm/consent-manager/container.js +162 -0
- package/esm/consent-manager/dialog.js +105 -0
- package/esm/consent-manager/font-styles.js +8 -0
- package/esm/consent-manager/index.js +220 -0
- package/esm/consent-manager/preference-dialog.js +154 -0
- package/esm/consent-manager-builder/analytics.js +73 -0
- package/esm/consent-manager-builder/fetch-destinations.js +98 -0
- package/esm/consent-manager-builder/index.js +325 -0
- package/esm/consent-manager-builder/preferences.js +73 -0
- package/esm/index.js +28 -0
- package/esm/standalone.js +58 -0
- package/esm/types.js +1 -0
- package/package.json +168 -0
- package/src/__tests__/consent-manager-builder/analytics.test.ts +279 -0
- package/src/__tests__/consent-manager-builder/fetch-destinations.test.ts +89 -0
- package/src/__tests__/consent-manager-builder/index.todo.js +386 -0
- package/src/__tests__/consent-manager-builder/preferences.test.ts +156 -0
- package/src/__tests__/index.test.ts +68 -0
- package/src/consent-manager/banner.tsx +227 -0
- package/src/consent-manager/buttons.tsx +78 -0
- package/src/consent-manager/cancel-dialog.tsx +68 -0
- package/src/consent-manager/categories.ts +27 -0
- package/src/consent-manager/container.tsx +282 -0
- package/src/consent-manager/dialog.tsx +236 -0
- package/src/consent-manager/font-styles.tsx +14 -0
- package/src/consent-manager/index.tsx +327 -0
- package/src/consent-manager/preference-dialog.tsx +371 -0
- package/src/consent-manager-builder/analytics.ts +104 -0
- package/src/consent-manager-builder/fetch-destinations.ts +50 -0
- package/src/consent-manager-builder/index.tsx +426 -0
- package/src/consent-manager-builder/preferences.ts +100 -0
- package/src/index.ts +42 -0
- package/src/standalone.tsx +57 -0
- package/src/styled.d.ts +7 -0
- package/src/types.ts +151 -0
- package/standalone/consent-manager.js +23 -0
- package/standalone/consent-manager.js.map +1 -0
- package/types/__tests__/consent-manager-builder/analytics.test.d.ts +1 -0
- package/types/__tests__/consent-manager-builder/fetch-destinations.test.d.ts +1 -0
- package/types/__tests__/consent-manager-builder/index.todo.d.ts +1 -0
- package/types/__tests__/consent-manager-builder/preferences.test.d.ts +1 -0
- package/types/__tests__/index.test.d.ts +1 -0
- package/types/consent-manager/banner.d.ts +21 -0
- package/types/consent-manager/buttons.d.ts +13 -0
- package/types/consent-manager/cancel-dialog.d.ts +19 -0
- package/types/consent-manager/categories.d.ts +3 -0
- package/types/consent-manager/container.d.ts +35 -0
- package/types/consent-manager/dialog.d.ts +29 -0
- package/types/consent-manager/font-styles.d.ts +2 -0
- package/types/consent-manager/index.d.ts +35 -0
- package/types/consent-manager/preference-dialog.d.ts +32 -0
- package/types/consent-manager-builder/analytics.d.ts +14 -0
- package/types/consent-manager-builder/fetch-destinations.d.ts +2 -0
- package/types/consent-manager-builder/index.d.ts +126 -0
- package/types/consent-manager-builder/preferences.d.ts +26 -0
- package/types/index.d.ts +7 -0
- package/types/src/__tests__/consent-manager-builder/analytics.test.d.ts +1 -0
- package/types/src/__tests__/consent-manager-builder/fetch-destinations.test.d.ts +1 -0
- package/types/src/__tests__/consent-manager-builder/preferences.test.d.ts +1 -0
- package/types/src/__tests__/index.test.d.ts +1 -0
- package/types/src/consent-manager/banner.d.ts +21 -0
- package/types/src/consent-manager/buttons.d.ts +13 -0
- package/types/src/consent-manager/cancel-dialog.d.ts +19 -0
- package/types/src/consent-manager/categories.d.ts +3 -0
- package/types/src/consent-manager/container.d.ts +35 -0
- package/types/src/consent-manager/dialog.d.ts +29 -0
- package/types/src/consent-manager/font-styles.d.ts +2 -0
- package/types/src/consent-manager/index.d.ts +35 -0
- package/types/src/consent-manager/preference-dialog.d.ts +32 -0
- package/types/src/consent-manager-builder/analytics.d.ts +14 -0
- package/types/src/consent-manager-builder/fetch-destinations.d.ts +2 -0
- package/types/src/consent-manager-builder/index.d.ts +126 -0
- package/types/src/consent-manager-builder/preferences.d.ts +26 -0
- package/types/src/index.d.ts +7 -0
- package/types/src/standalone.d.ts +5 -0
- package/types/src/types.d.ts +131 -0
- package/types/standalone.d.ts +5 -0
- package/types/types.d.ts +131 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import React, { PureComponent } from 'react'
|
|
2
|
+
import ReactDOM from 'react-dom'
|
|
3
|
+
import styled from '@emotion/styled'
|
|
4
|
+
import { keyframes } from '@emotion/react'
|
|
5
|
+
|
|
6
|
+
import nanoid from 'nanoid'
|
|
7
|
+
import fontStyles from './font-styles'
|
|
8
|
+
|
|
9
|
+
const ANIMATION_DURATION = '200ms'
|
|
10
|
+
const ANIMATION_EASING = 'cubic-bezier(0.0, 0.0, 0.2, 1)'
|
|
11
|
+
|
|
12
|
+
const Overlay = styled('div')`
|
|
13
|
+
position: fixed;
|
|
14
|
+
left: 0;
|
|
15
|
+
right: 0;
|
|
16
|
+
top: 0;
|
|
17
|
+
bottom: 0;
|
|
18
|
+
z-index: 1000;
|
|
19
|
+
display: flex;
|
|
20
|
+
align-items: center;
|
|
21
|
+
justify-content: center;
|
|
22
|
+
background: rgba(67, 90, 111, 0.699);
|
|
23
|
+
`
|
|
24
|
+
|
|
25
|
+
const openAnimation = keyframes`
|
|
26
|
+
from {
|
|
27
|
+
transform: scale(0.8);
|
|
28
|
+
opacity: 0;
|
|
29
|
+
}
|
|
30
|
+
to {
|
|
31
|
+
transform: scale(1);
|
|
32
|
+
opacity: 1;
|
|
33
|
+
}
|
|
34
|
+
`
|
|
35
|
+
|
|
36
|
+
interface RootProps {
|
|
37
|
+
readonly width: number | string | undefined
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const Root = styled('section')<RootProps>`
|
|
41
|
+
${fontStyles};
|
|
42
|
+
display: flex;
|
|
43
|
+
flex-direction: column;
|
|
44
|
+
max-width: calc(100vw - 16px);
|
|
45
|
+
max-height: calc(100% - 16px);
|
|
46
|
+
width: ${props => props.width};
|
|
47
|
+
margin: 8px;
|
|
48
|
+
background: #fff;
|
|
49
|
+
border-radius: 8px;
|
|
50
|
+
animation: ${openAnimation} ${ANIMATION_DURATION} ${ANIMATION_EASING} both;
|
|
51
|
+
`
|
|
52
|
+
|
|
53
|
+
const Form = styled('form')`
|
|
54
|
+
display: flex;
|
|
55
|
+
flex-direction: column;
|
|
56
|
+
min-height: 0;
|
|
57
|
+
`
|
|
58
|
+
|
|
59
|
+
const Header = styled('div')`
|
|
60
|
+
flex: 1 0 auto;
|
|
61
|
+
display: flex;
|
|
62
|
+
align-items: center;
|
|
63
|
+
justify-content: space-between;
|
|
64
|
+
padding: 12px 16px;
|
|
65
|
+
border-bottom: 1px solid rgba(67, 90, 111, 0.079);
|
|
66
|
+
`
|
|
67
|
+
|
|
68
|
+
const Title = styled('h2')`
|
|
69
|
+
margin: 0;
|
|
70
|
+
color: #1f4160;
|
|
71
|
+
font-size: 16px;
|
|
72
|
+
font-weight: 600;
|
|
73
|
+
line-height: 1.3;
|
|
74
|
+
`
|
|
75
|
+
|
|
76
|
+
const HeaderCancelButton = styled('button')`
|
|
77
|
+
padding: 8px;
|
|
78
|
+
border: none;
|
|
79
|
+
background: none;
|
|
80
|
+
color: inherit;
|
|
81
|
+
font: inherit;
|
|
82
|
+
font-size: 14px;
|
|
83
|
+
line-height: 1;
|
|
84
|
+
cursor: pointer;
|
|
85
|
+
`
|
|
86
|
+
|
|
87
|
+
const Content = styled('div')`
|
|
88
|
+
overflow-y: auto;
|
|
89
|
+
padding: 16px;
|
|
90
|
+
padding-bottom: 0;
|
|
91
|
+
min-height: 0;
|
|
92
|
+
font-size: 14px;
|
|
93
|
+
line-height: 1.2;
|
|
94
|
+
|
|
95
|
+
p {
|
|
96
|
+
margin: 0;
|
|
97
|
+
&:not(:last-child) {
|
|
98
|
+
margin-bottom: 0.7em;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
a {
|
|
103
|
+
color: #47b881;
|
|
104
|
+
&:hover {
|
|
105
|
+
color: #64c395;
|
|
106
|
+
}
|
|
107
|
+
&:active {
|
|
108
|
+
color: #248953;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
`
|
|
112
|
+
|
|
113
|
+
const Buttons = styled('div')`
|
|
114
|
+
padding: 16px;
|
|
115
|
+
text-align: right;
|
|
116
|
+
`
|
|
117
|
+
|
|
118
|
+
interface DialogProps {
|
|
119
|
+
innerRef: (element: HTMLElement | null) => void
|
|
120
|
+
onCancel?: () => void
|
|
121
|
+
onSubmit: (e: React.FormEvent<HTMLFormElement>) => void
|
|
122
|
+
title: React.ReactNode
|
|
123
|
+
buttons: React.ReactNode
|
|
124
|
+
width?: string
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export default class Dialog extends PureComponent<DialogProps, {}> {
|
|
128
|
+
static displayName = 'Dialog'
|
|
129
|
+
private titleId: string
|
|
130
|
+
private container: HTMLElement
|
|
131
|
+
private root: HTMLElement
|
|
132
|
+
private form: HTMLFormElement
|
|
133
|
+
|
|
134
|
+
static defaultProps = {
|
|
135
|
+
onCancel: undefined,
|
|
136
|
+
width: '750px'
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
constructor(props: DialogProps) {
|
|
140
|
+
super(props)
|
|
141
|
+
|
|
142
|
+
this.titleId = nanoid()
|
|
143
|
+
this.container = document.createElement('div')
|
|
144
|
+
this.container.setAttribute('data-consent-manager-dialog', '')
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
render() {
|
|
148
|
+
const { onCancel, onSubmit, title, children, buttons, width } = this.props
|
|
149
|
+
|
|
150
|
+
const dialog = (
|
|
151
|
+
<Overlay id="hightouchio_overlayDialog" onClick={this.handleOverlayClick}>
|
|
152
|
+
<Root
|
|
153
|
+
id="hightouchio_rootDialog"
|
|
154
|
+
ref={this.handleRootRef}
|
|
155
|
+
role="dialog"
|
|
156
|
+
aria-modal
|
|
157
|
+
aria-labelledby={this.titleId}
|
|
158
|
+
width={width}
|
|
159
|
+
>
|
|
160
|
+
<Header id="hightouchio_headerDialog">
|
|
161
|
+
<Title id={this.titleId}>{title}</Title>
|
|
162
|
+
{onCancel && (
|
|
163
|
+
<HeaderCancelButton
|
|
164
|
+
id="hightouchio_headerCancelBtn"
|
|
165
|
+
onClick={onCancel}
|
|
166
|
+
title="Cancel"
|
|
167
|
+
aria-label="Cancel"
|
|
168
|
+
>
|
|
169
|
+
✕
|
|
170
|
+
</HeaderCancelButton>
|
|
171
|
+
)}
|
|
172
|
+
</Header>
|
|
173
|
+
|
|
174
|
+
<Form
|
|
175
|
+
id={`preferenceDialogForm_${this.titleId}`}
|
|
176
|
+
ref={this.handleFormRef}
|
|
177
|
+
onSubmit={onSubmit}
|
|
178
|
+
>
|
|
179
|
+
<Content id="hightouchio_contentDialog">{children}</Content>
|
|
180
|
+
|
|
181
|
+
<Buttons id="hightouchio_buttonsDialog">{buttons}</Buttons>
|
|
182
|
+
</Form>
|
|
183
|
+
</Root>
|
|
184
|
+
</Overlay>
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
return ReactDOM.createPortal(dialog, this.container)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
componentDidMount() {
|
|
191
|
+
const { innerRef } = this.props
|
|
192
|
+
|
|
193
|
+
if (this.form) {
|
|
194
|
+
const input: HTMLInputElement | null = this.form.querySelector('input,button')
|
|
195
|
+
if (input) {
|
|
196
|
+
input.focus()
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
document.body.appendChild(this.container)
|
|
200
|
+
document.body.addEventListener('keydown', this.handleEsc, false)
|
|
201
|
+
document.body.style.overflow = 'hidden'
|
|
202
|
+
innerRef(this.container)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
componentWillUnmount() {
|
|
206
|
+
const { innerRef } = this.props
|
|
207
|
+
document.body.removeEventListener('keydown', this.handleEsc, false)
|
|
208
|
+
document.body.style.overflow = ''
|
|
209
|
+
document.body.removeChild(this.container)
|
|
210
|
+
innerRef(null)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
handleRootRef = (node: HTMLElement) => {
|
|
214
|
+
this.root = node
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
handleFormRef = (node: HTMLFormElement) => {
|
|
218
|
+
this.form = node
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
handleOverlayClick = e => {
|
|
222
|
+
const { onCancel } = this.props
|
|
223
|
+
// Ignore propogated clicks from inside the dialog
|
|
224
|
+
if (onCancel && this.root && !this.root.contains(e.target)) {
|
|
225
|
+
onCancel()
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
handleEsc = (e: KeyboardEvent) => {
|
|
230
|
+
const { onCancel } = this.props
|
|
231
|
+
// Esc key
|
|
232
|
+
if (onCancel && e.keyCode === 27) {
|
|
233
|
+
onCancel()
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { css } from '@emotion/react'
|
|
2
|
+
|
|
3
|
+
export default css`
|
|
4
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial,
|
|
5
|
+
sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
|
|
6
|
+
-moz-osx-font-smoothing: grayscale;
|
|
7
|
+
-webkit-font-smoothing: antialiased;
|
|
8
|
+
font-smoothing: antialiased;
|
|
9
|
+
color: #435a6f;
|
|
10
|
+
font-size: 16px;
|
|
11
|
+
font-weight: 400;
|
|
12
|
+
line-height: 22px;
|
|
13
|
+
letter-spacing: -0.05px;
|
|
14
|
+
`
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import React, { PureComponent } from 'react'
|
|
2
|
+
import ConsentManagerBuilder from '../consent-manager-builder'
|
|
3
|
+
import Container from './container'
|
|
4
|
+
import { ADVERTISING_CATEGORIES, FUNCTIONAL_CATEGORIES } from './categories'
|
|
5
|
+
import {
|
|
6
|
+
CategoryPreferences,
|
|
7
|
+
Destination,
|
|
8
|
+
ConsentManagerProps,
|
|
9
|
+
PreferenceDialogTemplate
|
|
10
|
+
} from '../types'
|
|
11
|
+
|
|
12
|
+
const zeroValuePreferences: CategoryPreferences = {
|
|
13
|
+
marketingAndAnalytics: null,
|
|
14
|
+
advertising: null,
|
|
15
|
+
functional: null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const defaultPreferencesDialogTemplate: PreferenceDialogTemplate = {
|
|
19
|
+
headings: {
|
|
20
|
+
allowValue: 'Allow',
|
|
21
|
+
categoryValue: 'Category',
|
|
22
|
+
purposeValue: 'Purpose',
|
|
23
|
+
toolsValue: 'Tools'
|
|
24
|
+
},
|
|
25
|
+
checkboxes: {
|
|
26
|
+
noValue: 'No',
|
|
27
|
+
yesValue: 'Yes'
|
|
28
|
+
},
|
|
29
|
+
actionButtons: {
|
|
30
|
+
cancelValue: 'Cancel',
|
|
31
|
+
saveValue: 'Save'
|
|
32
|
+
},
|
|
33
|
+
cancelDialogButtons: {
|
|
34
|
+
cancelValue: 'Yes, Cancel',
|
|
35
|
+
backValue: 'Go Back'
|
|
36
|
+
},
|
|
37
|
+
categories: [
|
|
38
|
+
{
|
|
39
|
+
key: 'functional',
|
|
40
|
+
name: 'Functional',
|
|
41
|
+
description:
|
|
42
|
+
'To monitor the performance of our site and to enhance your browsing experience.',
|
|
43
|
+
example: 'For example, these tools enable you to communicate with us via live chat.'
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
key: 'marketing',
|
|
47
|
+
name: 'Marketing and Analytics',
|
|
48
|
+
description:
|
|
49
|
+
'To understand user behavior in order to provide you with a more relevant browsing experience or personalize the content on our site.',
|
|
50
|
+
example:
|
|
51
|
+
'For example, we collect information about which pages you visit to help us present more relevant information.'
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
key: 'advertising',
|
|
55
|
+
name: 'Advertising',
|
|
56
|
+
description:
|
|
57
|
+
'To personalize and measure the effectiveness of advertising on our site and other websites.',
|
|
58
|
+
example:
|
|
59
|
+
'For example, we may serve you a personalized ad based on the pages you visit on our site.'
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
key: 'essential',
|
|
63
|
+
name: 'Essential',
|
|
64
|
+
description: 'We use browser cookies that are necessary for the site to work as intended.',
|
|
65
|
+
example:
|
|
66
|
+
'For example, we store your website data collection preferences so we can honor them if you return to our site. You can disable these cookies in your browser settings but if you do the site may not work as intended.'
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
export default class ConsentManager extends PureComponent<ConsentManagerProps, {}> {
|
|
71
|
+
static displayName = 'ConsentManager'
|
|
72
|
+
|
|
73
|
+
static defaultProps = {
|
|
74
|
+
options: undefined,
|
|
75
|
+
shouldRequireConsent: () => true,
|
|
76
|
+
implyConsentOnInteraction: false,
|
|
77
|
+
onError: undefined,
|
|
78
|
+
cookieDomain: undefined,
|
|
79
|
+
cookieName: undefined,
|
|
80
|
+
cookieExpires: undefined,
|
|
81
|
+
cookieAttributes: {},
|
|
82
|
+
customCategories: undefined,
|
|
83
|
+
bannerActionsBlock: undefined,
|
|
84
|
+
bannerHideCloseButton: false,
|
|
85
|
+
bannerTextColor: '#fff',
|
|
86
|
+
bannerContent:
|
|
87
|
+
'We use cookies (and other similar technologies) to collect data to improve your experience on our site. By using our website, you’re agreeing to the collection of data as described in our Privacy Policy.',
|
|
88
|
+
bannerSubContent: 'You can change your preferences at any time.',
|
|
89
|
+
bannerBackgroundColor: '#1f4160',
|
|
90
|
+
preferencesDialogTitle: 'Website Data Collection Preferences',
|
|
91
|
+
preferencesDialogContent: (
|
|
92
|
+
<div>
|
|
93
|
+
<p>
|
|
94
|
+
We use data collected by cookies and JavaScript libraries to improve your browsing
|
|
95
|
+
experience, analyze site traffic, deliver personalized advertisements, and increase the
|
|
96
|
+
overall performance of our site.
|
|
97
|
+
</p>
|
|
98
|
+
<p>By using our website, you’re agreeing to our Privacy Policy.</p>
|
|
99
|
+
<p>
|
|
100
|
+
The table below outlines how we use this data by category. To opt out of a category of
|
|
101
|
+
data collection, select “No” and save your preferences.
|
|
102
|
+
</p>
|
|
103
|
+
</div>
|
|
104
|
+
),
|
|
105
|
+
cancelDialogTitle: 'Are you sure you want to cancel?',
|
|
106
|
+
cancelDialogContent:
|
|
107
|
+
'Your preferences have not been saved. By continuing to use our website, you’re agreeing to our Privacy Policy.',
|
|
108
|
+
defaultDestinationBehavior: 'disable',
|
|
109
|
+
preferencesDialogTemplate: defaultPreferencesDialogTemplate
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
render() {
|
|
113
|
+
const {
|
|
114
|
+
writeKey,
|
|
115
|
+
options,
|
|
116
|
+
shouldRequireConsent,
|
|
117
|
+
implyConsentOnInteraction,
|
|
118
|
+
cookieDomain,
|
|
119
|
+
cookieName,
|
|
120
|
+
cookieExpires,
|
|
121
|
+
cookieAttributes,
|
|
122
|
+
bannerContent,
|
|
123
|
+
bannerActionsBlock,
|
|
124
|
+
bannerSubContent,
|
|
125
|
+
bannerTextColor,
|
|
126
|
+
bannerBackgroundColor,
|
|
127
|
+
bannerHideCloseButton,
|
|
128
|
+
bannerAsModal,
|
|
129
|
+
preferencesDialogTitle,
|
|
130
|
+
preferencesDialogContent,
|
|
131
|
+
cancelDialogTitle,
|
|
132
|
+
cancelDialogContent,
|
|
133
|
+
customCategories,
|
|
134
|
+
defaultDestinationBehavior,
|
|
135
|
+
cdnHost,
|
|
136
|
+
preferencesDialogTemplate,
|
|
137
|
+
onError
|
|
138
|
+
} = this.props
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<ConsentManagerBuilder
|
|
142
|
+
onError={onError}
|
|
143
|
+
writeKey={writeKey}
|
|
144
|
+
options={options}
|
|
145
|
+
shouldRequireConsent={shouldRequireConsent}
|
|
146
|
+
cookieDomain={cookieDomain}
|
|
147
|
+
cookieName={cookieName}
|
|
148
|
+
cookieExpires={cookieExpires}
|
|
149
|
+
cookieAttributes={cookieAttributes}
|
|
150
|
+
initialPreferences={this.getInitialPreferences()}
|
|
151
|
+
mapCustomPreferences={this.handleMapCustomPreferences}
|
|
152
|
+
customCategories={customCategories}
|
|
153
|
+
defaultDestinationBehavior={defaultDestinationBehavior}
|
|
154
|
+
cdnHost={cdnHost}
|
|
155
|
+
>
|
|
156
|
+
{({
|
|
157
|
+
destinations,
|
|
158
|
+
customCategories,
|
|
159
|
+
newDestinations,
|
|
160
|
+
preferences,
|
|
161
|
+
isConsentRequired,
|
|
162
|
+
setPreferences,
|
|
163
|
+
resetPreferences,
|
|
164
|
+
saveConsent,
|
|
165
|
+
havePreferencesChanged,
|
|
166
|
+
workspaceAddedNewDestinations
|
|
167
|
+
}) => {
|
|
168
|
+
return (
|
|
169
|
+
<Container
|
|
170
|
+
customCategories={customCategories}
|
|
171
|
+
destinations={destinations}
|
|
172
|
+
newDestinations={newDestinations}
|
|
173
|
+
preferences={preferences}
|
|
174
|
+
isConsentRequired={isConsentRequired}
|
|
175
|
+
setPreferences={setPreferences}
|
|
176
|
+
resetPreferences={resetPreferences}
|
|
177
|
+
saveConsent={saveConsent}
|
|
178
|
+
closeBehavior={this.props.closeBehavior}
|
|
179
|
+
implyConsentOnInteraction={
|
|
180
|
+
implyConsentOnInteraction ?? ConsentManager.defaultProps.implyConsentOnInteraction
|
|
181
|
+
}
|
|
182
|
+
bannerContent={bannerContent}
|
|
183
|
+
bannerSubContent={bannerSubContent}
|
|
184
|
+
bannerActionsBlock={bannerActionsBlock}
|
|
185
|
+
bannerHideCloseButton={bannerHideCloseButton}
|
|
186
|
+
bannerTextColor={bannerTextColor || ConsentManager.defaultProps.bannerTextColor}
|
|
187
|
+
bannerBackgroundColor={
|
|
188
|
+
bannerBackgroundColor || ConsentManager.defaultProps.bannerBackgroundColor
|
|
189
|
+
}
|
|
190
|
+
bannerAsModal={bannerAsModal}
|
|
191
|
+
preferencesDialogTitle={preferencesDialogTitle}
|
|
192
|
+
preferencesDialogContent={preferencesDialogContent}
|
|
193
|
+
cancelDialogTitle={cancelDialogTitle}
|
|
194
|
+
cancelDialogContent={cancelDialogContent}
|
|
195
|
+
havePreferencesChanged={havePreferencesChanged}
|
|
196
|
+
defaultDestinationBehavior={defaultDestinationBehavior}
|
|
197
|
+
workspaceAddedNewDestinations={workspaceAddedNewDestinations}
|
|
198
|
+
preferencesDialogTemplate={
|
|
199
|
+
preferencesDialogTemplate
|
|
200
|
+
? this.mergeTemplates(preferencesDialogTemplate, defaultPreferencesDialogTemplate)
|
|
201
|
+
: ConsentManager.defaultProps.preferencesDialogTemplate
|
|
202
|
+
}
|
|
203
|
+
/>
|
|
204
|
+
)
|
|
205
|
+
}}
|
|
206
|
+
</ConsentManagerBuilder>
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
mergeTemplates = (
|
|
211
|
+
newProps: PreferenceDialogTemplate,
|
|
212
|
+
defaultPreferencesDialogTemplate: PreferenceDialogTemplate
|
|
213
|
+
): PreferenceDialogTemplate => {
|
|
214
|
+
const headingsMerge = {
|
|
215
|
+
...defaultPreferencesDialogTemplate.headings,
|
|
216
|
+
...newProps.headings
|
|
217
|
+
}
|
|
218
|
+
const checkboxesMerge = {
|
|
219
|
+
...defaultPreferencesDialogTemplate.checkboxes,
|
|
220
|
+
...newProps.checkboxes
|
|
221
|
+
}
|
|
222
|
+
const actionButtonsMerge = {
|
|
223
|
+
...defaultPreferencesDialogTemplate.actionButtons,
|
|
224
|
+
...newProps.actionButtons
|
|
225
|
+
}
|
|
226
|
+
const cancelDialogButtonsMerge = {
|
|
227
|
+
...defaultPreferencesDialogTemplate.cancelDialogButtons,
|
|
228
|
+
...newProps.cancelDialogButtons
|
|
229
|
+
}
|
|
230
|
+
const categoriesMerge = defaultPreferencesDialogTemplate?.categories!.map(category => ({
|
|
231
|
+
...category,
|
|
232
|
+
...newProps?.categories?.find(c => c.key === category.key)
|
|
233
|
+
}))
|
|
234
|
+
return {
|
|
235
|
+
headings: headingsMerge,
|
|
236
|
+
checkboxes: checkboxesMerge,
|
|
237
|
+
actionButtons: actionButtonsMerge,
|
|
238
|
+
cancelDialogButtons: cancelDialogButtonsMerge,
|
|
239
|
+
categories: categoriesMerge
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
getInitialPreferences = () => {
|
|
244
|
+
const { initialPreferences, customCategories } = this.props
|
|
245
|
+
if (initialPreferences) {
|
|
246
|
+
return initialPreferences
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (!customCategories) {
|
|
250
|
+
return zeroValuePreferences
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const initialCustomPreferences = {}
|
|
254
|
+
Object.keys(customCategories).forEach(category => {
|
|
255
|
+
initialCustomPreferences[category] = null
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
return initialCustomPreferences
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
handleMapCustomPreferences = (destinations: Destination[], preferences: CategoryPreferences) => {
|
|
262
|
+
const { customCategories } = this.props
|
|
263
|
+
const destinationPreferences = {}
|
|
264
|
+
const customPreferences = {}
|
|
265
|
+
|
|
266
|
+
if (customCategories) {
|
|
267
|
+
for (const preferenceName of Object.keys(customCategories)) {
|
|
268
|
+
const value = preferences[preferenceName]
|
|
269
|
+
if (typeof value === 'boolean' || typeof value === 'string') {
|
|
270
|
+
customPreferences[preferenceName] = value
|
|
271
|
+
} else {
|
|
272
|
+
customPreferences[preferenceName] = true
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
destinations.forEach(destination => {
|
|
277
|
+
// Mark custom categories
|
|
278
|
+
Object.entries(customCategories).forEach(([categoryName, { integrations }]) => {
|
|
279
|
+
const consentAlreadySetToFalse = destinationPreferences[destination.id] === false
|
|
280
|
+
const shouldSetConsent = integrations?.includes(destination.id) ?? false
|
|
281
|
+
if (shouldSetConsent && !consentAlreadySetToFalse) {
|
|
282
|
+
destinationPreferences[destination.id] = customPreferences[categoryName]
|
|
283
|
+
}
|
|
284
|
+
})
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
return { destinationPreferences, customPreferences }
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Default unset preferences to true (for implicit consent)
|
|
291
|
+
for (const preferenceName of Object.keys(preferences)) {
|
|
292
|
+
const value = preferences[preferenceName]
|
|
293
|
+
if (typeof value === 'boolean') {
|
|
294
|
+
customPreferences[preferenceName] = value
|
|
295
|
+
} else {
|
|
296
|
+
customPreferences[preferenceName] = true
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const customPrefs = customPreferences as CategoryPreferences
|
|
301
|
+
|
|
302
|
+
for (const destination of destinations) {
|
|
303
|
+
// Mark advertising destinations
|
|
304
|
+
if (
|
|
305
|
+
ADVERTISING_CATEGORIES.find(c => c === destination.category) &&
|
|
306
|
+
destinationPreferences[destination.id] !== false
|
|
307
|
+
) {
|
|
308
|
+
destinationPreferences[destination.id] = customPrefs.advertising
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Mark function destinations
|
|
312
|
+
if (
|
|
313
|
+
FUNCTIONAL_CATEGORIES.find(c => c === destination.category) &&
|
|
314
|
+
destinationPreferences[destination.id] !== false
|
|
315
|
+
) {
|
|
316
|
+
destinationPreferences[destination.id] = customPrefs.functional
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Fallback to marketing
|
|
320
|
+
if (!(destination.id in destinationPreferences)) {
|
|
321
|
+
destinationPreferences[destination.id] = customPrefs.marketingAndAnalytics
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return { destinationPreferences, customPreferences }
|
|
326
|
+
}
|
|
327
|
+
}
|