@playpilot/tpi 8.23.2 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playpilot/tpi",
3
- "version": "8.23.2",
3
+ "version": "8.23.4",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -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('&')
@@ -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&param=123')