@playpilot/tpi 8.15.2 → 8.16.0

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.15.2",
3
+ "version": "8.16.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -16,7 +16,7 @@
16
16
  "release": "node release.js"
17
17
  },
18
18
  "devDependencies": {
19
- "@playpilot/retargeting-tracking": "^1.0.0",
19
+ "@playpilot/retargeting-tracking": "^1.1.0",
20
20
  "@sveltejs/adapter-auto": "^7.0.1",
21
21
  "@sveltejs/kit": "^2.56.1",
22
22
  "@sveltejs/vite-plugin-svelte": "^4.0.0",
package/src/lib/pixel.ts CHANGED
@@ -1,6 +1,14 @@
1
+ import { RETARGETING_USER_ID_KEY } from '@playpilot/retargeting-tracking'
1
2
  import { hasConsentedTo } from './consent'
3
+ import { getUserId } from './user'
2
4
 
3
5
  export function isPixelAllowed(): boolean {
4
6
  if (!window.PlayPilotLinkInjections.config?.allow_retargeting_pixels) return false
5
- return hasConsentedTo('pixels')
7
+
8
+ if (!hasConsentedTo('pixels')) return false
9
+
10
+ // @ts-ignore
11
+ window[RETARGETING_USER_ID_KEY] = getUserId()
12
+
13
+ return true
6
14
  }
@@ -1,16 +1,25 @@
1
1
  import { hasConsentedTo } from '$lib/consent'
2
2
  import { isPixelAllowed } from '$lib/pixel'
3
+ import { getUserId } from '$lib/user'
4
+ import { RETARGETING_USER_ID_KEY } from '@playpilot/retargeting-tracking'
3
5
  import { beforeEach, describe, expect, it, vi } from 'vitest'
4
6
 
5
7
  vi.mock('$lib/consent', () => ({
6
8
  hasConsentedTo: vi.fn(() => true),
7
9
  }))
8
10
 
11
+ vi.mock('$lib/user', () => ({
12
+ getUserId: vi.fn(),
13
+ }))
14
+
9
15
  describe('pixel.ts', () => {
10
16
  beforeEach(() => {
11
17
  // @ts-ignore
12
18
  window.PlayPilotLinkInjections = {}
13
19
 
20
+ // @ts-ignore
21
+ delete window[RETARGETING_USER_ID_KEY]
22
+
14
23
  vi.mocked(hasConsentedTo).mockImplementation(() => true)
15
24
  })
16
25
 
@@ -43,11 +52,25 @@ describe('pixel.ts', () => {
43
52
  expect(isPixelAllowed()).toBe(true)
44
53
  })
45
54
 
46
- it('Should return true if config object is allow_retargeting_pixels is true but hasConsentedTo is false', () => {
55
+ it('Should return false if config object is allow_retargeting_pixels is true but hasConsentedTo is false', () => {
47
56
  vi.mocked(hasConsentedTo).mockImplementation(() => false)
48
57
  window.PlayPilotLinkInjections.config = { allow_retargeting_pixels: true }
49
58
 
50
59
  expect(isPixelAllowed()).toBe(false)
51
60
  })
61
+
62
+ it('Should set user id on window', () => {
63
+ vi.mocked(hasConsentedTo).mockImplementation(() => true)
64
+ vi.mocked(getUserId).mockImplementation(() => 'abc')
65
+ window.PlayPilotLinkInjections.config = { allow_retargeting_pixels: true }
66
+
67
+ // @ts-ignore
68
+ expect(window[RETARGETING_USER_ID_KEY]).not.toBeTruthy()
69
+
70
+ isPixelAllowed()
71
+
72
+ // @ts-ignore
73
+ expect(window[RETARGETING_USER_ID_KEY]).toBe('abc')
74
+ })
52
75
  })
53
76
  })