This repository was archived by the owner on Jan 15, 2026. It is now read-only.
forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeep_links.test.ts
More file actions
107 lines (96 loc) · 3.34 KB
/
Copy pathdeep_links.test.ts
File metadata and controls
107 lines (96 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import {
DEEP_LINK_ENTITY_SCHEMA,
DEEP_LINK_RECEIVED_EVENT_SCHEMA,
SCREEN_VIEW_EVENT_SCHEMA,
} from '../../src/constants';
import { newDeepLinksPlugin } from '../../src/plugins/deep_links';
import { buildSelfDescribingEvent, Payload, trackerCore } from '@snowplow/tracker-core';
describe('Deep Link plugin', () => {
it('adds the url and refr properties on the deep link event', () => {
const payloads: Payload[] = [];
const tracker = trackerCore({
callback: (pb) => payloads.push(pb.build()),
base64: false,
});
const deepLinksPlugin = newDeepLinksPlugin({}, tracker);
tracker.addPlugin(deepLinksPlugin);
deepLinksPlugin.trackDeepLinkReceivedEvent({
url: 'http://url.com',
referrer: 'http://referrer.com',
});
expect(payloads.length).toBe(1);
const [{ url, refr, ue_pr }] = payloads as any;
expect(url).toBe('http://url.com');
expect(refr).toBe('http://referrer.com');
const { data } = JSON.parse(ue_pr);
expect(data.schema).toBe(DEEP_LINK_RECEIVED_EVENT_SCHEMA);
expect(data.data.url).toBe('http://url.com');
expect(data.data.referrer).toBe('http://referrer.com');
});
it('adds the deep link context to the first screen view event', () => {
const payloads: Payload[] = [];
const tracker = trackerCore({
callback: (pb) => payloads.push(pb.build()),
base64: false,
});
const deepLinksPlugin = newDeepLinksPlugin({}, tracker);
tracker.addPlugin(deepLinksPlugin);
deepLinksPlugin.trackDeepLinkReceivedEvent({
url: 'http://url.com',
referrer: 'http://referrer.com',
});
tracker.track(
buildSelfDescribingEvent({
event: {
schema: SCREEN_VIEW_EVENT_SCHEMA,
data: {},
},
})
);
tracker.track(
buildSelfDescribingEvent({
event: {
schema: SCREEN_VIEW_EVENT_SCHEMA,
data: {},
},
})
);
expect(payloads.length).toBe(3);
const [, { url, refr, co }, { co: co2 }] = payloads as any;
expect(url).toBe('http://url.com');
expect(refr).toBe('http://referrer.com');
expect(co).not.toBeUndefined();
const entities = JSON.parse(co).data;
const deepLinkEntity = entities.find((entity: any) => entity.schema === DEEP_LINK_ENTITY_SCHEMA);
expect(deepLinkEntity).not.toBeUndefined();
expect(deepLinkEntity.data.url).toBe('http://url.com');
expect(deepLinkEntity.data.referrer).toBe('http://referrer.com');
expect(co2 ?? '').not.toContain(DEEP_LINK_ENTITY_SCHEMA);
});
it('does not add the deep link entity if disabled', () => {
const payloads: Payload[] = [];
const tracker = trackerCore({
callback: (pb) => payloads.push(pb.build()),
base64: false,
});
const deepLinksPlugin = newDeepLinksPlugin({ deepLinkContext: false }, tracker);
tracker.addPlugin(deepLinksPlugin);
deepLinksPlugin.trackDeepLinkReceivedEvent({
url: 'http://url.com',
referrer: 'http://referrer.com',
});
tracker.track(
buildSelfDescribingEvent({
event: {
schema: SCREEN_VIEW_EVENT_SCHEMA,
data: {},
},
})
);
expect(payloads.length).toBe(2);
const [, { url, refr, co }] = payloads as any;
expect(url).toBe('http://url.com');
expect(refr).toBe('http://referrer.com');
expect(co ?? '').not.toContain(DEEP_LINK_ENTITY_SCHEMA);
});
});