@playpilot/tpi 6.4.2 → 6.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playpilot/tpi",
3
- "version": "6.4.2",
3
+ "version": "6.4.4",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -29,7 +29,6 @@ export async function fetchLinkInjections(
29
29
  // We use separate requests when running the AI or setting the editor session vs when only getting the results.
30
30
  // For regular requests we use a GET endpoint, but when saving data we POST to the same url.
31
31
  if (Object.entries(params).length) {
32
- // Additional params are added when re-running AI. These are necessary for the API
33
32
  if (params.run_ai) {
34
33
  params.hash = hash
35
34
  params.page_text = pageText
@@ -4,9 +4,4 @@ export const SplitTest = {
4
4
  numberOfVariants: 2,
5
5
  variantNames: ['Separated', 'Inline'] as string[],
6
6
  },
7
- PostersScrollReveal: {
8
- key: 'posters_scroll_reveal',
9
- numberOfVariants: 2,
10
- variantNames: ['Default', 'With Posters'] as string[],
11
- },
12
7
  } as const
@@ -0,0 +1,7 @@
1
+ import genres from '$lib/data/genres.json'
2
+
3
+ export function genreSlugsToNames(slugs: string[] = []): string[] {
4
+ return slugs.map((slug) => {
5
+ return genres.find((genre) => genre.slug === slug)?.name || ''
6
+ }).filter(Boolean)
7
+ }
@@ -1,6 +1,7 @@
1
1
  import { hasConsentedTo } from './consent'
2
2
  import { mobileBreakpoint } from './constants'
3
3
  import { isCrawler } from './crawler'
4
+ import { genreSlugsToNames } from './genre'
4
5
  import type { TitleData } from './types/title'
5
6
  import { getFullUrlPath } from './url'
6
7
 
@@ -29,6 +30,7 @@ export async function track(event: string, title: TitleData | null = null, paylo
29
30
  title: title.title,
30
31
  title_sid: title.sid,
31
32
  title_type: title.type,
33
+ genres: genreSlugsToNames(title.genres),
32
34
  providers: [...new Set(title.providers?.map(p => p.name) || [])],
33
35
  ...payload,
34
36
  }
@@ -234,7 +234,6 @@
234
234
 
235
235
  {#key linkInjections}
236
236
  <UserJourney />
237
- <PostersScrollReveal />
238
237
  {/key}
239
238
 
240
239
  <Consent onchange={afterConsent} />
@@ -1,7 +1,5 @@
1
1
  <script lang="ts">
2
2
  import { mobileBreakpoint } from '$lib/constants'
3
- import { SplitTest } from '$lib/enums/SplitTest'
4
- import { isInSplitTestVariant, trackSplitTestAction, trackSplitTestView } from '$lib/splitTest'
5
3
  import { onMount } from 'svelte'
6
4
 
7
5
  const linksWithPosters = Array.from(document.querySelectorAll<HTMLElement>('[data-playpilot-poster-url]'))
@@ -18,27 +16,11 @@
18
16
  onMount(() => {
19
17
  if (!isMobile) return
20
18
 
21
- trackSplitTestView(SplitTest.PostersScrollReveal)
22
-
23
19
  return destroyAllPosters
24
20
  })
25
21
 
26
- $effect(() => {
27
- if (!isMobile) return
28
- if (!linksWithPosters.length) return
29
-
30
- const onclick = () => trackSplitTestAction(SplitTest.PostersScrollReveal, 'click')
31
-
32
- for(const link of linksWithPosters) link.addEventListener('click', onclick)
33
-
34
- return () => {
35
- for(const link of linksWithPosters) link.removeEventListener('click', onclick)
36
- }
37
- })
38
-
39
22
  function onscroll(): void {
40
23
  if (!isMobile) return
41
- if (!isInSplitTestVariant(SplitTest.PostersScrollReveal)) return
42
24
 
43
25
  setScrollTimeout()
44
26
 
@@ -0,0 +1,23 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { genreSlugsToNames } from '$lib/genre'
4
+
5
+ describe('genres.ts', () => {
6
+ describe('genreSlugsToNames', () => {
7
+ it('Should return genre names for given slugs', () => {
8
+ expect(genreSlugsToNames(['101', '103'])).toEqual(['Action', 'Kids'])
9
+ })
10
+
11
+ it('Should exclude slugs that were not found', () => {
12
+ expect(genreSlugsToNames(['101', 'not-found'])).toEqual(['Action'])
13
+ })
14
+
15
+ it('Should return an empty array if no slugs were found', () => {
16
+ expect(genreSlugsToNames(['not-found'])).toEqual([])
17
+ })
18
+
19
+ it('Should return an empty array when no slugs were given', () => {
20
+ expect(genreSlugsToNames([])).toEqual([])
21
+ })
22
+ })
23
+ })
@@ -121,7 +121,7 @@ describe('$lib/tracking', () => {
121
121
  expect(global.fetch).toHaveBeenCalledWith(
122
122
  expect.any(String),
123
123
  expect.objectContaining({
124
- body: expect.stringContaining(`"original_title":"${title.original_title}","title":"${title.title}","title_sid":"${title.sid}","title_type":"${title.type}"`),
124
+ body: expect.stringContaining(`"original_title":"${title.original_title}","title":"${title.title}","title_sid":"${title.sid}","title_type":"${title.type}","genres":["Action","Adventure","Sci-Fi","Drama"]`),
125
125
  }),
126
126
  )
127
127
  })
@@ -1,14 +1,7 @@
1
- import { fireEvent, render } from '@testing-library/svelte'
1
+ import { render } from '@testing-library/svelte'
2
2
  import { describe, it, expect, vi, beforeEach } from 'vitest'
3
3
  import PostersScrollReveal from '../../../routes/components/PostersScrollReveal.svelte'
4
4
  import { mobileBreakpoint } from '$lib/constants'
5
- import { isInSplitTestVariant, trackSplitTestAction } from '$lib/splitTest'
6
-
7
- vi.mock('$lib/splitTest', () => ({
8
- trackSplitTestView: vi.fn(),
9
- trackSplitTestAction: vi.fn(),
10
- isInSplitTestVariant: vi.fn(() => true),
11
- }))
12
5
 
13
6
  function createPosterLink(top = 0, url = 'poster.jpg') {
14
7
  const link = document.createElement('a')
@@ -37,8 +30,6 @@ describe('FloatingPoster', () => {
37
30
 
38
31
  vi.useFakeTimers()
39
32
  vi.resetAllMocks()
40
-
41
- vi.mocked(isInSplitTestVariant).mockReturnValue(true)
42
33
  })
43
34
 
44
35
  it('Should create poster when link is in viewport', async () => {
@@ -147,16 +138,4 @@ describe('FloatingPoster', () => {
147
138
  window.dispatchEvent(new Event('scroll'))
148
139
  expect(document.querySelector('[data-playpilot-poster]')).toBeTruthy()
149
140
  })
150
-
151
- it('Should fire split test tracking on click', async () => {
152
- createPosterLink(500)
153
-
154
- render(PostersScrollReveal)
155
-
156
- window.dispatchEvent(new Event('scroll'))
157
-
158
- await fireEvent.click(/** @type {HTMLElement} */ (document.querySelector('[data-playpilot-poster]')))
159
-
160
- expect(trackSplitTestAction).toHaveBeenCalled()
161
- })
162
141
  })