@teleporthq/teleport-project-generator-next 0.45.7 → 0.45.9
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/__tests__/analytics-experiments.test.ts +45 -6
- package/__tests__/analytics-tracker-consent.test.ts +73 -4
- package/__tests__/item-comparison-project-plugin.test.ts +57 -0
- package/__tests__/static-export-project-plugin.test.ts +239 -0
- package/dist/cjs/access-rules/gate-runtime-source.d.ts +10 -1
- package/dist/cjs/access-rules/gate-runtime-source.d.ts.map +1 -1
- package/dist/cjs/access-rules/gate-runtime-source.js +20 -2
- package/dist/cjs/access-rules/gate-runtime-source.js.map +1 -1
- package/dist/cjs/analytics/experiments.d.ts +17 -8
- package/dist/cjs/analytics/experiments.d.ts.map +1 -1
- package/dist/cjs/analytics/experiments.js +30 -13
- package/dist/cjs/analytics/experiments.js.map +1 -1
- package/dist/cjs/analytics/tracker-source.d.ts +1 -1
- package/dist/cjs/analytics/tracker-source.d.ts.map +1 -1
- package/dist/cjs/analytics/tracker-source.js +1 -1
- package/dist/cjs/analytics/tracker-source.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +24 -22
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/item-comparison/compare-route.d.ts.map +1 -1
- package/dist/cjs/item-comparison/compare-route.js +1 -1
- package/dist/cjs/item-comparison/compare-route.js.map +1 -1
- package/dist/cjs/item-comparison/settings.d.ts +11 -0
- package/dist/cjs/item-comparison/settings.d.ts.map +1 -1
- package/dist/cjs/item-comparison/settings.js +15 -1
- package/dist/cjs/item-comparison/settings.js.map +1 -1
- package/dist/cjs/static-export/project-plugin.d.ts +17 -0
- package/dist/cjs/static-export/project-plugin.d.ts.map +1 -0
- package/dist/cjs/static-export/project-plugin.js +182 -0
- package/dist/cjs/static-export/project-plugin.js.map +1 -0
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/access-rules/gate-runtime-source.d.ts +10 -1
- package/dist/esm/access-rules/gate-runtime-source.d.ts.map +1 -1
- package/dist/esm/access-rules/gate-runtime-source.js +20 -2
- package/dist/esm/access-rules/gate-runtime-source.js.map +1 -1
- package/dist/esm/analytics/experiments.d.ts +17 -8
- package/dist/esm/analytics/experiments.d.ts.map +1 -1
- package/dist/esm/analytics/experiments.js +30 -13
- package/dist/esm/analytics/experiments.js.map +1 -1
- package/dist/esm/analytics/tracker-source.d.ts +1 -1
- package/dist/esm/analytics/tracker-source.d.ts.map +1 -1
- package/dist/esm/analytics/tracker-source.js +1 -1
- package/dist/esm/analytics/tracker-source.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/item-comparison/compare-route.d.ts.map +1 -1
- package/dist/esm/item-comparison/compare-route.js +1 -1
- package/dist/esm/item-comparison/compare-route.js.map +1 -1
- package/dist/esm/item-comparison/settings.d.ts +11 -0
- package/dist/esm/item-comparison/settings.d.ts.map +1 -1
- package/dist/esm/item-comparison/settings.js +15 -1
- package/dist/esm/item-comparison/settings.js.map +1 -1
- package/dist/esm/static-export/project-plugin.d.ts +17 -0
- package/dist/esm/static-export/project-plugin.d.ts.map +1 -0
- package/dist/esm/static-export/project-plugin.js +179 -0
- package/dist/esm/static-export/project-plugin.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/access-rules/gate-runtime-source.ts +69 -11
- package/src/analytics/experiments.ts +34 -13
- package/src/analytics/tracker-source.ts +34 -7
- package/src/index.ts +1 -0
- package/src/item-comparison/compare-route.ts +9 -5
- package/src/item-comparison/settings.ts +27 -0
- package/src/static-export/project-plugin.ts +137 -0
|
@@ -31,12 +31,22 @@ const uidlWith = (rootChildren: any[], componentChildren: any[] = []) =>
|
|
|
31
31
|
|
|
32
32
|
function runScript(ids: string[], storage: Record<string, string>, random = 0.2) {
|
|
33
33
|
const styles: string[] = []
|
|
34
|
+
const listeners: Record<string, Array<() => void>> = {}
|
|
34
35
|
const fakeWindow = {
|
|
35
36
|
localStorage: {
|
|
36
37
|
getItem: (key: string) => (key in storage ? storage[key] : null),
|
|
37
38
|
setItem: (key: string, value: string) => {
|
|
38
39
|
storage[key] = value
|
|
39
40
|
},
|
|
41
|
+
removeItem: (key: string) => {
|
|
42
|
+
delete storage[key]
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
addEventListener: (type: string, listener: () => void) => {
|
|
46
|
+
listeners[type] = (listeners[type] || []).concat(listener)
|
|
47
|
+
},
|
|
48
|
+
removeEventListener: (type: string, listener: () => void) => {
|
|
49
|
+
listeners[type] = (listeners[type] || []).filter((known) => known !== listener)
|
|
40
50
|
},
|
|
41
51
|
} as any
|
|
42
52
|
const fakeDocument = {
|
|
@@ -48,7 +58,13 @@ function runScript(ids: string[], storage: Record<string, string>, random = 0.2)
|
|
|
48
58
|
fakeDocument,
|
|
49
59
|
Object.assign(Object.create(Math), { random: () => random })
|
|
50
60
|
)
|
|
51
|
-
|
|
61
|
+
// What the cookie banner's Accept does: the workflow step writes the key and
|
|
62
|
+
// announces the write in this tab.
|
|
63
|
+
const accept = () => {
|
|
64
|
+
storage.cookieConsent = 'accepted'
|
|
65
|
+
;(listeners['teleport:local-storage'] || []).forEach((listener) => listener())
|
|
66
|
+
}
|
|
67
|
+
return { assigned: fakeWindow.__tpExp as Record<string, string>, styles, accept }
|
|
52
68
|
}
|
|
53
69
|
|
|
54
70
|
describe('experiments — finding them in the project', () => {
|
|
@@ -87,23 +103,45 @@ describe('experiments — finding them in the project', () => {
|
|
|
87
103
|
})
|
|
88
104
|
|
|
89
105
|
describe('experiments — the head script', () => {
|
|
90
|
-
it('flips a coin without consent,
|
|
106
|
+
it('flips a coin without consent, hides the other variant, and stores nothing on the device', () => {
|
|
91
107
|
const storage: Record<string, string> = {}
|
|
92
108
|
const first = runScript(['hero-1'], storage, 0.2)
|
|
93
109
|
expect(first.assigned).toEqual({ 'hero-1': 'a' })
|
|
94
|
-
expect(storage['tq_exp:hero-1']).toBe('a')
|
|
95
110
|
expect(first.styles).toEqual([
|
|
96
111
|
'[data-tq-exp="hero-1"][data-tq-exp-variant="b"],[data-tq-exp="hero-1"][data-tq-exp-variant="b"] *{display:none!important}',
|
|
97
112
|
])
|
|
98
|
-
|
|
99
|
-
const again = runScript(['hero-1'], storage, 0.9)
|
|
100
|
-
expect(again.assigned).toEqual({ 'hero-1': 'a' })
|
|
113
|
+
expect(storage).toEqual({})
|
|
101
114
|
|
|
102
115
|
const other = runScript(['hero-1'], {}, 0.9)
|
|
103
116
|
expect(other.assigned).toEqual({ 'hero-1': 'b' })
|
|
104
117
|
expect(other.styles[0]).toContain('[data-tq-exp-variant="a"]')
|
|
105
118
|
})
|
|
106
119
|
|
|
120
|
+
it('without consent, removes an arm an earlier build stored instead of reading it', () => {
|
|
121
|
+
const storage: Record<string, string> = { 'tq_exp:hero-1': 'b', cookieConsent: 'declined' }
|
|
122
|
+
expect(runScript(['hero-1'], storage, 0.2).assigned).toEqual({ 'hero-1': 'a' })
|
|
123
|
+
expect(storage).toEqual({ cookieConsent: 'declined' })
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('stores the arm the visitor is seeing once they accept on this page, and keeps it after', () => {
|
|
127
|
+
const storage: Record<string, string> = {}
|
|
128
|
+
const page = runScript(['hero-1'], storage, 0.9)
|
|
129
|
+
expect(page.assigned).toEqual({ 'hero-1': 'b' })
|
|
130
|
+
expect(storage['tq_exp:hero-1']).toBeUndefined()
|
|
131
|
+
|
|
132
|
+
page.accept()
|
|
133
|
+
expect(storage['tq_exp:hero-1']).toBe('b')
|
|
134
|
+
// The next page load keeps the version they saw, whatever the coin says.
|
|
135
|
+
expect(runScript(['hero-1'], storage, 0.2).assigned).toEqual({ 'hero-1': 'b' })
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('with consent, flips a coin once, stores the arm and reuses it', () => {
|
|
139
|
+
const storage: Record<string, string> = { cookieConsent: 'accepted' }
|
|
140
|
+
expect(runScript(['hero-1'], storage, 0.2).assigned).toEqual({ 'hero-1': 'a' })
|
|
141
|
+
expect(storage['tq_exp:hero-1']).toBe('a')
|
|
142
|
+
expect(runScript(['hero-1'], storage, 0.9).assigned).toEqual({ 'hero-1': 'a' })
|
|
143
|
+
})
|
|
144
|
+
|
|
107
145
|
it('derives the arm from the visitor id with consent — stable per visitor, not per site', () => {
|
|
108
146
|
const consented = { cookieConsent: 'accepted', tp_aid: 'visitor-123' }
|
|
109
147
|
const one = runScript(['hero-1', 'cta-2'], { ...consented }, 0.1)
|
|
@@ -126,6 +164,7 @@ describe('experiments — the head script', () => {
|
|
|
126
164
|
throw new Error('blocked')
|
|
127
165
|
},
|
|
128
166
|
},
|
|
167
|
+
addEventListener: () => undefined,
|
|
129
168
|
} as any
|
|
130
169
|
const fakeDocument = {
|
|
131
170
|
createElement: () => ({ textContent: '' }),
|
|
@@ -24,12 +24,14 @@ function memoryStorage() {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
function bootTracker() {
|
|
27
|
+
function bootTracker(options: { experiments?: Record<string, string> } = {}) {
|
|
28
28
|
const localStorage = memoryStorage()
|
|
29
29
|
const sessionStorage = memoryStorage()
|
|
30
30
|
const batches: Sent[][] = []
|
|
31
31
|
const heartbeats: Sent[] = []
|
|
32
32
|
const documentListeners: Record<string, () => void> = {}
|
|
33
|
+
// The A/B tests whose element is on the current page.
|
|
34
|
+
let experimentsOnPage: string[] = []
|
|
33
35
|
|
|
34
36
|
const fakeDocument = {
|
|
35
37
|
visibilityState: 'visible',
|
|
@@ -38,7 +40,8 @@ function bootTracker() {
|
|
|
38
40
|
addEventListener: (type: string, listener: () => void) => {
|
|
39
41
|
documentListeners[type] = listener
|
|
40
42
|
},
|
|
41
|
-
querySelector: () =>
|
|
43
|
+
querySelector: (selector: string) =>
|
|
44
|
+
experimentsOnPage.some((id) => selector === `[data-tq-exp="${id}"]`) ? {} : null,
|
|
42
45
|
}
|
|
43
46
|
const fakeWindow = {
|
|
44
47
|
location: { hostname: 'shop.example.com', pathname: '/', search: '' },
|
|
@@ -48,6 +51,7 @@ function bootTracker() {
|
|
|
48
51
|
innerHeight: 900,
|
|
49
52
|
scrollY: 0,
|
|
50
53
|
addEventListener: () => undefined,
|
|
54
|
+
__tpExp: options.experiments,
|
|
51
55
|
}
|
|
52
56
|
const fakeFetch = (url: string, init: { body: string }) => {
|
|
53
57
|
const payload = JSON.parse(init.body)
|
|
@@ -94,12 +98,25 @@ function bootTracker() {
|
|
|
94
98
|
fakeDocument.visibilityState = 'visible'
|
|
95
99
|
documentListeners.visibilitychange()
|
|
96
100
|
}
|
|
97
|
-
const navigate = (path: string) => {
|
|
101
|
+
const navigate = (path: string, experiments: string[] = []) => {
|
|
98
102
|
fakeWindow.location.pathname = path
|
|
103
|
+
experimentsOnPage = experiments
|
|
99
104
|
tracker.trackRouteChange(path)
|
|
100
105
|
}
|
|
106
|
+
const showExperiments = (experiments: string[]) => {
|
|
107
|
+
experimentsOnPage = experiments
|
|
108
|
+
}
|
|
101
109
|
|
|
102
|
-
return {
|
|
110
|
+
return {
|
|
111
|
+
tracker,
|
|
112
|
+
localStorage,
|
|
113
|
+
sessionStorage,
|
|
114
|
+
heartbeats,
|
|
115
|
+
flush,
|
|
116
|
+
show,
|
|
117
|
+
navigate,
|
|
118
|
+
showExperiments,
|
|
119
|
+
}
|
|
103
120
|
}
|
|
104
121
|
|
|
105
122
|
describe('tracker — consent given or withdrawn mid-visit', () => {
|
|
@@ -163,3 +180,55 @@ describe('tracker — consent given or withdrawn mid-visit', () => {
|
|
|
163
180
|
expect(next.sessionId).not.toBe(landing.sessionId)
|
|
164
181
|
})
|
|
165
182
|
})
|
|
183
|
+
|
|
184
|
+
describe('tracker — the A/B test versions a visitor has seen', () => {
|
|
185
|
+
const SEEN_KEY = 'tq_exp_seen'
|
|
186
|
+
|
|
187
|
+
it('keeps them in memory until the banner is accepted, then stores them', () => {
|
|
188
|
+
const page = bootTracker({ experiments: { 'hero-1': 'b' } })
|
|
189
|
+
page.showExperiments(['hero-1'])
|
|
190
|
+
page.tracker.initTeleportAnalytics({})
|
|
191
|
+
const [landing] = page.flush()
|
|
192
|
+
|
|
193
|
+
expect(landing.exp).toBe('hero-1:b')
|
|
194
|
+
expect(page.localStorage.getItem(SEEN_KEY)).toBeNull()
|
|
195
|
+
|
|
196
|
+
// A page without the test still counts for the version that led there.
|
|
197
|
+
page.navigate('/checkout')
|
|
198
|
+
const [checkout] = page.flush()
|
|
199
|
+
expect(checkout.exp).toBe('hero-1:b')
|
|
200
|
+
expect(page.localStorage.getItem(SEEN_KEY)).toBeNull()
|
|
201
|
+
|
|
202
|
+
page.localStorage.setItem('cookieConsent', 'accepted')
|
|
203
|
+
page.navigate('/thanks')
|
|
204
|
+
const [thanks] = page.flush()
|
|
205
|
+
expect(thanks.exp).toBe('hero-1:b')
|
|
206
|
+
expect(JSON.parse(page.localStorage.getItem(SEEN_KEY) as string)).toEqual({ 'hero-1': 'b' })
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
it('removes the versions an earlier build stored for a visitor who has not accepted', () => {
|
|
210
|
+
const page = bootTracker({ experiments: { 'hero-1': 'a' } })
|
|
211
|
+
page.localStorage.setItem(SEEN_KEY, JSON.stringify({ 'cta-2': 'b' }))
|
|
212
|
+
page.showExperiments(['hero-1'])
|
|
213
|
+
page.tracker.initTeleportAnalytics({})
|
|
214
|
+
const [landing] = page.flush()
|
|
215
|
+
|
|
216
|
+
expect(landing.exp).toBe('hero-1:a')
|
|
217
|
+
expect(page.localStorage.getItem(SEEN_KEY)).toBeNull()
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
it('reads and stores them as before for a visitor who accepted earlier', () => {
|
|
221
|
+
const page = bootTracker({ experiments: { 'hero-1': 'a', 'cta-2': 'b' } })
|
|
222
|
+
page.localStorage.setItem('cookieConsent', 'accepted')
|
|
223
|
+
page.localStorage.setItem(SEEN_KEY, JSON.stringify({ 'cta-2': 'b' }))
|
|
224
|
+
page.showExperiments(['hero-1'])
|
|
225
|
+
page.tracker.initTeleportAnalytics({})
|
|
226
|
+
const [landing] = page.flush()
|
|
227
|
+
|
|
228
|
+
expect(landing.exp).toBe('hero-1:a,cta-2:b')
|
|
229
|
+
expect(JSON.parse(page.localStorage.getItem(SEEN_KEY) as string)).toEqual({
|
|
230
|
+
'hero-1': 'a',
|
|
231
|
+
'cta-2': 'b',
|
|
232
|
+
})
|
|
233
|
+
})
|
|
234
|
+
})
|
|
@@ -371,4 +371,61 @@ describe('NextItemComparisonProjectPlugin', () => {
|
|
|
371
371
|
expect(priceCell({ price: 5 }).text).toBe('5.00')
|
|
372
372
|
})
|
|
373
373
|
})
|
|
374
|
+
|
|
375
|
+
describe('a bookable item’s price', () => {
|
|
376
|
+
// A `teleport_booking_items` row: a price, no currency column.
|
|
377
|
+
const ROOM = { price: '80.00' }
|
|
378
|
+
|
|
379
|
+
const bookingRouteWith = async (data?: Record<string, unknown>) => {
|
|
380
|
+
const structure = makeStructure(
|
|
381
|
+
{ settings: { kinds: ['products', 'bookingItems'] }, ...(data ? { data } : {}) },
|
|
382
|
+
{ store: true, bookings: true }
|
|
383
|
+
)
|
|
384
|
+
await new NextItemComparisonProjectPlugin().runAfter(structure)
|
|
385
|
+
return routeCells(structure.files.get('item-comparison-route').files[0].content as string)
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
it('is quoted in the bookings’ currency, the way the editor’s comparison prints it', async () => {
|
|
389
|
+
const { cell } = await bookingRouteWith({
|
|
390
|
+
priceSymbolSide: 'before',
|
|
391
|
+
bookingPrice: { symbol: '€', side: 'before' },
|
|
392
|
+
})
|
|
393
|
+
expect(cell('bookingItems', 'price', ROOM)).toEqual({ text: '€ 80.00', number: 80 })
|
|
394
|
+
})
|
|
395
|
+
|
|
396
|
+
it('writes the symbol on the side the editor says for the bookings’ currency', async () => {
|
|
397
|
+
const { cell } = await bookingRouteWith({ bookingPrice: { symbol: 'lei', side: 'after' } })
|
|
398
|
+
expect(cell('bookingItems', 'price', ROOM)).toEqual({ text: '80.00 lei', number: 80 })
|
|
399
|
+
})
|
|
400
|
+
|
|
401
|
+
it('leaves a product’s price exactly as before', async () => {
|
|
402
|
+
const { cell } = await bookingRouteWith({
|
|
403
|
+
priceSymbolSide: 'before',
|
|
404
|
+
bookingPrice: { symbol: 'lei', side: 'after' },
|
|
405
|
+
})
|
|
406
|
+
expect(cell('products', 'price', FLAT_PRODUCT)).toEqual({ text: 'lei 149.00', number: 149 })
|
|
407
|
+
expect(cell('products', 'price', { price: 5 })).toEqual({ text: '5.00', number: 5 })
|
|
408
|
+
})
|
|
409
|
+
|
|
410
|
+
it('stays a bare amount for a project exported before the editor sent the currency', async () => {
|
|
411
|
+
const { cell } = await bookingRouteWith({ priceSymbolSide: 'before' })
|
|
412
|
+
expect(cell('bookingItems', 'price', ROOM)).toEqual({ text: '80.00', number: 80 })
|
|
413
|
+
})
|
|
414
|
+
|
|
415
|
+
it('ignores a currency the editor did not send in a usable shape', () => {
|
|
416
|
+
const config = (bookingPrice: unknown) =>
|
|
417
|
+
resolveItemComparisonConfig(
|
|
418
|
+
makeStructure(
|
|
419
|
+
{ settings: { kinds: ['bookingItems'] }, data: { bookingPrice } },
|
|
420
|
+
{ bookings: true }
|
|
421
|
+
).uidl
|
|
422
|
+
)!.bookingPrice
|
|
423
|
+
expect(config({ symbol: ' € ', side: 'after' })).toEqual({ symbol: '€', side: 'after' })
|
|
424
|
+
expect(config({ symbol: '€', side: 'sideways' })).toEqual({ symbol: '€', side: 'before' })
|
|
425
|
+
expect(config({ symbol: '' })).toBeNull()
|
|
426
|
+
expect(config({ symbol: 'A'.repeat(11) })).toBeNull()
|
|
427
|
+
expect(config('EUR')).toBeNull()
|
|
428
|
+
expect(config(undefined)).toBeNull()
|
|
429
|
+
})
|
|
430
|
+
})
|
|
374
431
|
})
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { ProjectPluginStructure } from '@teleporthq/teleport-types'
|
|
2
|
+
import { buildGateHeadSnippet } from '../src/access-rules/gate-runtime-source'
|
|
3
|
+
import { AccessRulesSettings } from '../src/access-rules/settings'
|
|
4
|
+
import { StaticExportProjectPlugin } from '../src/static-export/project-plugin'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A download other than the Next.js app runs no workflows: its age gate is
|
|
8
|
+
* driven by the gate's head snippet alone (the style hides it, the snippet
|
|
9
|
+
* answers its controls by their marks), and its popups are left out.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const SETTINGS: AccessRulesSettings = {
|
|
13
|
+
ageGateEnabled: true,
|
|
14
|
+
minimumAge: 18,
|
|
15
|
+
ageGateMode: 'confirm',
|
|
16
|
+
ageGateScope: 'site',
|
|
17
|
+
rememberDays: 30,
|
|
18
|
+
allowCrawlers: true,
|
|
19
|
+
geoMode: 'off',
|
|
20
|
+
geoCountries: [],
|
|
21
|
+
geoUnknownCountry: 'allow',
|
|
22
|
+
}
|
|
23
|
+
const RUNTIME = { gatedPaths: [] as string[], unavailablePaths: ['/unavailable'] }
|
|
24
|
+
|
|
25
|
+
/** A control the visitor clicks: itself for the marks it carries, the gate around it. */
|
|
26
|
+
const control = (marks: string[], gate: unknown) => {
|
|
27
|
+
const element = {
|
|
28
|
+
closest: (selector: string): unknown =>
|
|
29
|
+
selector === '[data-tq-age-gate]'
|
|
30
|
+
? gate
|
|
31
|
+
: marks.some((mark) => selector === `[${mark}]`)
|
|
32
|
+
? element
|
|
33
|
+
: null,
|
|
34
|
+
}
|
|
35
|
+
return element
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function openPage(pathname: string, settings = SETTINGS, runtime = RUNTIME) {
|
|
39
|
+
const attributes: Record<string, string> = {}
|
|
40
|
+
let click: (event: { target: unknown }) => void = () => undefined
|
|
41
|
+
const fakeDocument = {
|
|
42
|
+
cookie: '',
|
|
43
|
+
readyState: 'complete',
|
|
44
|
+
documentElement: {
|
|
45
|
+
setAttribute: (name: string, value: string) => {
|
|
46
|
+
attributes[name] = value
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
head: { appendChild: () => undefined },
|
|
50
|
+
body: { querySelector: () => ({}) },
|
|
51
|
+
querySelector: () => null,
|
|
52
|
+
createElement: () => ({ setAttribute: () => undefined }),
|
|
53
|
+
addEventListener: (type: string, listener: (event: { target: unknown }) => void) => {
|
|
54
|
+
if (type === 'click') {
|
|
55
|
+
click = listener
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
const told: string[] = []
|
|
60
|
+
const fakeWindow = {
|
|
61
|
+
addEventListener: () => undefined,
|
|
62
|
+
dispatchEvent: (event: { type: string }) => told.push(event.type),
|
|
63
|
+
}
|
|
64
|
+
const snippet = buildGateHeadSnippet(settings, runtime, { withoutWorkflows: true })
|
|
65
|
+
const script = snippet.slice(snippet.indexOf('<script>') + 8, snippet.lastIndexOf('</script>'))
|
|
66
|
+
new Function('window', 'document', 'location', 'history', 'CustomEvent', script)(
|
|
67
|
+
fakeWindow,
|
|
68
|
+
fakeDocument,
|
|
69
|
+
{ pathname, protocol: 'https:' },
|
|
70
|
+
{ pushState: () => undefined, replaceState: () => undefined },
|
|
71
|
+
function CustomEvent(this: { type: string }, type: string) {
|
|
72
|
+
this.type = type
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
return {
|
|
76
|
+
gate: () => attributes['data-tq-age-gate'],
|
|
77
|
+
cookie: () => fakeDocument.cookie,
|
|
78
|
+
click: (target: unknown) => click({ target }),
|
|
79
|
+
told,
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
describe('the age gate in a download that runs no workflows', () => {
|
|
84
|
+
it('lets the visitor in when they press the confirm button, and remembers it', () => {
|
|
85
|
+
const page = openPage('/index.html')
|
|
86
|
+
expect(page.gate()).toBe('open')
|
|
87
|
+
|
|
88
|
+
page.click(control(['data-tq-age-gate-confirm'], null))
|
|
89
|
+
expect(page.gate()).toBe('hidden')
|
|
90
|
+
expect(page.cookie()).toBe('tq_age_ok=18; Path=/; SameSite=Lax; Max-Age=2592000; Secure')
|
|
91
|
+
// Nothing waits for a component that listens for no event here.
|
|
92
|
+
expect(page.told).toEqual([])
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('checks a date of birth: an adult goes in, a minor is shown the gate’s error', () => {
|
|
96
|
+
const removed: string[] = []
|
|
97
|
+
const birthGate = (value: string) => ({
|
|
98
|
+
querySelector: (selector: string) =>
|
|
99
|
+
selector === '[data-tq-age-gate-birthdate]'
|
|
100
|
+
? { value }
|
|
101
|
+
: selector === '[data-tq-age-gate-error]'
|
|
102
|
+
? { removeAttribute: (name: string) => removed.push(name) }
|
|
103
|
+
: null,
|
|
104
|
+
})
|
|
105
|
+
const page = openPage('/', { ...SETTINGS, ageGateMode: 'birthdate' })
|
|
106
|
+
|
|
107
|
+
page.click(control(['data-tq-age-gate-submit'], birthGate('2020-05-01')))
|
|
108
|
+
expect(page.gate()).toBe('open')
|
|
109
|
+
expect(removed).toEqual(['hidden'])
|
|
110
|
+
|
|
111
|
+
page.click(control(['data-tq-age-gate-submit'], birthGate('1990-05-01')))
|
|
112
|
+
expect(page.gate()).toBe('hidden')
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('reads an HTML page’s file name as its path', () => {
|
|
116
|
+
const scoped = { ...SETTINGS, ageGateScope: 'pages' as const }
|
|
117
|
+
const shop = { ...RUNTIME, gatedPaths: ['/shop'] }
|
|
118
|
+
expect(openPage('/shop.html', scoped, shop).gate()).toBe('open')
|
|
119
|
+
expect(openPage('/index.html', scoped, shop).gate()).toBe('hidden')
|
|
120
|
+
expect(openPage('/unavailable.html').gate()).toBe('hidden')
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('leaves the published site’s script exactly as it was', () => {
|
|
124
|
+
const published = buildGateHeadSnippet(SETTINGS, RUNTIME)
|
|
125
|
+
expect(published).toBe(buildGateHeadSnippet(SETTINGS, RUNTIME, { withoutWorkflows: false }))
|
|
126
|
+
expect(published).not.toContain('data-tq-age-gate-confirm')
|
|
127
|
+
expect(published).not.toContain('.html')
|
|
128
|
+
expect(published).toContain('if (++tries < 40) setTimeout(tick, 250);')
|
|
129
|
+
})
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
describe('StaticExportProjectPlugin', () => {
|
|
133
|
+
const s = (content: unknown) => ({ type: 'static', content })
|
|
134
|
+
const instance = (name: string) => ({
|
|
135
|
+
type: 'element',
|
|
136
|
+
content: { elementType: 'component', semanticType: name, dependency: { type: 'local' } },
|
|
137
|
+
})
|
|
138
|
+
const structureWith = (extra: Record<string, unknown>) =>
|
|
139
|
+
({
|
|
140
|
+
uidl: {
|
|
141
|
+
name: 'p',
|
|
142
|
+
globals: { settings: { title: 'P', language: 'en' }, assets: [] },
|
|
143
|
+
root: {
|
|
144
|
+
name: 'App',
|
|
145
|
+
node: {
|
|
146
|
+
type: 'element',
|
|
147
|
+
content: {
|
|
148
|
+
elementType: 'container',
|
|
149
|
+
children: [
|
|
150
|
+
instance('Hero'),
|
|
151
|
+
instance('WelcomePopup'),
|
|
152
|
+
{
|
|
153
|
+
type: 'conditional',
|
|
154
|
+
content: {
|
|
155
|
+
node: instance('WelcomePopup'),
|
|
156
|
+
reference: { type: 'dynamic', content: { referenceType: 'state', id: 'x' } },
|
|
157
|
+
value: true,
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
{ type: 'element', content: { elementType: 'text', children: [s('Hi')] } },
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
components: {
|
|
166
|
+
WelcomePopup: {
|
|
167
|
+
name: 'WelcomePopup',
|
|
168
|
+
node: { type: 'element', content: { elementType: 'container', children: [] } },
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
...extra,
|
|
172
|
+
},
|
|
173
|
+
files: new Map(),
|
|
174
|
+
dependencies: {},
|
|
175
|
+
devDependencies: {},
|
|
176
|
+
template: { files: [], subFolders: [] },
|
|
177
|
+
} as unknown as ProjectPluginStructure)
|
|
178
|
+
|
|
179
|
+
it('leaves out the popups and keeps everything else', async () => {
|
|
180
|
+
const structure = structureWith({
|
|
181
|
+
popups: { popups: [{ id: 'p1', componentName: 'WelcomePopup' }], excludedPaths: [] },
|
|
182
|
+
})
|
|
183
|
+
await new StaticExportProjectPlugin().runBefore(structure)
|
|
184
|
+
const children = (structure.uidl.root.node.content as { children: unknown[] }).children
|
|
185
|
+
expect(children).toEqual([
|
|
186
|
+
instance('Hero'),
|
|
187
|
+
{ type: 'element', content: { elementType: 'text', children: [s('Hi')] } },
|
|
188
|
+
])
|
|
189
|
+
expect(structure.uidl.globals.customCode).toBeUndefined()
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
it('puts the gate’s snippet for downloads first in the head', async () => {
|
|
193
|
+
const structure = structureWith({
|
|
194
|
+
plugins: {
|
|
195
|
+
accessRules: {
|
|
196
|
+
settings: { ageGateEnabled: true },
|
|
197
|
+
data: { gate: 'component', gatedPaths: [] },
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
})
|
|
201
|
+
structure.uidl.globals.customCode = { head: '<meta name="x">' }
|
|
202
|
+
await new StaticExportProjectPlugin().runBefore(structure)
|
|
203
|
+
const head = structure.uidl.globals.customCode.head
|
|
204
|
+
expect(head.startsWith('<style>html[data-tq-age-gate="hidden"]')).toBe(true)
|
|
205
|
+
expect(head).toContain('"confirm":"data-tq-age-gate-confirm"')
|
|
206
|
+
expect(head.endsWith('<meta name="x">')).toBe(true)
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
it('keeps an A/B test’s original and leaves out its variation', async () => {
|
|
210
|
+
const version = (id: string, variant: string, label: string) => ({
|
|
211
|
+
type: 'element',
|
|
212
|
+
content: {
|
|
213
|
+
elementType: 'container',
|
|
214
|
+
attrs: { 'data-tq-exp': s(id), 'data-tq-exp-variant': s(variant) },
|
|
215
|
+
children: [s(label)],
|
|
216
|
+
},
|
|
217
|
+
})
|
|
218
|
+
const structure = structureWith({})
|
|
219
|
+
const page = structure.uidl.root.node.content as { children: unknown[] }
|
|
220
|
+
page.children = [
|
|
221
|
+
version('hero-1', 'a', 'Original'),
|
|
222
|
+
version('hero-1', 'b', 'Variation'),
|
|
223
|
+
// Not an id the generator acts on: left as it is.
|
|
224
|
+
version('NOT AN ID', 'b', 'Unmarked'),
|
|
225
|
+
]
|
|
226
|
+
await new StaticExportProjectPlugin().runBefore(structure)
|
|
227
|
+
expect(page.children).toEqual([
|
|
228
|
+
version('hero-1', 'a', 'Original'),
|
|
229
|
+
version('NOT AN ID', 'b', 'Unmarked'),
|
|
230
|
+
])
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
it('changes nothing in a project with none of them', async () => {
|
|
234
|
+
const structure = structureWith({})
|
|
235
|
+
const before = JSON.stringify(structure.uidl)
|
|
236
|
+
await new StaticExportProjectPlugin().runBefore(structure)
|
|
237
|
+
expect(JSON.stringify(structure.uidl)).toBe(before)
|
|
238
|
+
})
|
|
239
|
+
})
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { AccessRulesSettings } from './settings';
|
|
2
|
+
export interface GateHeadSnippetOptions {
|
|
3
|
+
/**
|
|
4
|
+
* For a download that runs none of the project's workflows (HTML, React,
|
|
5
|
+
* Vue, Nuxt, Angular): the snippet answers the gate's controls itself, by
|
|
6
|
+
* their marks, and the style alone hides the gate — nothing tells the
|
|
7
|
+
* component to close. A page's `.html` is read as its path.
|
|
8
|
+
*/
|
|
9
|
+
withoutWorkflows?: boolean;
|
|
10
|
+
}
|
|
2
11
|
/**
|
|
3
12
|
* The age gate's head snippet, for a project whose gate is the editor's Age
|
|
4
13
|
* Gate component: drawn open on every published page, so a visitor who must
|
|
@@ -18,5 +27,5 @@ import { AccessRulesSettings } from './settings';
|
|
|
18
27
|
export declare const buildGateHeadSnippet: (settings: AccessRulesSettings, runtime: {
|
|
19
28
|
gatedPaths: string[];
|
|
20
29
|
unavailablePaths: string[];
|
|
21
|
-
}) => string;
|
|
30
|
+
}, options?: GateHeadSnippetOptions) => string;
|
|
22
31
|
//# sourceMappingURL=gate-runtime-source.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gate-runtime-source.d.ts","sourceRoot":"","sources":["../../../src/access-rules/gate-runtime-source.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"gate-runtime-source.d.ts","sourceRoot":"","sources":["../../../src/access-rules/gate-runtime-source.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAqBhD,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,oBAAoB,aACrB,mBAAmB,WACpB;IAAE,UAAU,EAAE,MAAM,EAAE,CAAC;IAAC,gBAAgB,EAAE,MAAM,EAAE,CAAA;CAAE,YACpD,sBAAsB,KAC9B,MA0KF,CAAA"}
|
|
@@ -12,6 +12,13 @@ var EVENTS = {
|
|
|
12
12
|
open: 'tq-age-gate-open',
|
|
13
13
|
tooYoung: 'tq-age-gate-too-young',
|
|
14
14
|
};
|
|
15
|
+
/** The editor's marks on the gate's own controls (`access-rules-markers.ts` there). */
|
|
16
|
+
var CONTROLS = {
|
|
17
|
+
confirm: 'data-tq-age-gate-confirm',
|
|
18
|
+
birthdate: 'data-tq-age-gate-birthdate',
|
|
19
|
+
submit: 'data-tq-age-gate-submit',
|
|
20
|
+
error: 'data-tq-age-gate-error',
|
|
21
|
+
};
|
|
15
22
|
/**
|
|
16
23
|
* The age gate's head snippet, for a project whose gate is the editor's Age
|
|
17
24
|
* Gate component: drawn open on every published page, so a visitor who must
|
|
@@ -28,7 +35,18 @@ var EVENTS = {
|
|
|
28
35
|
*
|
|
29
36
|
* ⛔ Shipped inside a `<script>` in the head: no closing-tag sequence in it.
|
|
30
37
|
*/
|
|
31
|
-
var buildGateHeadSnippet = function (settings, runtime) {
|
|
38
|
+
var buildGateHeadSnippet = function (settings, runtime, options) {
|
|
39
|
+
if (options === void 0) { options = {}; }
|
|
40
|
+
var _a = options.withoutWorkflows, withoutWorkflows = _a === void 0 ? false : _a;
|
|
41
|
+
var staticPath = withoutWorkflows
|
|
42
|
+
? "\n p = p.replace(/\\/index\\.html$/, '/').replace(/\\.html$/, '');"
|
|
43
|
+
: '';
|
|
44
|
+
var settleBody = withoutWorkflows
|
|
45
|
+
? "\n return;"
|
|
46
|
+
: "\n var tries = 0;\n (function tick() {\n var shown = !!(document.body && document.body.querySelector(ROOT));\n if (shown === open) return;\n tell(open ? EVENTS.open : EVENTS.close);\n if (++tries < 40) setTimeout(tick, 250);\n })();";
|
|
47
|
+
var controls = withoutWorkflows
|
|
48
|
+
? "\n // No workflow runs here: the gate's own controls are answered by their marks.\n var CONTROLS = ".concat((0, source_literals_1.toJsLiteral)(CONTROLS), ";\n function control(event, mark) {\n var target = event.target;\n return target && target.closest ? target.closest('[' + mark + ']') : null;\n }\n document.addEventListener('click', function (event) {\n if (control(event, CONTROLS.confirm)) {\n confirmed();\n return;\n }\n var submit = control(event, CONTROLS.submit);\n if (!submit) return;\n var gate = submit.closest(ROOT) || document;\n var field = gate.querySelector('[' + CONTROLS.birthdate + ']');\n var text = field && typeof field.value === 'string' ? field.value : '';\n if (!text) {\n if (field && field.reportValidity) field.reportValidity();\n return;\n }\n if (years(text) >= S.minimumAge) {\n confirmed();\n return;\n }\n var error = gate.querySelector('[' + CONTROLS.error + ']');\n if (error) error.removeAttribute('hidden');\n });")
|
|
49
|
+
: '';
|
|
32
50
|
var client = {
|
|
33
51
|
enabled: settings.ageGateEnabled,
|
|
34
52
|
minimumAge: settings.minimumAge,
|
|
@@ -40,7 +58,7 @@ var buildGateHeadSnippet = function (settings, runtime) {
|
|
|
40
58
|
noindex: !settings.allowCrawlers,
|
|
41
59
|
};
|
|
42
60
|
var style = "html[".concat(ROOT_ATTR, "=\"hidden\"] [").concat(ROOT_ATTR, "]{display:none!important}html[").concat(ROOT_ATTR, "=\"open\"]{overflow:hidden}");
|
|
43
|
-
var script = "(function () {\n var S = ".concat((0, source_literals_1.toJsLiteral)(client), ";\n var COOKIE = ").concat((0, source_literals_1.toJsLiteral)(constants_1.AGE_COOKIE), ";\n var ATTR = ").concat((0, source_literals_1.toJsLiteral)(ROOT_ATTR), ";\n var ROOT = '[' + ATTR + ']';\n var PREFIX = 'workflow:custom:';\n var EVENTS = ").concat((0, source_literals_1.toJsLiteral)(EVENTS), ";\n var html = document.documentElement;\n function cookie() {\n var parts = document.cookie ? document.cookie.split('; ') : [];\n for (var i = 0; i < parts.length; i++) {\n var eq = parts[i].indexOf('=');\n if (eq > 0 && parts[i].slice(0, eq) === COOKIE) {\n try { return decodeURIComponent(parts[i].slice(eq + 1)); } catch (e) { return ''; }\n }\n }\n return '';\n }\n function remember() {\n var value = COOKIE + '=' + encodeURIComponent(String(S.minimumAge)) + '; Path=/; SameSite=Lax';\n if (S.rememberSeconds > 0) value += '; Max-Age=' + S.rememberSeconds;\n if (location.protocol === 'https:') value += '; Secure';\n document.cookie = value;\n }\n function path() {\n var p = location.pathname
|
|
61
|
+
var script = "(function () {\n var S = ".concat((0, source_literals_1.toJsLiteral)(client), ";\n var COOKIE = ").concat((0, source_literals_1.toJsLiteral)(constants_1.AGE_COOKIE), ";\n var ATTR = ").concat((0, source_literals_1.toJsLiteral)(ROOT_ATTR), ";\n var ROOT = '[' + ATTR + ']';\n var PREFIX = 'workflow:custom:';\n var EVENTS = ").concat((0, source_literals_1.toJsLiteral)(EVENTS), ";\n var html = document.documentElement;\n function cookie() {\n var parts = document.cookie ? document.cookie.split('; ') : [];\n for (var i = 0; i < parts.length; i++) {\n var eq = parts[i].indexOf('=');\n if (eq > 0 && parts[i].slice(0, eq) === COOKIE) {\n try { return decodeURIComponent(parts[i].slice(eq + 1)); } catch (e) { return ''; }\n }\n }\n return '';\n }\n function remember() {\n var value = COOKIE + '=' + encodeURIComponent(String(S.minimumAge)) + '; Path=/; SameSite=Lax';\n if (S.rememberSeconds > 0) value += '; Max-Age=' + S.rememberSeconds;\n if (location.protocol === 'https:') value += '; Secure';\n document.cookie = value;\n }\n function path() {\n var p = location.pathname;").concat(staticPath, "\n return p.length > 1 ? p.replace(/\\/+$/, '').toLowerCase() : p;\n }\n function matches(p, patterns) {\n for (var i = 0; i < patterns.length; i++) {\n var pattern = patterns[i];\n if (pattern.slice(-2) === '/*') {\n var base = pattern.slice(0, -2) || '/';\n if (p === base || p.indexOf(base === '/' ? '/' : base + '/') === 0) return true;\n } else if (pattern.slice(-1) === '*') {\n if (p.indexOf(pattern.slice(0, -1)) === 0) return true;\n } else if (p === pattern) {\n return true;\n }\n }\n return false;\n }\n function gated(p) {\n if (!S.enabled || matches(p, S.ungated)) return false;\n return S.scope !== 'pages' || matches(p, S.pages);\n }\n function wanted() {\n return gated(path()) && cookie() !== String(S.minimumAge);\n }\n function tell(name, detail) {\n try {\n window.dispatchEvent(new CustomEvent(PREFIX + name, { detail: detail || {} }));\n } catch (e) {}\n }\n // The component answers only once hydrated: ask until the gate matches.\n // Looked for inside the body: <html> carries the same attribute as its mark.\n function settle(open) {").concat(settleBody, "\n }\n function noindex() {\n if (!S.noindex || !gated(path()) || document.querySelector('meta[name=\"robots\"][' + ATTR + ']')) return;\n var meta = document.createElement('meta');\n meta.name = 'robots';\n meta.content = 'noindex, nofollow';\n meta.setAttribute(ATTR, '');\n document.head.appendChild(meta);\n }\n function apply() {\n var open = wanted();\n html.setAttribute(ATTR, open ? 'open' : 'hidden');\n settle(open);\n noindex();\n }\n function confirmed() {\n remember();\n html.setAttribute(ATTR, 'hidden');\n settle(false);\n }\n function years(text) {\n var birth = new Date(text + 'T00:00:00');\n if (isNaN(birth.getTime())) return -1;\n var now = new Date();\n var age = now.getFullYear() - birth.getFullYear();\n var early = now.getMonth() < birth.getMonth() || (now.getMonth() === birth.getMonth() && now.getDate() < birth.getDate());\n return early ? age - 1 : age;\n }\n window.addEventListener(PREFIX + EVENTS.confirm, confirmed);\n window.addEventListener(PREFIX + EVENTS.birthdate, function (event) {\n var detail = event && event.detail;\n var text = typeof detail === 'string' ? detail : detail && typeof detail.value === 'string' ? detail.value : '';\n if (!text) return;\n if (years(text) >= S.minimumAge) confirmed();\n else tell(EVENTS.tooYoung);\n });").concat(controls, "\n html.setAttribute(ATTR, wanted() ? 'open' : 'hidden');\n function onRoute() {\n setTimeout(apply, 0);\n }\n var push = history.pushState;\n var replace = history.replaceState;\n history.pushState = function () {\n push.apply(this, arguments);\n onRoute();\n };\n history.replaceState = function () {\n replace.apply(this, arguments);\n onRoute();\n };\n window.addEventListener('popstate', onRoute);\n if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', apply);\n else apply();\n})();");
|
|
44
62
|
return "<style>".concat(style, "</style><script>").concat(script, "</script>");
|
|
45
63
|
};
|
|
46
64
|
exports.buildGateHeadSnippet = buildGateHeadSnippet;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gate-runtime-source.js","sourceRoot":"","sources":["../../../src/access-rules/gate-runtime-source.ts"],"names":[],"mappings":";;;AAAA,0DAAoD;AAEpD,yCAAwC;AAExC,2GAA2G;AAC3G,IAAM,SAAS,GAAG,kBAAkB,CAAA;AACpC,IAAM,MAAM,GAAG;IACb,OAAO,EAAE,qBAAqB;IAC9B,SAAS,EAAE,uBAAuB;IAClC,KAAK,EAAE,mBAAmB;IAC1B,IAAI,EAAE,kBAAkB;IACxB,QAAQ,EAAE,uBAAuB;CAClC,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACI,IAAM,oBAAoB,GAAG,UAClC,QAA6B,EAC7B,OAA6D;
|
|
1
|
+
{"version":3,"file":"gate-runtime-source.js","sourceRoot":"","sources":["../../../src/access-rules/gate-runtime-source.ts"],"names":[],"mappings":";;;AAAA,0DAAoD;AAEpD,yCAAwC;AAExC,2GAA2G;AAC3G,IAAM,SAAS,GAAG,kBAAkB,CAAA;AACpC,IAAM,MAAM,GAAG;IACb,OAAO,EAAE,qBAAqB;IAC9B,SAAS,EAAE,uBAAuB;IAClC,KAAK,EAAE,mBAAmB;IAC1B,IAAI,EAAE,kBAAkB;IACxB,QAAQ,EAAE,uBAAuB;CAClC,CAAA;AAED,uFAAuF;AACvF,IAAM,QAAQ,GAAG;IACf,OAAO,EAAE,0BAA0B;IACnC,SAAS,EAAE,4BAA4B;IACvC,MAAM,EAAE,yBAAyB;IACjC,KAAK,EAAE,wBAAwB;CAChC,CAAA;AAYD;;;;;;;;;;;;;;;GAeG;AACI,IAAM,oBAAoB,GAAG,UAClC,QAA6B,EAC7B,OAA6D,EAC7D,OAAoC;IAApC,wBAAA,EAAA,YAAoC;IAE5B,IAAA,KAA6B,OAAO,iBAAZ,EAAxB,gBAAgB,mBAAG,KAAK,KAAA,CAAY;IAC5C,IAAM,UAAU,GAAG,gBAAgB;QACjC,CAAC,CAAC,uEAC8D;QAChE,CAAC,CAAC,EAAE,CAAA;IACN,IAAM,UAAU,GAAG,gBAAgB;QACjC,CAAC,CAAC,eACM;QACR,CAAC,CAAC,uQAOI,CAAA;IACR,IAAM,QAAQ,GAAG,gBAAgB;QAC/B,CAAC,CAAC,+GAEa,IAAA,6BAAW,EAAC,QAAQ,CAAC,o3BAyBlC;QACF,CAAC,CAAC,EAAE,CAAA;IACN,IAAM,MAAM,GAAG;QACb,OAAO,EAAE,QAAQ,CAAC,cAAc;QAChC,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,KAAK,EAAE,QAAQ,CAAC,YAAY;QAC5B,KAAK,EAAE,OAAO,CAAC,UAAU;QACzB,sHAAsH;QACtH,OAAO,EAAE,OAAO,CAAC,gBAAgB;QACjC,eAAe,EAAE,QAAQ,CAAC,YAAY,GAAG,KAAK;QAC9C,OAAO,EAAE,CAAC,QAAQ,CAAC,aAAa;KACjC,CAAA;IACD,IAAM,KAAK,GAAG,eAAQ,SAAS,2BAAe,SAAS,2CAAiC,SAAS,gCAA2B,CAAA;IAC5H,IAAM,MAAM,GAAG,oCACL,IAAA,6BAAW,EAAC,MAAM,CAAC,+BACd,IAAA,6BAAW,EAAC,sBAAU,CAAC,6BACzB,IAAA,6BAAW,EAAC,SAAS,CAAC,mGAGpB,IAAA,6BAAW,EAAC,MAAM,CAAC,iwBAmBJ,UAAU,kpCA+Bf,UAAU,k2CAoC9B,QAAQ,wiBAkBT,CAAA;IACJ,OAAO,iBAAU,KAAK,6BAAmB,MAAM,cAAW,CAAA;AAC5D,CAAC,CAAA;AA9KY,QAAA,oBAAoB,wBA8KhC"}
|
|
@@ -13,10 +13,16 @@ import { ProjectPluginStructure } from '@teleporthq/teleport-types';
|
|
|
13
13
|
* style rule, so there is no flash of two heroes. The rule also hides that
|
|
14
14
|
* element's descendants: a component instance is a `display: contents`
|
|
15
15
|
* wrapper, and `display: none` on the wrapper alone is not enough in every
|
|
16
|
-
* browser.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* browser.
|
|
17
|
+
*
|
|
18
|
+
* Nothing is stored before the visitor accepts the cookie banner
|
|
19
|
+
* (`cookieConsent` exactly 'accepted', the analytics tracker's own test): the
|
|
20
|
+
* arm is then picked for the page load and held in memory, which client-side
|
|
21
|
+
* navigation keeps; an arm an earlier build stored is removed. With consent
|
|
22
|
+
* the arm is kept in `localStorage` (`tq_exp:<id>`), so a returning visitor
|
|
23
|
+
* sees the same page, and is derived from the analytics visitor id, so the
|
|
24
|
+
* assignment also survives a cleared key. A visitor who accepts on the page
|
|
25
|
+
* keeps the version they are looking at. Only localStorage, no cookies, no
|
|
20
26
|
* cross-site identifier (spec §12).
|
|
21
27
|
*
|
|
22
28
|
* The script publishes `window.__tpExp = { <id>: 'a'|'b' }` for every
|
|
@@ -35,10 +41,13 @@ export declare function collectExperimentIds(uidl: ProjectPluginStructure['uidl'
|
|
|
35
41
|
* it runs in `<head>` of every page, before any bundle. `E` is the list of
|
|
36
42
|
* experiment ids baked in at generation.
|
|
37
43
|
*
|
|
38
|
-
* Arm choice: the stored arm; else, with
|
|
39
|
-
* of a 32-bit FNV-1a hash of `<visitorId>|<id>` (stable per visitor and
|
|
40
|
-
* experiment — the same person is not always "a"); else a coin flip
|
|
41
|
-
*
|
|
44
|
+
* Arm choice, with consent: the stored arm; else, with a visitor id, the
|
|
45
|
+
* parity of a 32-bit FNV-1a hash of `<visitorId>|<id>` (stable per visitor and
|
|
46
|
+
* per experiment — the same person is not always "a"); else a coin flip, and
|
|
47
|
+
* the arm is stored and reused. Without consent: a coin flip, stored only
|
|
48
|
+
* once the banner's Accept writes the consent (the workflow step announces
|
|
49
|
+
* its write with `teleport:local-storage`; another tab's with `storage`), and
|
|
50
|
+
* never over an arm another tab stored first.
|
|
42
51
|
*/
|
|
43
52
|
export declare function buildExperimentAssignmentScript(ids: string[]): string;
|
|
44
53
|
/** The `<script>` tag for the project's `customCode.head`; empty without experiments. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"experiments.d.ts","sourceRoot":"","sources":["../../../src/analytics/experiments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"experiments.d.ts","sourceRoot":"","sources":["../../../src/analytics/experiments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAQnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,eAAe,gBAAgB,CAAA;AAC5C,eAAO,MAAM,uBAAuB,wBAAwB,CAAA;AAC5D,eAAO,MAAM,yBAAyB,YAAY,CAAA;AAKlD,uFAAuF;AACvF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,sBAAsB,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAUnF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,+BAA+B,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,CAyBrE;AAED,yFAAyF;AACzF,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,CAKhE"}
|