@playpilot/tpi 8.21.8-beta.1 → 8.21.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/build.html +3 -0
- package/dist/editorial.mount.js +8 -8
- package/dist/link-injections.js +2 -2
- package/dist/mount.js +6 -6
- package/package.json +2 -2
- package/src/lib/tracking.ts +2 -1
- package/src/lib/user.ts +15 -0
- package/src/routes/components/Rails/TitlesRail.svelte +12 -7
- package/src/tests/lib/user.test.js +39 -1
- package/src/tests/routes/components/Rails/TitlesRail.test.js +7 -9
- package/src/tests/setup.js +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playpilot/tpi",
|
|
3
|
-
"version": "8.21.
|
|
3
|
+
"version": "8.21.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite dev",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"postinstall": "patch-package"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@playpilot/retargeting-tracking": "^1.4.
|
|
20
|
+
"@playpilot/retargeting-tracking": "^1.4.2",
|
|
21
21
|
"@sveltejs/adapter-auto": "^7.0.1",
|
|
22
22
|
"@sveltejs/kit": "^2.56.1",
|
|
23
23
|
"@sveltejs/vite-plugin-svelte": "^4.0.0",
|
package/src/lib/tracking.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { isCrawler } from './crawler'
|
|
|
4
4
|
import { genreSlugsToNames } from './genre'
|
|
5
5
|
import type { TitleData } from './types/title'
|
|
6
6
|
import { getFullUrlPath } from './url'
|
|
7
|
-
import { getUserId, isUserTrackingAllowed } from './user'
|
|
7
|
+
import { getSessionId, getUserId, isUserTrackingAllowed } from './user'
|
|
8
8
|
|
|
9
9
|
const baseUrl = 'https://insights.playpilot.net'
|
|
10
10
|
|
|
@@ -41,6 +41,7 @@ export async function track(event: string, title: TitleData | null = null, paylo
|
|
|
41
41
|
|
|
42
42
|
if (isUserTrackingAllowed()) {
|
|
43
43
|
payload.user_id = getUserId()
|
|
44
|
+
payload.session_id = getSessionId()
|
|
44
45
|
payload.region = window.PlayPilotLinkInjections.region
|
|
45
46
|
}
|
|
46
47
|
|
package/src/lib/user.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { hasConsentedTo } from './consent'
|
|
|
2
2
|
import { generateRandomHash } from './hash'
|
|
3
3
|
|
|
4
4
|
export const localStorageUserKey = 'playpilot_user_id'
|
|
5
|
+
export const sessionStorageSessionKey = 'playpilot_session_id'
|
|
5
6
|
|
|
6
7
|
export function getUserId(): string | null {
|
|
7
8
|
if (!isUserTrackingAllowed()) return null
|
|
@@ -17,6 +18,20 @@ export function getUserId(): string | null {
|
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
export function getSessionId(): string | null {
|
|
22
|
+
if (!isUserTrackingAllowed()) return null
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const sessionId = sessionStorage.getItem(sessionStorageSessionKey)
|
|
26
|
+
if (sessionId) return sessionId
|
|
27
|
+
|
|
28
|
+
sessionStorage.setItem(sessionStorageSessionKey, generateRandomHash(16))
|
|
29
|
+
return sessionStorage.getItem(sessionStorageSessionKey)
|
|
30
|
+
} catch {
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
20
35
|
export function isUserTrackingAllowed(): boolean {
|
|
21
36
|
return !!window.PlayPilotLinkInjections?.config?.allow_user_id_tracking && hasConsentedTo('tracking')
|
|
22
37
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import Rail from './Rail.svelte'
|
|
6
6
|
import type { TitleData } from '$lib/types/title'
|
|
7
7
|
import { openModal } from '$lib/modal'
|
|
8
|
-
import { exploreTitleUrl
|
|
8
|
+
import { exploreTitleUrl } from '$lib/routes'
|
|
9
9
|
import { generateRandomHash } from '$lib/hash'
|
|
10
10
|
import { getFirstTitleWithAvailableTrailer } from '$lib/trailer'
|
|
11
11
|
import { useExploreRouter } from '$lib/explore'
|
|
@@ -174,14 +174,15 @@
|
|
|
174
174
|
onresize={() => slider?.reposition()}>
|
|
175
175
|
{#each titles as title, index}
|
|
176
176
|
{@const expanded = isExpanded(title)}
|
|
177
|
-
{@const href = navigateToExplore ? exploreTitleUrl(title) : titleUrl(title)}
|
|
178
177
|
{@const onclick = (event: MouseEvent): void => openTitle(event, titles, index)}
|
|
179
178
|
|
|
180
179
|
<div class="title" class:expanded data-testid="title">
|
|
181
180
|
<div class="media">
|
|
182
181
|
{#if expanded}
|
|
183
182
|
<div class="video" out:fade={{ delay: 200, duration: 200 }}>
|
|
184
|
-
|
|
183
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
184
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
185
|
+
<div class="video-overlay" title="" {onclick}></div>
|
|
185
186
|
|
|
186
187
|
{#if !!title.embeddable_url}
|
|
187
188
|
<YouTubeEmbed bind:this={embed} embeddable_url={title.embeddable_url!} muted loop captions showMuteControls />
|
|
@@ -190,15 +191,19 @@
|
|
|
190
191
|
{/if}
|
|
191
192
|
</div>
|
|
192
193
|
{:else}
|
|
193
|
-
|
|
194
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
195
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
196
|
+
<div class="poster" {onclick}>
|
|
194
197
|
<TitlePoster {title} width={96} height={144} />
|
|
195
|
-
</
|
|
198
|
+
</div>
|
|
196
199
|
{/if}
|
|
197
200
|
</div>
|
|
198
201
|
|
|
199
|
-
|
|
202
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
203
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
204
|
+
<span class="heading" {onclick} data-testid="heading">
|
|
200
205
|
{title.title}
|
|
201
|
-
</
|
|
206
|
+
</span>
|
|
202
207
|
|
|
203
208
|
{#if aside}
|
|
204
209
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
|
2
|
-
import { getUserId, isUserTrackingAllowed, localStorageUserKey } from '$lib/user'
|
|
2
|
+
import { getSessionId, getUserId, isUserTrackingAllowed, localStorageUserKey, sessionStorageSessionKey } from '$lib/user'
|
|
3
3
|
import { hasConsentedTo } from '$lib/consent'
|
|
4
4
|
|
|
5
5
|
vi.mock('$lib/consent', () => ({
|
|
@@ -45,6 +45,44 @@ describe('user.ts', () => {
|
|
|
45
45
|
})
|
|
46
46
|
})
|
|
47
47
|
|
|
48
|
+
describe('getSessionId', () => {
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
window.PlayPilotLinkInjections = {
|
|
52
|
+
config: {
|
|
53
|
+
allow_user_id_tracking: true,
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
vi.mocked(hasConsentedTo).mockImplementation(() => true)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('Should return random hash by default', () => {
|
|
61
|
+
expect(getSessionId()).toBeTruthy()
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('Should return the previously set value', () => {
|
|
65
|
+
sessionStorage.setItem(sessionStorageSessionKey, 'some_value')
|
|
66
|
+
|
|
67
|
+
expect(getSessionId()).toBe('some_value')
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('Should return null if allow_user_id_tracking is not set', () => {
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
window.PlayPilotLinkInjections = {}
|
|
73
|
+
|
|
74
|
+
expect(getSessionId()).toBe(null)
|
|
75
|
+
|
|
76
|
+
sessionStorage.setItem(sessionStorageSessionKey, 'some_value')
|
|
77
|
+
|
|
78
|
+
expect(getSessionId()).toBe(null)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('Should return the same id when called multiple times', () => {
|
|
82
|
+
expect(getSessionId()).toBe(getSessionId())
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
|
|
48
86
|
describe('isUserTrackingAllowed', () => {
|
|
49
87
|
beforeEach(() => {
|
|
50
88
|
// @ts-ignore
|
|
@@ -36,16 +36,15 @@ describe('TitlesRail.svelte', () => {
|
|
|
36
36
|
})
|
|
37
37
|
|
|
38
38
|
it('Should render all titles', async () => {
|
|
39
|
-
const { getAllByTestId
|
|
39
|
+
const { getAllByTestId } = render(TitlesRail, { titles: [title, title] })
|
|
40
40
|
|
|
41
41
|
expect(getAllByTestId('title')).toHaveLength(2)
|
|
42
|
-
expect(getAllByRole('link')[0].getAttribute('href')).toBe(`https://www.playpilot.com/series/${title.slug}/`)
|
|
43
42
|
})
|
|
44
43
|
|
|
45
44
|
it('Should fire openModal when title is clicked', async () => {
|
|
46
|
-
const {
|
|
45
|
+
const { getByText } = render(TitlesRail, { titles: [title] })
|
|
47
46
|
|
|
48
|
-
await fireEvent.click(
|
|
47
|
+
await fireEvent.click(getByText(title.title))
|
|
49
48
|
|
|
50
49
|
expect(openModal).toHaveBeenCalledWith({
|
|
51
50
|
type: 'titles-rail',
|
|
@@ -57,9 +56,9 @@ describe('TitlesRail.svelte', () => {
|
|
|
57
56
|
|
|
58
57
|
it('Should fire given onclick function when title is clicked', async () => {
|
|
59
58
|
const onclick = vi.fn()
|
|
60
|
-
const {
|
|
59
|
+
const { getByText } = render(TitlesRail, { titles: [title], onclick })
|
|
61
60
|
|
|
62
|
-
await fireEvent.click(
|
|
61
|
+
await fireEvent.click(getByText(title.title))
|
|
63
62
|
|
|
64
63
|
expect(onclick).toHaveBeenCalledWith(title)
|
|
65
64
|
})
|
|
@@ -215,11 +214,10 @@ describe('TitlesRail.svelte', () => {
|
|
|
215
214
|
})
|
|
216
215
|
|
|
217
216
|
it('Should navigate to explore page rather than open modal when navigateToExplore is true', async () => {
|
|
218
|
-
const {
|
|
217
|
+
const { getByText } = render(TitlesRail, { titles: [title], navigateToExplore: true })
|
|
219
218
|
|
|
220
|
-
await fireEvent.click(
|
|
219
|
+
await fireEvent.click(getByText(title.title))
|
|
221
220
|
|
|
222
|
-
expect(getAllByRole('link')[0].getAttribute('href')).toContain(`?route=modal&sid=${title.sid}`)
|
|
223
221
|
expect(window.location.href).toContain(`?route=modal&sid=${title.sid}`)
|
|
224
222
|
expect(openModal).not.toHaveBeenCalledWith()
|
|
225
223
|
})
|
package/src/tests/setup.js
CHANGED
|
@@ -96,7 +96,9 @@ beforeEach(() => {
|
|
|
96
96
|
document.cookie.split(';').forEach((cookie) => document.cookie = cookie.replace(/^ +/, '').replace(/=.*/, '=;'))
|
|
97
97
|
|
|
98
98
|
window.HTMLElement.prototype.scrollIntoView = vi.fn()
|
|
99
|
+
|
|
99
100
|
localStorage.clear()
|
|
101
|
+
sessionStorage.clear()
|
|
100
102
|
|
|
101
103
|
mockAnimations()
|
|
102
104
|
})
|