@playpilot/tpi 8.23.1 → 8.23.2
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/package.json
CHANGED
package/src/lib/splitTest.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { hasConsentedTo } from './consent'
|
|
2
1
|
import { TrackingEvent } from './enums/TrackingEvent'
|
|
3
2
|
import { track } from './tracking'
|
|
4
3
|
|
|
@@ -15,8 +14,6 @@ export const sessionStoragePrefix = 'playpilot_split_test_'
|
|
|
15
14
|
* The identifier is saved on the window object so that it is consistent across this session.
|
|
16
15
|
*/
|
|
17
16
|
export function getSplitTestIdentifier({ key }: SplitTest): number {
|
|
18
|
-
if (!hasConsentedTo('tracking')) return 0
|
|
19
|
-
|
|
20
17
|
const windowIdentifier = window.PlayPilotLinkInjections?.split_test_identifiers?.[key]
|
|
21
18
|
if (windowIdentifier !== undefined) return windowIdentifier
|
|
22
19
|
|
|
@@ -25,7 +22,7 @@ export function getSplitTestIdentifier({ key }: SplitTest): number {
|
|
|
25
22
|
let storedIdentifier = sessionStorage.getItem(sessionStoragePrefix + key)
|
|
26
23
|
|
|
27
24
|
if (!storedIdentifier) {
|
|
28
|
-
const randomIdentifier = Math.random().toString()
|
|
25
|
+
const randomIdentifier = (Math.floor(Math.random() * 100) / 100).toString()
|
|
29
26
|
sessionStorage.setItem(sessionStoragePrefix + key, randomIdentifier)
|
|
30
27
|
storedIdentifier = randomIdentifier
|
|
31
28
|
}
|
|
@@ -53,8 +50,6 @@ export function getSplitTestVariantName(test: SplitTest): string {
|
|
|
53
50
|
}
|
|
54
51
|
|
|
55
52
|
export function isInSplitTestVariant(test: SplitTest, variant = 1): boolean {
|
|
56
|
-
if (!hasConsentedTo('tracking')) return false
|
|
57
|
-
|
|
58
53
|
return getSplitTestVariantIndex(test) === variant
|
|
59
54
|
}
|
|
60
55
|
|
|
@@ -2,11 +2,6 @@ import { describe, it, expect, vi, afterEach } from 'vitest'
|
|
|
2
2
|
import { getSplitTestIdentifier, getSplitTestVariantIndex, getSplitTestVariantName, isInSplitTestVariant, sessionStoragePrefix, trackSplitTestAction, trackSplitTestView } from '$lib/splitTest'
|
|
3
3
|
import { track } from '$lib/tracking'
|
|
4
4
|
import { TrackingEvent } from '$lib/enums/TrackingEvent'
|
|
5
|
-
import { hasConsentedTo } from '$lib/consent'
|
|
6
|
-
|
|
7
|
-
vi.mock('$lib/consent', () => ({
|
|
8
|
-
hasConsentedTo: vi.fn(() => true),
|
|
9
|
-
}))
|
|
10
5
|
|
|
11
6
|
vi.mock('$lib/tracking', () => ({
|
|
12
7
|
track: vi.fn(),
|
|
@@ -23,8 +18,6 @@ describe('$lib/splitTest', () => {
|
|
|
23
18
|
window.PlayPilotLinkInjections = {}
|
|
24
19
|
|
|
25
20
|
vi.resetAllMocks()
|
|
26
|
-
|
|
27
|
-
vi.mocked(hasConsentedTo).mockImplementation(() => true)
|
|
28
21
|
})
|
|
29
22
|
|
|
30
23
|
describe('getSplitTestIdentifier', () => {
|
|
@@ -60,12 +53,6 @@ describe('$lib/splitTest', () => {
|
|
|
60
53
|
})
|
|
61
54
|
})
|
|
62
55
|
|
|
63
|
-
it('Should return 0 if user did not consent', () => {
|
|
64
|
-
vi.mocked(hasConsentedTo).mockImplementation(() => false)
|
|
65
|
-
|
|
66
|
-
expect(getSplitTestIdentifier(splitTest)).toBe(0)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
56
|
it('Should store value in sessionStorage', () => {
|
|
70
57
|
getSplitTestIdentifier(splitTest)
|
|
71
58
|
|
|
@@ -118,16 +105,6 @@ describe('$lib/splitTest', () => {
|
|
|
118
105
|
expect(isInSplitTestVariant(multiple, 1)).toBe(false)
|
|
119
106
|
expect(isInSplitTestVariant(multiple, 2)).toBe(true)
|
|
120
107
|
})
|
|
121
|
-
|
|
122
|
-
it('Should return false if user did not consent', () => {
|
|
123
|
-
vi.mocked(hasConsentedTo).mockImplementation(() => false)
|
|
124
|
-
|
|
125
|
-
// @ts-ignore
|
|
126
|
-
window.PlayPilotLinkInjections.split_test_identifiers = {}
|
|
127
|
-
window.PlayPilotLinkInjections.split_test_identifiers[splitTest.key] = 0.75
|
|
128
|
-
|
|
129
|
-
expect(isInSplitTestVariant(splitTest)).toBe(false)
|
|
130
|
-
})
|
|
131
108
|
})
|
|
132
109
|
|
|
133
110
|
describe('trackSplitTestView', () => {
|