@jitsu/js 1.9.7-canary.903.20240731114701 → 1.9.8
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/.turbo/turbo-build.log +5 -5
- package/.turbo/turbo-clean.log +1 -1
- package/.turbo/turbo-test.log +2129 -436
- package/__tests__/node/nodejs.test.ts +213 -78
- package/__tests__/playwright/cases/disable-user-ids.html +23 -0
- package/__tests__/playwright/cases/dont-send.html +22 -0
- package/__tests__/playwright/cases/ip-policy.html +22 -0
- package/__tests__/playwright/integration.test.ts +170 -2
- package/dist/analytics-plugin.d.ts +3 -5
- package/dist/browser.d.ts +5 -3
- package/dist/index.d.ts +2 -2
- package/dist/jitsu.cjs.js +165 -39
- package/dist/jitsu.d.ts +6 -1
- package/dist/jitsu.es.js +165 -40
- package/dist/web/p.js.txt +195 -44
- package/package.json +4 -3
- package/src/analytics-plugin.ts +146 -49
- package/src/browser.ts +45 -16
- package/src/destination-plugins/index.ts +0 -1
- package/src/index.ts +57 -28
- package/src/jitsu.ts +0 -93
|
@@ -38,99 +38,234 @@ describe("Test Jitsu NodeJS client", () => {
|
|
|
38
38
|
console.log("Server is down " + server.baseUrl);
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
beforeAll(async () => {
|
|
42
42
|
await startServer();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
requestLog = [];
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
afterAll(async () => {
|
|
50
|
+
await shutdownServer();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("setAnonymousId test2", async () => {
|
|
54
|
+
const config = {
|
|
55
|
+
host: server.baseUrl,
|
|
56
|
+
writeKey: "key:secret",
|
|
57
|
+
debug: true,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
console.log("[JITSU TEST] Initializing Jitsu");
|
|
61
|
+
const client = jitsuAnalytics(config);
|
|
62
|
+
console.log("[JITSU TEST] Jitsu instance", client);
|
|
63
|
+
|
|
64
|
+
const anonymousId = "anonymous_id_test";
|
|
65
|
+
console.log("[JITSU TEST] Setting anonymous id to " + anonymousId);
|
|
66
|
+
await client.setAnonymousId(anonymousId);
|
|
67
|
+
console.log("user state", client.getState("user"));
|
|
68
|
+
|
|
69
|
+
expect(requestLog.length).toBe(0);
|
|
70
|
+
console.log("[JITSU TEST] Sending event EVENT_1");
|
|
71
|
+
await client.track("EVENT_1");
|
|
72
|
+
await client.track("EVENT_2");
|
|
73
|
+
await client.track("groupId");
|
|
74
|
+
|
|
75
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
76
|
+
|
|
77
|
+
expect(requestLog.length).toBe(3);
|
|
78
|
+
expect(requestLog[1].body.anonymousId).toBe("anonymous_id_test");
|
|
79
|
+
expect(requestLog[0].body.anonymousId).toBe("anonymous_id_test");
|
|
80
|
+
expect(requestLog[2].body.anonymousId).toBe("anonymous_id_test");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("test privacy dontSend", async () => {
|
|
84
|
+
const config = {
|
|
85
|
+
host: server.baseUrl,
|
|
86
|
+
writeKey: "key:secret",
|
|
87
|
+
debug: true,
|
|
88
|
+
privacy: {
|
|
89
|
+
dontSend: true,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
const client = jitsuAnalytics(config);
|
|
93
|
+
expect(requestLog.length).toBe(0);
|
|
94
|
+
await client.identify("myUserId", { email: "myUserId@example.com" });
|
|
95
|
+
await client.group("myGroupId", { name: "myGroupId" });
|
|
96
|
+
await client.track("myEvent", { prop1: "value1" });
|
|
97
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
98
|
+
expect(requestLog.length).toBe(0);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("test privacy dontSend then consent", async () => {
|
|
102
|
+
const config = {
|
|
103
|
+
host: server.baseUrl,
|
|
104
|
+
writeKey: "key:secret",
|
|
105
|
+
debug: true,
|
|
106
|
+
privacy: {
|
|
107
|
+
dontSend: true,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
const client = jitsuAnalytics(config);
|
|
111
|
+
expect(requestLog.length).toBe(0);
|
|
112
|
+
await client.identify("myUserId", { email: "myUserId@example.com" });
|
|
113
|
+
await client.group("myGroupId", { name: "myGroupId" });
|
|
114
|
+
await client.track("myEvent", { prop1: "value1" });
|
|
115
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
116
|
+
expect(requestLog.length).toBe(0);
|
|
43
117
|
|
|
118
|
+
client.configure({
|
|
119
|
+
privacy: {
|
|
120
|
+
dontSend: false,
|
|
121
|
+
consentCategories: {
|
|
122
|
+
analytics: true,
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
await client.identify("myUserId", { email: "myUserId@example.com" });
|
|
127
|
+
await client.group("myGroupId", { name: "myGroupId" });
|
|
128
|
+
await client.track("myEvent", { prop1: "value1" });
|
|
129
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
130
|
+
|
|
131
|
+
expect(requestLog.length).toBe(3);
|
|
132
|
+
const p = requestLog[2];
|
|
133
|
+
expect(p.type).toEqual("track");
|
|
134
|
+
expect(p.body.event).toBe("myEvent");
|
|
135
|
+
expect(p.body.userId).toEqual("myUserId");
|
|
136
|
+
expect(p.body.groupId).toEqual("myGroupId");
|
|
137
|
+
expect(p.body.context?.traits?.email).toEqual("myUserId@example.com");
|
|
138
|
+
expect(p.body.context?.consent?.categoryPreferences).toEqual({ analytics: true });
|
|
139
|
+
expect((p.body.anonymousId ?? "").length).toBeGreaterThan(0);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("test privacy disableUserIds", async () => {
|
|
143
|
+
const config = {
|
|
144
|
+
host: server.baseUrl,
|
|
145
|
+
writeKey: "key:secret",
|
|
146
|
+
debug: true,
|
|
147
|
+
privacy: {
|
|
148
|
+
disableUserIds: true,
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
const client = jitsuAnalytics(config);
|
|
152
|
+
expect(requestLog.length).toBe(0);
|
|
153
|
+
await client.identify("myUserId", { email: "myUserId@example.com" });
|
|
154
|
+
await client.group("myGroupId", { name: "myGroupId" });
|
|
155
|
+
await client.track("myEvent", { prop1: "value1" });
|
|
156
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
157
|
+
expect(requestLog.length).toBe(1);
|
|
158
|
+
const p = requestLog[0];
|
|
159
|
+
expect(p.type).toEqual("track");
|
|
160
|
+
expect(p.body.event).toBe("myEvent");
|
|
161
|
+
expect(p.body.userId).toBeUndefined();
|
|
162
|
+
expect(p.body.groupId).toBeUndefined();
|
|
163
|
+
expect(p.body.context?.traits?.email).toBeUndefined();
|
|
164
|
+
expect(p.body.anonymousId).toBeUndefined();
|
|
165
|
+
expect(p.body.properties?.prop1).toBe("value1");
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("test privacy disableUserIds then consent", async () => {
|
|
44
169
|
const config = {
|
|
45
170
|
host: server.baseUrl,
|
|
46
171
|
writeKey: "key:secret",
|
|
47
172
|
debug: true,
|
|
173
|
+
privacy: {
|
|
174
|
+
disableUserIds: true,
|
|
175
|
+
},
|
|
48
176
|
};
|
|
177
|
+
const client = jitsuAnalytics(config);
|
|
178
|
+
expect(requestLog.length).toBe(0);
|
|
179
|
+
await client.identify("myUserId", { email: "myUserId@example.com" });
|
|
180
|
+
await client.group("myGroupId", { name: "myGroupId" });
|
|
181
|
+
await client.track("myEvent", { prop1: "value1" });
|
|
182
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
183
|
+
expect(requestLog.length).toBe(1);
|
|
184
|
+
let p = requestLog[0];
|
|
185
|
+
expect(p.type).toEqual("track");
|
|
186
|
+
expect(p.body.event).toBe("myEvent");
|
|
187
|
+
expect(p.body.userId).toBeUndefined();
|
|
188
|
+
expect(p.body.groupId).toBeUndefined();
|
|
189
|
+
expect(p.body.context?.traits?.email).toBeUndefined();
|
|
190
|
+
expect(p.body.anonymousId).toBeUndefined();
|
|
191
|
+
expect(p.body.properties?.prop1).toBe("value1");
|
|
49
192
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
} finally {
|
|
73
|
-
shutdownServer();
|
|
74
|
-
}
|
|
193
|
+
client.configure({
|
|
194
|
+
privacy: {
|
|
195
|
+
disableUserIds: false,
|
|
196
|
+
consentCategories: {
|
|
197
|
+
analytics: true,
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
await client.identify("myUserId", { email: "myUserId@example.com" });
|
|
202
|
+
await client.group("myGroupId", { name: "myGroupId" });
|
|
203
|
+
await client.track("myEvent", { prop1: "value1" });
|
|
204
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
205
|
+
|
|
206
|
+
expect(requestLog.length).toBe(4);
|
|
207
|
+
p = requestLog[3];
|
|
208
|
+
expect(p.type).toEqual("track");
|
|
209
|
+
expect(p.body.event).toBe("myEvent");
|
|
210
|
+
expect(p.body.userId).toEqual("myUserId");
|
|
211
|
+
expect(p.body.groupId).toEqual("myGroupId");
|
|
212
|
+
expect(p.body.context?.traits?.email).toEqual("myUserId@example.com");
|
|
213
|
+
expect(p.body.context?.consent?.categoryPreferences).toEqual({ analytics: true });
|
|
214
|
+
expect((p.body.anonymousId ?? "").length).toBeGreaterThan(0);
|
|
75
215
|
});
|
|
76
216
|
|
|
77
217
|
test("node js", async () => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
86
|
-
await jitsu.track("testTrack");
|
|
218
|
+
const jitsu: AnalyticsInterface = jitsuAnalytics({
|
|
219
|
+
writeKey: "key:secret",
|
|
220
|
+
host: server.baseUrl,
|
|
221
|
+
debug: true,
|
|
222
|
+
fetch: fetchImpl,
|
|
223
|
+
});
|
|
224
|
+
await jitsu.track("testTrack");
|
|
87
225
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
226
|
+
await jitsu.identify("testUser", {
|
|
227
|
+
email: "test@test.com",
|
|
228
|
+
});
|
|
91
229
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
230
|
+
await jitsu.group("testGroup", {
|
|
231
|
+
name: "Test Group",
|
|
232
|
+
});
|
|
95
233
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
},
|
|
234
|
+
await jitsu.page({
|
|
235
|
+
name: "test",
|
|
236
|
+
environment: "nodejs",
|
|
237
|
+
context: {
|
|
238
|
+
page: {
|
|
239
|
+
url: "http://server.com",
|
|
103
240
|
},
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
await shutdownServer();
|
|
133
|
-
}
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
244
|
+
expect(requestLog.length).toBe(4);
|
|
245
|
+
expect(requestLog[0].type).toBe("track");
|
|
246
|
+
expect(requestLog[1].type).toBe("identify");
|
|
247
|
+
expect(requestLog[2].type).toBe("group");
|
|
248
|
+
expect(requestLog[3].type).toBe("page");
|
|
249
|
+
|
|
250
|
+
const track = requestLog[0].body as AnalyticsClientEvent;
|
|
251
|
+
const identify = requestLog[1].body as AnalyticsClientEvent;
|
|
252
|
+
const group = requestLog[2].body as AnalyticsClientEvent;
|
|
253
|
+
const page = requestLog[3].body as AnalyticsClientEvent;
|
|
254
|
+
|
|
255
|
+
//expect(track.userId).toBe(undefined);
|
|
256
|
+
expect(page.properties.name).toBe("test");
|
|
257
|
+
expect(page.properties?.environment).toBe("nodejs");
|
|
258
|
+
expect(page.context.page.url).toBe("http://server.com");
|
|
259
|
+
expect(page.userId).toBe("testUser");
|
|
260
|
+
expect(identify.traits.email).toBe("test@test.com");
|
|
261
|
+
expect(identify.anonymousId).toBe(page.anonymousId);
|
|
262
|
+
expect(group.traits.name).toBe("Test Group");
|
|
263
|
+
expect(group.anonymousId).toBe(page.anonymousId);
|
|
264
|
+
expect(group.userId).toBe("testUser");
|
|
265
|
+
expect(group.groupId).toBe("testGroup");
|
|
266
|
+
|
|
267
|
+
const pagePayload = requestLog[0].body;
|
|
268
|
+
console.log("pagePayload", pagePayload);
|
|
134
269
|
});
|
|
135
270
|
|
|
136
271
|
test("tld", async () => {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
|
|
3
|
+
<html lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
+
|
|
8
|
+
<title>Tracking page</title>
|
|
9
|
+
|
|
10
|
+
<script
|
|
11
|
+
type="text/javascript"
|
|
12
|
+
src="<%=trackingBase%>/p.js"
|
|
13
|
+
data-privacy-disable-user-ids="true"
|
|
14
|
+
data-init-only="true"
|
|
15
|
+
data-debug="true"
|
|
16
|
+
defer
|
|
17
|
+
></script>
|
|
18
|
+
</head>
|
|
19
|
+
|
|
20
|
+
<body>
|
|
21
|
+
<h1>Test</h1>
|
|
22
|
+
</body>
|
|
23
|
+
</html>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
|
|
3
|
+
<html lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
+
|
|
8
|
+
<title>Tracking page</title>
|
|
9
|
+
|
|
10
|
+
<script
|
|
11
|
+
type="text/javascript"
|
|
12
|
+
src="<%=trackingBase%>/p.js"
|
|
13
|
+
data-privacy-dont-send="true"
|
|
14
|
+
data-debug="true"
|
|
15
|
+
defer
|
|
16
|
+
></script>
|
|
17
|
+
</head>
|
|
18
|
+
|
|
19
|
+
<body>
|
|
20
|
+
<h1>Test</h1>
|
|
21
|
+
</body>
|
|
22
|
+
</html>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
|
|
3
|
+
<html lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
+
|
|
8
|
+
<title>Tracking page</title>
|
|
9
|
+
|
|
10
|
+
<script
|
|
11
|
+
type="text/javascript"
|
|
12
|
+
src="<%=trackingBase%>/p.js"
|
|
13
|
+
data-privacy-ip-policy="stripLastOctet"
|
|
14
|
+
data-debug="true"
|
|
15
|
+
defer
|
|
16
|
+
></script>
|
|
17
|
+
</head>
|
|
18
|
+
|
|
19
|
+
<body>
|
|
20
|
+
<h1>Test</h1>
|
|
21
|
+
</body>
|
|
22
|
+
</html>
|
|
@@ -5,7 +5,6 @@ import * as path from "path";
|
|
|
5
5
|
import ejs from "ejs";
|
|
6
6
|
// import chalk from "chalk";
|
|
7
7
|
import * as process from "process";
|
|
8
|
-
import * as console from "console";
|
|
9
8
|
import { AnalyticsClientEvent, AnalyticsInterface } from "@jitsu/protocols/analytics.d";
|
|
10
9
|
|
|
11
10
|
test.use({
|
|
@@ -24,7 +23,7 @@ const app = express();
|
|
|
24
23
|
|
|
25
24
|
let server: SimpleSyrup;
|
|
26
25
|
|
|
27
|
-
let requestLog: { type: string; body: AnalyticsClientEvent }[] = [];
|
|
26
|
+
let requestLog: { type: string; body: AnalyticsClientEvent; headers: any }[] = [];
|
|
28
27
|
|
|
29
28
|
test.beforeAll(async () => {
|
|
30
29
|
const testCasesHandlers = fs.readdirSync(path.join(__dirname, "cases")).reduce((res, file) => {
|
|
@@ -60,6 +59,7 @@ test.beforeAll(async () => {
|
|
|
60
59
|
res.send({ ok: true });
|
|
61
60
|
requestLog.push({
|
|
62
61
|
type: req.params.type,
|
|
62
|
+
headers: req.headers,
|
|
63
63
|
body: req.body,
|
|
64
64
|
});
|
|
65
65
|
},
|
|
@@ -279,6 +279,174 @@ test("reset", async ({ browser }) => {
|
|
|
279
279
|
expect(secondTrack.body.anonymousId).not.toEqual("john-doe-id-1");
|
|
280
280
|
});
|
|
281
281
|
|
|
282
|
+
const generateEventsForConsentTests = async () => {
|
|
283
|
+
const analytics = window["jitsu"] as AnalyticsInterface;
|
|
284
|
+
await analytics.identify("myUserId", { email: "myUserId@example.com" });
|
|
285
|
+
await analytics.group("myGroupId", { name: "myGroupId" });
|
|
286
|
+
await analytics.page("myPage");
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
test("ip-policy", async ({ browser }) => {
|
|
290
|
+
clearRequestLog();
|
|
291
|
+
const browserContext = await browser.newContext();
|
|
292
|
+
const { page, uncaughtErrors } = await createLoggingPage(browserContext);
|
|
293
|
+
const [pageResult] = await Promise.all([page.goto(`${server.baseUrl}/ip-policy.html`)]);
|
|
294
|
+
await page.waitForFunction(() => window["jitsu"] !== undefined, undefined, {
|
|
295
|
+
timeout: 1000,
|
|
296
|
+
polling: 100,
|
|
297
|
+
});
|
|
298
|
+
expect(pageResult?.status()).toBe(200);
|
|
299
|
+
//wait for some time since the server has an artificial latency of 30ms
|
|
300
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
301
|
+
expect(uncaughtErrors.length).toEqual(0);
|
|
302
|
+
expect(requestLog.length).toBe(1);
|
|
303
|
+
const p = requestLog[0];
|
|
304
|
+
expect(p.headers?.["x-ip-policy"]).toEqual("stripLastOctet");
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
test("dont-send", async ({ browser }) => {
|
|
308
|
+
clearRequestLog();
|
|
309
|
+
const browserContext = await browser.newContext();
|
|
310
|
+
const { page, uncaughtErrors } = await createLoggingPage(browserContext);
|
|
311
|
+
const [pageResult] = await Promise.all([page.goto(`${server.baseUrl}/dont-send.html`)]);
|
|
312
|
+
await page.waitForFunction(() => window["jitsu"] !== undefined, undefined, {
|
|
313
|
+
timeout: 1000,
|
|
314
|
+
polling: 100,
|
|
315
|
+
});
|
|
316
|
+
expect(pageResult?.status()).toBe(200);
|
|
317
|
+
//wait for some time since the server has an artificial latency of 30ms
|
|
318
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
319
|
+
expect(uncaughtErrors.length).toEqual(0);
|
|
320
|
+
expect(requestLog.length).toBe(0);
|
|
321
|
+
await page.evaluate(generateEventsForConsentTests);
|
|
322
|
+
|
|
323
|
+
const cookies = await browserContext.cookies();
|
|
324
|
+
|
|
325
|
+
expect(uncaughtErrors.length).toEqual(0);
|
|
326
|
+
expect(requestLog.length).toBe(0);
|
|
327
|
+
expect(cookies.length).toBe(0);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
test("dont-send-then-consent", async ({ browser }) => {
|
|
331
|
+
clearRequestLog();
|
|
332
|
+
const browserContext = await browser.newContext();
|
|
333
|
+
const { page, uncaughtErrors } = await createLoggingPage(browserContext);
|
|
334
|
+
const [pageResult] = await Promise.all([page.goto(`${server.baseUrl}/dont-send.html`)]);
|
|
335
|
+
await page.waitForFunction(() => window["jitsu"] !== undefined, undefined, {
|
|
336
|
+
timeout: 1000,
|
|
337
|
+
polling: 100,
|
|
338
|
+
});
|
|
339
|
+
expect(pageResult?.status()).toBe(200);
|
|
340
|
+
//wait for some time since the server has an artificial latency of 30ms
|
|
341
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
342
|
+
expect(uncaughtErrors.length).toEqual(0);
|
|
343
|
+
expect(requestLog.length).toBe(0);
|
|
344
|
+
|
|
345
|
+
await page.evaluate(async () => {
|
|
346
|
+
const analytics = window["jitsu"] as AnalyticsInterface;
|
|
347
|
+
analytics.configure({
|
|
348
|
+
privacy: {
|
|
349
|
+
dontSend: false,
|
|
350
|
+
consentCategories: {
|
|
351
|
+
analytics: true,
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
await page.evaluate(generateEventsForConsentTests);
|
|
357
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
358
|
+
|
|
359
|
+
const cookies = await browserContext.cookies();
|
|
360
|
+
expect(uncaughtErrors.length).toEqual(0);
|
|
361
|
+
expect(requestLog.length).toBe(3);
|
|
362
|
+
expect(cookies.length).toBe(5);
|
|
363
|
+
const p = requestLog[2];
|
|
364
|
+
expect(p.type).toEqual("page");
|
|
365
|
+
expect(p.body.userId).toEqual("myUserId");
|
|
366
|
+
expect(p.body.groupId).toEqual("myGroupId");
|
|
367
|
+
expect(p.body.context?.traits?.email).toEqual("myUserId@example.com");
|
|
368
|
+
expect(p.body.context?.consent?.categoryPreferences).toEqual({ analytics: true });
|
|
369
|
+
expect((p.body.anonymousId ?? "").length).toBeGreaterThan(0);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
test("disable-user-ids", async ({ browser }) => {
|
|
373
|
+
clearRequestLog();
|
|
374
|
+
const browserContext = await browser.newContext();
|
|
375
|
+
const { page, uncaughtErrors } = await createLoggingPage(browserContext);
|
|
376
|
+
const [pageResult] = await Promise.all([page.goto(`${server.baseUrl}/disable-user-ids.html`)]);
|
|
377
|
+
await page.waitForFunction(() => window["jitsu"] !== undefined, undefined, {
|
|
378
|
+
timeout: 1000,
|
|
379
|
+
polling: 100,
|
|
380
|
+
});
|
|
381
|
+
expect(pageResult?.status()).toBe(200);
|
|
382
|
+
//wait for some time since the server has an artificial latency of 30ms
|
|
383
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
384
|
+
expect(uncaughtErrors.length).toEqual(0);
|
|
385
|
+
|
|
386
|
+
expect(requestLog.length).toBe(0);
|
|
387
|
+
await page.evaluate(generateEventsForConsentTests);
|
|
388
|
+
|
|
389
|
+
const cookies = await browserContext.cookies();
|
|
390
|
+
|
|
391
|
+
expect(uncaughtErrors.length).toEqual(0);
|
|
392
|
+
expect(cookies.length).toBe(0);
|
|
393
|
+
expect(requestLog.length).toBe(1);
|
|
394
|
+
const p = requestLog[0];
|
|
395
|
+
expect(p.type).toEqual("page");
|
|
396
|
+
expect(p.body.userId).toBeUndefined();
|
|
397
|
+
expect(p.body.groupId).toBeUndefined();
|
|
398
|
+
expect(p.body.context?.traits?.email).toBeUndefined();
|
|
399
|
+
expect(p.body.anonymousId).toBeUndefined();
|
|
400
|
+
expect(p.body.properties?.path).toBe("/disable-user-ids.html");
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
test("disable-user-ids-then-consent", async ({ browser }) => {
|
|
404
|
+
clearRequestLog();
|
|
405
|
+
const browserContext = await browser.newContext();
|
|
406
|
+
const { page, uncaughtErrors } = await createLoggingPage(browserContext);
|
|
407
|
+
const [pageResult] = await Promise.all([page.goto(`${server.baseUrl}/disable-user-ids.html`)]);
|
|
408
|
+
await page.waitForFunction(() => window["jitsu"] !== undefined, undefined, {
|
|
409
|
+
timeout: 1000,
|
|
410
|
+
polling: 100,
|
|
411
|
+
});
|
|
412
|
+
expect(pageResult?.status()).toBe(200);
|
|
413
|
+
//wait for some time since the server has an artificial latency of 30ms
|
|
414
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
415
|
+
expect(uncaughtErrors.length).toEqual(0);
|
|
416
|
+
expect(requestLog.length).toBe(0);
|
|
417
|
+
await page.evaluate(generateEventsForConsentTests);
|
|
418
|
+
let cookies = await browserContext.cookies();
|
|
419
|
+
expect(uncaughtErrors.length).toEqual(0);
|
|
420
|
+
expect(cookies.length).toBe(0);
|
|
421
|
+
expect(requestLog.length).toBe(1);
|
|
422
|
+
|
|
423
|
+
await page.evaluate(async () => {
|
|
424
|
+
const analytics = window["jitsu"] as AnalyticsInterface;
|
|
425
|
+
analytics.configure({
|
|
426
|
+
privacy: {
|
|
427
|
+
disableUserIds: false,
|
|
428
|
+
consentCategories: {
|
|
429
|
+
analytics: true,
|
|
430
|
+
},
|
|
431
|
+
},
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
await page.evaluate(generateEventsForConsentTests);
|
|
435
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
436
|
+
|
|
437
|
+
cookies = await browserContext.cookies();
|
|
438
|
+
expect(uncaughtErrors.length).toEqual(0);
|
|
439
|
+
expect(requestLog.length).toBe(4);
|
|
440
|
+
expect(cookies.length).toBe(5);
|
|
441
|
+
const p = requestLog[3];
|
|
442
|
+
expect(p.type).toEqual("page");
|
|
443
|
+
expect(p.body.userId).toEqual("myUserId");
|
|
444
|
+
expect(p.body.groupId).toEqual("myGroupId");
|
|
445
|
+
expect(p.body.context?.traits?.email).toEqual("myUserId@example.com");
|
|
446
|
+
expect(p.body.context?.consent?.categoryPreferences).toEqual({ analytics: true });
|
|
447
|
+
expect((p.body.anonymousId ?? "").length).toBeGreaterThan(0);
|
|
448
|
+
});
|
|
449
|
+
|
|
282
450
|
test("basic", async ({ browser }) => {
|
|
283
451
|
clearRequestLog();
|
|
284
452
|
const browserContext = await browser.newContext();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JitsuOptions, PersistentStorage, RuntimeFacade } from "
|
|
1
|
+
import { JitsuOptions, PersistentStorage, RuntimeFacade } from "@jitsu/protocols/analytics";
|
|
2
2
|
import { AnalyticsPlugin } from "analytics";
|
|
3
3
|
export declare const parseQuery: (qs?: string) => Record<string, string>;
|
|
4
4
|
export type StorageFactory = (cookieDomain: string, cookie2key: Record<string, string>) => PersistentStorage;
|
|
@@ -23,8 +23,6 @@ export type InternalPluginDescriptor = {
|
|
|
23
23
|
name: string;
|
|
24
24
|
};
|
|
25
25
|
export type DeviceOptions = AnalyticsPluginDescriptor | InternalPluginDescriptor;
|
|
26
|
-
export
|
|
27
|
-
storageWrapper?: (persistentStorage: PersistentStorage) => PersistentStorage;
|
|
28
|
-
};
|
|
29
|
-
export declare const jitsuAnalyticsPlugin: (pluginConfig?: JitsuPluginConfig) => AnalyticsPlugin;
|
|
26
|
+
export declare const jitsuAnalyticsPlugin: (jitsuOptions: JitsuOptions, storage: PersistentStorage) => AnalyticsPlugin;
|
|
30
27
|
export declare function randomId(hashString?: string | undefined): string;
|
|
28
|
+
export declare function uuid(): string;
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type { JitsuOptions } from "
|
|
1
|
+
import type { JitsuOptions } from "@jitsu/protocols/analytics";
|
|
2
2
|
export type JitsuBrowserOptions = {
|
|
3
3
|
namespace?: string;
|
|
4
|
-
userId?: string;
|
|
5
4
|
onload?: string;
|
|
6
5
|
initOnly?: boolean;
|
|
7
6
|
} & JitsuOptions;
|
|
8
|
-
export type Parser =
|
|
7
|
+
export type Parser = {
|
|
8
|
+
path?: (name: string) => string[];
|
|
9
|
+
parse: (arg: string) => any;
|
|
10
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AnalyticsInterface, JitsuOptions } from "
|
|
1
|
+
import { Callback, DispatchedEvent, ID, JSONObject, Options, AnalyticsInterface, JitsuOptions, PersistentStorage, RuntimeFacade, DynamicJitsuOptions } from "@jitsu/protocols/analytics";
|
|
2
2
|
export default function parse(input: any): any;
|
|
3
3
|
export declare const emptyAnalytics: AnalyticsInterface;
|
|
4
4
|
export declare function jitsuAnalytics(_opts: JitsuOptions): AnalyticsInterface;
|
|
5
|
-
export
|
|
5
|
+
export { Callback, DispatchedEvent, ID, JSONObject, Options, AnalyticsInterface, JitsuOptions, PersistentStorage, RuntimeFacade, DynamicJitsuOptions, };
|
|
6
6
|
export * from "./analytics-plugin";
|