@playpilot/tpi 8.23.1 → 8.23.4
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/dist/editorial.mount.js +7 -7
- package/dist/link-injections.js +1 -1
- package/dist/mount.js +5 -5
- package/package.json +1 -1
- package/src/lib/splitTest.ts +1 -6
- package/src/lib/tracking.ts +2 -1
- package/src/lib/url.ts +9 -0
- package/src/tests/lib/splitTest.test.js +0 -23
- package/src/tests/lib/url.test.js +17 -1
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
|
|
package/src/lib/tracking.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { mobileBreakpoint } from './constants'
|
|
|
3
3
|
import { isCrawler } from './crawler'
|
|
4
4
|
import { genreSlugsToNames } from './genre'
|
|
5
5
|
import type { TitleData } from './types/title'
|
|
6
|
-
import { getFullUrlPath } from './url'
|
|
6
|
+
import { getFullUrlPath, getUrlParams } from './url'
|
|
7
7
|
import { getSessionId, getUserId, isUserTrackingAllowed } from './user'
|
|
8
8
|
|
|
9
9
|
const baseUrl = 'https://insights.playpilot.net'
|
|
@@ -48,6 +48,7 @@ export async function track(event: string, title: TitleData | null = null, paylo
|
|
|
48
48
|
payload.version = __SCRIPT_VERSION__
|
|
49
49
|
payload.time_since_initialize = window.PlayPilotLinkInjections?.time_at_initialize ? Date.now() - window.PlayPilotLinkInjections.time_at_initialize : 0
|
|
50
50
|
payload.url = getFullUrlPath()
|
|
51
|
+
payload.url_params = getUrlParams()
|
|
51
52
|
payload.organization_sid = window.PlayPilotLinkInjections?.organization_sid || 'undefined'
|
|
52
53
|
payload.domain_sid = window.PlayPilotLinkInjections?.domain_sid || 'undefined'
|
|
53
54
|
payload.device = {
|
package/src/lib/url.ts
CHANGED
|
@@ -10,6 +10,15 @@ export function getFullUrlPath(): string {
|
|
|
10
10
|
return location.protocol + '//' + location.host + cleanedPathname
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export function getUrlParams(): string {
|
|
14
|
+
try {
|
|
15
|
+
const url = new URL(location.href)
|
|
16
|
+
return Object.fromEntries(url.searchParams.entries())
|
|
17
|
+
} catch {
|
|
18
|
+
return {}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
13
22
|
export function paramsToString(params: Record<string, any>): string {
|
|
14
23
|
const filteredParams = Object.entries(params).filter(([_, value]) => value !== undefined && value !== null && value !== '')
|
|
15
24
|
return filteredParams.map(([key, value]) => `${key}=${value}`).join('&')
|
|
@@ -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', () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
2
|
-
import { getFullUrlPath, isUrlExcludedViaConfig, paramsToString } from '$lib/url'
|
|
2
|
+
import { getFullUrlPath, getUrlParams, isUrlExcludedViaConfig, paramsToString } from '$lib/url'
|
|
3
3
|
|
|
4
4
|
describe('url.ts', () => {
|
|
5
5
|
describe('getFullUrlPath', () => {
|
|
@@ -53,6 +53,22 @@ describe('url.ts', () => {
|
|
|
53
53
|
})
|
|
54
54
|
})
|
|
55
55
|
|
|
56
|
+
describe('getUrlParams', () => {
|
|
57
|
+
it('Should return query params as object', () => {
|
|
58
|
+
window.location.pathname = '/some-path'
|
|
59
|
+
window.location.search = '?some=param&other=thing'
|
|
60
|
+
|
|
61
|
+
expect(getUrlParams()).toEqual({ some: 'param', other: 'thing' })
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('Should return empty object if no params are given', () => {
|
|
65
|
+
window.location.pathname = '/some-path'
|
|
66
|
+
window.location.search = ''
|
|
67
|
+
|
|
68
|
+
expect(getUrlParams()).toEqual({ })
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
56
72
|
describe('paramsToString', () => {
|
|
57
73
|
it('Should convert a flat object to a query string', () => {
|
|
58
74
|
expect(paramsToString({ some: 'value', param: 123 })).toBe('some=value¶m=123')
|