@ht-sdks/consent-manager 0.0.1 → 0.1.0
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/README.md +5 -19
- package/commonjs/__tests__/consent-manager-builder/index.todo.js +6 -3
- package/commonjs/__tests__/consent-manager-builder/preferences.test.js +30 -49
- package/commonjs/consent-manager-builder/analytics.js +3 -5
- package/commonjs/consent-manager-builder/preferences.js +10 -9
- package/esm/__tests__/consent-manager-builder/index.todo.js +6 -3
- package/esm/__tests__/consent-manager-builder/preferences.test.js +30 -49
- package/esm/consent-manager-builder/analytics.js +3 -5
- package/esm/consent-manager-builder/preferences.js +10 -9
- package/package.json +2 -3
- package/src/__tests__/consent-manager-builder/index.todo.js +5 -2
- package/src/__tests__/consent-manager-builder/preferences.test.ts +37 -58
- package/src/consent-manager-builder/analytics.ts +4 -1
- package/src/consent-manager-builder/preferences.ts +15 -11
- package/src/types.ts +0 -1
- package/standalone/consent-manager.js +2 -2
- package/standalone/consent-manager.js.map +1 -1
- package/types/src/types.d.ts +0 -1
- package/types/types.d.ts +0 -1
|
@@ -42,15 +42,16 @@ export function savePreferences(_a) {
|
|
|
42
42
|
var destinationPreferences = _a.destinationPreferences, customPreferences = _a.customPreferences, cookieDomain = _a.cookieDomain, cookieName = _a.cookieName, cookieExpires = _a.cookieExpires, _b = _a.cookieAttributes, cookieAttributes = _b === void 0 ? {} : _b;
|
|
43
43
|
var wd = window;
|
|
44
44
|
if (wd.htevents) {
|
|
45
|
-
wd.htevents.identify({
|
|
46
|
-
destinationTrackingPreferences: destinationPreferences,
|
|
47
|
-
// use `categoryTrackingPreferences` here for consistency with `context.consent.categoryPreferences`
|
|
48
|
-
categoryTrackingPreferences: customPreferences
|
|
49
|
-
});
|
|
50
45
|
wd.htevents.track('Consent Updated', {
|
|
51
|
-
|
|
52
|
-
// use `
|
|
53
|
-
|
|
46
|
+
destinationPreferences: destinationPreferences,
|
|
47
|
+
// use `categoryPreferences` here for consistency with `context.consent.categoryPreferences`
|
|
48
|
+
categoryPreferences: customPreferences
|
|
49
|
+
}, {
|
|
50
|
+
// update `context.consent` here to immediately reflect the updated preferences
|
|
51
|
+
consent: {
|
|
52
|
+
destinationPreferences: destinationPreferences,
|
|
53
|
+
categoryPreferences: customPreferences
|
|
54
|
+
}
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
else {
|
|
@@ -70,4 +71,4 @@ export function savePreferences(_a) {
|
|
|
70
71
|
customPreferences: customPreferences
|
|
71
72
|
});
|
|
72
73
|
}
|
|
73
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
74
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJlZmVyZW5jZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29uc2VudC1tYW5hZ2VyLWJ1aWxkZXIvcHJlZmVyZW5jZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7QUFBQSxvREFBb0Q7QUFDcEQsT0FBTyxPQUE2QixNQUFNLFdBQVcsQ0FBQTtBQUNyRCxPQUFPLFNBQVMsTUFBTSxxQkFBcUIsQ0FBQTtBQUUzQyxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sUUFBUSxDQUFBO0FBRXJDLE1BQU0sQ0FBQyxJQUFNLG1CQUFtQixHQUFHLG1CQUFtQixDQUFBO0FBQ3RELElBQU0sc0JBQXNCLEdBQUcsR0FBRyxDQUFBO0FBY2xDLHVDQUF1QztBQUN2QyxxREFBcUQ7QUFDckQsTUFBTSxVQUFVLGVBQWUsQ0FBQyxVQUFtQjtJQUNqRCxJQUFNLFdBQVcsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLFVBQVUsSUFBSSxtQkFBbUIsQ0FBc0IsQ0FBQTtJQUUzRixJQUFJLENBQUMsV0FBVyxFQUFFO1FBQ2hCLE9BQU8sRUFBR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UNGO1NBQU07UUFDTCxPQUFPLENBQUMsSUFBSSxDQUFDLHNFQUFzRSxDQUFDLENBQUE7S0FDckY7SUFFRCxJQUFNLE1BQU0sR0FBRyxZQUFZLElBQUksU0FBUyxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsSUFBSSxDQUFDLENBQUE7SUFDOUQsSUFBTSxPQUFPLEdBQUcsYUFBYSxJQUFJLHNCQUFzQixDQUFBO0lBQ3ZELElBQU0sS0FBSyxHQUFHO1FBQ1osT0FBTyxFQUFFLENBQUM7UUFDVixXQUFXLEVBQUUsc0JBQXNCO1FBQ25DLE1BQU0sRUFBRSxpQkFBaUI7S0FDTCxDQUFBO0lBRXRCLE9BQU8sQ0FBQyxHQUFHLENBQUMsVUFBVSxJQUFJLG1CQUFtQixFQUFFLEtBQUssYUFDbEQsT0FBTyxTQUFBO1FBQ1AsTUFBTSxRQUFBLElBQ0gsZ0JBQWdCLEVBQ25CLENBQUE7SUFFRixPQUFPLENBQUMsSUFBSSxDQUFDLGtCQUFrQixFQUFFO1FBQy9CLHNCQUFzQix3QkFBQTtRQUN0QixpQkFBaUIsbUJBQUE7S0FDbEIsQ0FBQyxDQUFBO0FBQ0osQ0FBQyJ9
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ht-sdks/consent-manager",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Drop-in consent management plugin for Hightouch Events Browser SDK",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gdpr",
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"scripts": {
|
|
29
29
|
"test": "jest src/__tests__",
|
|
30
30
|
"prepublishOnly": "npm run clean && npm run build",
|
|
31
|
-
"postpublish": "npm run build-storybook && npm run deploy-storybook -- --existing-output-dir=storybook-static",
|
|
32
31
|
"dev": "concurrently 'npm run build-standalone --watch' 'npx start-storybook -s ./ -p 9009'",
|
|
33
32
|
"build-commonjs": "tsc --outDir commonjs --module CommonJS --inlineSourceMap",
|
|
34
33
|
"build-esm": "tsc --module es2015 --outDir esm --inlineSourceMap",
|
|
@@ -37,7 +36,7 @@
|
|
|
37
36
|
"clean": "rm -rf commonjs esm standalone storybook-static types",
|
|
38
37
|
"standalone-hash": "shasum -b -a 256 standalone/consent-manager.js | xxd -r -p | base64",
|
|
39
38
|
"build-storybook": "npm run build-standalone && build-storybook && cp -r ./standalone ./storybook-static/standalone",
|
|
40
|
-
"deploy-storybook": "storybook-to-ghpages",
|
|
39
|
+
"deploy-storybook": "storybook-to-ghpages --existing-output-dir=storybook-static",
|
|
41
40
|
"lint": "eslint \"src/**/*.{ts,tsx}\"",
|
|
42
41
|
"size": "size-limit"
|
|
43
42
|
},
|
|
@@ -172,7 +172,11 @@ describe('ConsentManagerBuilder', () => {
|
|
|
172
172
|
test.skip('if defaultDestinationBehavior is set to imply and category is set to true, loads new destination', done => {
|
|
173
173
|
document.cookie =
|
|
174
174
|
'ht-cm-preferences={%22version%22:1%2C%22destinations%22:{%22Amplitude%22:true}%2C%22custom%22:{%22advertising%22:false%2C%22marketingAndAnalytics%22:true%2C%22functional%22:true}}'
|
|
175
|
-
window.htevents = {
|
|
175
|
+
window.htevents = {
|
|
176
|
+
load() {},
|
|
177
|
+
track() {},
|
|
178
|
+
addSourceMiddleware() {}
|
|
179
|
+
}
|
|
176
180
|
|
|
177
181
|
nock('https://cdn.hightouch-events.com')
|
|
178
182
|
.get('/v1/projects/123/integrations')
|
|
@@ -248,7 +252,6 @@ describe('ConsentManagerBuilder', () => {
|
|
|
248
252
|
'ht-cm-preferences={%22version%22:1%2C%22destinations%22:{%22Amplitude%22:true}%2C%22custom%22:{%22advertising%22:false%2C%22marketingAndAnalytics%22:false%2C%22functional%22:true}}'
|
|
249
253
|
window.htevents = {
|
|
250
254
|
load() {},
|
|
251
|
-
identify() {},
|
|
252
255
|
track() {},
|
|
253
256
|
addSourceMiddleware() {}
|
|
254
257
|
}
|
|
@@ -5,8 +5,26 @@ import {
|
|
|
5
5
|
savePreferences,
|
|
6
6
|
DEFAULT_COOKIE_NAME
|
|
7
7
|
} from '../../consent-manager-builder/preferences'
|
|
8
|
+
import { HtEventsBrowser } from '../../types'
|
|
8
9
|
|
|
9
10
|
describe('preferences', () => {
|
|
11
|
+
let htevents: sinon.SinonStubbedInstance<Pick<HtEventsBrowser, 'track'>>
|
|
12
|
+
|
|
13
|
+
function expectConsentUpdatedEvent({ destinationPreferences, customPreferences }) {
|
|
14
|
+
expect(htevents.track.calledOnce).toBe(true)
|
|
15
|
+
expect(htevents.track.args[0][0]).toBe('Consent Updated')
|
|
16
|
+
expect(htevents.track.args[0][1]).toMatchObject({
|
|
17
|
+
destinationPreferences: destinationPreferences,
|
|
18
|
+
categoryPreferences: customPreferences
|
|
19
|
+
})
|
|
20
|
+
expect(htevents.track.args[0][2]).toMatchObject({
|
|
21
|
+
consent: {
|
|
22
|
+
destinationPreferences: destinationPreferences,
|
|
23
|
+
categoryPreferences: customPreferences
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
10
28
|
beforeEach(() => {
|
|
11
29
|
window = {
|
|
12
30
|
location: {
|
|
@@ -23,6 +41,10 @@ describe('preferences', () => {
|
|
|
23
41
|
return
|
|
24
42
|
}
|
|
25
43
|
} as Document
|
|
44
|
+
document.cookie = ''
|
|
45
|
+
|
|
46
|
+
htevents = sinon.stub({ track() {} })
|
|
47
|
+
;(window as any).htevents = htevents
|
|
26
48
|
})
|
|
27
49
|
|
|
28
50
|
test('loadPreferences() returns preferences when cookie exists', () => {
|
|
@@ -53,13 +75,10 @@ describe('preferences', () => {
|
|
|
53
75
|
})
|
|
54
76
|
|
|
55
77
|
test('savePreferences() saves the preferences', () => {
|
|
56
|
-
const htevents = { identify: sinon.spy(), track: sinon.spy() }
|
|
57
|
-
;(window as any).htevents = htevents
|
|
58
|
-
document.cookie = ''
|
|
59
|
-
|
|
60
78
|
const destinationPreferences = {
|
|
61
79
|
Amplitude: true
|
|
62
80
|
}
|
|
81
|
+
|
|
63
82
|
const customPreferences = {
|
|
64
83
|
functional: true
|
|
65
84
|
}
|
|
@@ -70,87 +89,47 @@ describe('preferences', () => {
|
|
|
70
89
|
cookieDomain: undefined
|
|
71
90
|
})
|
|
72
91
|
|
|
73
|
-
|
|
74
|
-
expect(htevents.identify.args[0][0]).toMatchObject({
|
|
75
|
-
destinationTrackingPreferences: destinationPreferences,
|
|
76
|
-
categoryTrackingPreferences: customPreferences
|
|
77
|
-
})
|
|
92
|
+
expectConsentUpdatedEvent({ destinationPreferences, customPreferences })
|
|
78
93
|
|
|
79
|
-
expect(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
destinationTrackingPreferences: destinationPreferences,
|
|
83
|
-
categoryTrackingPreferences: customPreferences
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
expect(
|
|
87
|
-
document.cookie.includes(
|
|
88
|
-
`${DEFAULT_COOKIE_NAME}={%22version%22:1%2C%22destination%22:{%22Amplitude%22:true}%2C%22custom%22:{%22functional%22:true}}`
|
|
89
|
-
)
|
|
90
|
-
).toBe(true)
|
|
94
|
+
expect(document.cookie).toContain(
|
|
95
|
+
`${DEFAULT_COOKIE_NAME}={%22version%22:1%2C%22destination%22:{%22Amplitude%22:true}%2C%22custom%22:{%22functional%22:true}}`
|
|
96
|
+
)
|
|
91
97
|
})
|
|
92
98
|
|
|
93
99
|
test('savePreferences() sets the cookie domain', () => {
|
|
94
|
-
const htevents = { identify: sinon.spy(), track: sinon.spy() }
|
|
95
|
-
;(window as any).htevents = htevents
|
|
96
|
-
document.cookie = ''
|
|
97
|
-
|
|
98
100
|
const destinationPreferences = {
|
|
99
101
|
Amplitude: true
|
|
100
102
|
}
|
|
101
103
|
|
|
104
|
+
const customPreferences = undefined
|
|
105
|
+
|
|
102
106
|
savePreferences({
|
|
103
107
|
destinationPreferences,
|
|
104
|
-
customPreferences
|
|
108
|
+
customPreferences,
|
|
105
109
|
cookieDomain: 'example.com'
|
|
106
110
|
})
|
|
107
111
|
|
|
108
|
-
|
|
109
|
-
expect(htevents.identify.args[0][0]).toMatchObject({
|
|
110
|
-
destinationTrackingPreferences: destinationPreferences,
|
|
111
|
-
categoryTrackingPreferences: undefined
|
|
112
|
-
})
|
|
112
|
+
expectConsentUpdatedEvent({ destinationPreferences, customPreferences })
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
expect(htevents.track.args[0][0]).toBe('Consent Updated')
|
|
116
|
-
expect(htevents.track.args[0][1]).toMatchObject({
|
|
117
|
-
destinationTrackingPreferences: destinationPreferences,
|
|
118
|
-
categoryTrackingPreferences: undefined
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
// TODO: actually check domain
|
|
122
|
-
// expect(document.cookie.includes('domain=example.com')).toBe(true)
|
|
114
|
+
// ToDo: verify cookie domain is set (would need to mock js-cookie since document.cookie doesn't have domain info)
|
|
123
115
|
})
|
|
124
116
|
|
|
125
117
|
test('savePreferences() sets the cookie with custom key', () => {
|
|
126
|
-
const htevents = { identify: sinon.spy(), track: sinon.spy() }
|
|
127
|
-
;(window as any).htevents = htevents
|
|
128
|
-
document.cookie = ''
|
|
129
|
-
|
|
130
118
|
const destinationPreferences = {
|
|
131
119
|
Amplitude: true
|
|
132
120
|
}
|
|
133
121
|
|
|
122
|
+
const customPreferences = undefined
|
|
123
|
+
|
|
134
124
|
savePreferences({
|
|
135
125
|
destinationPreferences,
|
|
136
|
-
customPreferences
|
|
126
|
+
customPreferences,
|
|
137
127
|
cookieDomain: undefined,
|
|
138
128
|
cookieName: 'custom-tracking-preferences'
|
|
139
129
|
})
|
|
140
130
|
|
|
141
|
-
|
|
142
|
-
expect(htevents.identify.args[0][0]).toMatchObject({
|
|
143
|
-
destinationTrackingPreferences: destinationPreferences,
|
|
144
|
-
categoryTrackingPreferences: undefined
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
expect(htevents.track.calledOnce).toBe(true)
|
|
148
|
-
expect(htevents.track.args[0][0]).toBe('Consent Updated')
|
|
149
|
-
expect(htevents.track.args[0][1]).toMatchObject({
|
|
150
|
-
destinationTrackingPreferences: destinationPreferences,
|
|
151
|
-
categoryTrackingPreferences: undefined
|
|
152
|
-
})
|
|
131
|
+
expectConsentUpdatedEvent({ destinationPreferences, customPreferences })
|
|
153
132
|
|
|
154
|
-
expect(document.cookie.
|
|
133
|
+
expect(document.cookie).toContain('custom-tracking-preferences')
|
|
155
134
|
})
|
|
156
135
|
})
|
|
@@ -28,7 +28,10 @@ function getConsentMiddleware(
|
|
|
28
28
|
payload.obj.context.consent = {
|
|
29
29
|
defaultDestinationBehavior,
|
|
30
30
|
categoryPreferences,
|
|
31
|
-
destinationPreferences
|
|
31
|
+
destinationPreferences,
|
|
32
|
+
// give precedence to `context.consent` values set explicitly for the event
|
|
33
|
+
// this allows us to immediately reflect changes made to consent
|
|
34
|
+
...payload.obj.context.consent
|
|
32
35
|
}
|
|
33
36
|
next(payload)
|
|
34
37
|
}
|
|
@@ -64,17 +64,21 @@ export function savePreferences({
|
|
|
64
64
|
}: SavePreferences) {
|
|
65
65
|
const wd = window as WindowWithHtEvents
|
|
66
66
|
if (wd.htevents) {
|
|
67
|
-
wd.htevents.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
67
|
+
wd.htevents.track(
|
|
68
|
+
'Consent Updated',
|
|
69
|
+
{
|
|
70
|
+
destinationPreferences,
|
|
71
|
+
// use `categoryPreferences` here for consistency with `context.consent.categoryPreferences`
|
|
72
|
+
categoryPreferences: customPreferences
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
// update `context.consent` here to immediately reflect the updated preferences
|
|
76
|
+
consent: {
|
|
77
|
+
destinationPreferences,
|
|
78
|
+
categoryPreferences: customPreferences
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
)
|
|
78
82
|
} else {
|
|
79
83
|
console.warn('window.htevents not found...is the SDK snippet included on the page?')
|
|
80
84
|
}
|
package/src/types.ts
CHANGED
|
@@ -11,7 +11,6 @@ export type HtEventsBrowserOptions = {
|
|
|
11
11
|
export type HtEventsBrowser = {
|
|
12
12
|
initialized: boolean
|
|
13
13
|
load: (writeKey: string, options?: HtEventsBrowserOptions) => void
|
|
14
|
-
identify: (properties: Record<string, any>) => void
|
|
15
14
|
track: (event: string, properties: Record<string, any>, options?: any, callback?: any) => void
|
|
16
15
|
addSourceMiddleware: (middleware: Middleware) => void
|
|
17
16
|
}
|