@dashgram/javascript 1.0.0 → 1.0.1
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/README.md +117 -174
- package/dist/core/config.d.ts +1 -0
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +5 -4
- package/dist/core/context.d.ts +4 -8
- package/dist/core/context.d.ts.map +1 -1
- package/dist/core/context.js +6 -17
- package/dist/core/event-queue.d.ts +4 -4
- package/dist/core/event-queue.d.ts.map +1 -1
- package/dist/dashgram.min.js +1 -0
- package/dist/errors.d.ts +0 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +0 -10
- package/dist/index.d.ts +3 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -32
- package/dist/trackers/base-tracker.d.ts +3 -3
- package/dist/trackers/base-tracker.d.ts.map +1 -1
- package/dist/trackers/base-tracker.js +1 -4
- package/dist/trackers/core-tracker.d.ts +3 -3
- package/dist/trackers/core-tracker.d.ts.map +1 -1
- package/dist/trackers/core-tracker.js +19 -21
- package/dist/trackers/deep-tracker.d.ts +6 -0
- package/dist/trackers/deep-tracker.d.ts.map +1 -1
- package/dist/trackers/deep-tracker.js +562 -12
- package/dist/trackers/interaction-tracker.d.ts +7 -3
- package/dist/trackers/interaction-tracker.d.ts.map +1 -1
- package/dist/trackers/interaction-tracker.js +142 -37
- package/dist/transport/batch-processor.d.ts +4 -4
- package/dist/transport/batch-processor.d.ts.map +1 -1
- package/dist/transport/batch-processor.js +8 -8
- package/dist/transport/transport.d.ts +4 -3
- package/dist/transport/transport.d.ts.map +1 -1
- package/dist/transport/transport.js +17 -24
- package/dist/types/index.d.ts +100 -25
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/device.d.ts +3 -7
- package/dist/utils/device.d.ts.map +1 -1
- package/dist/utils/device.js +19 -53
- package/dist/utils/telegram.d.ts +4 -6
- package/dist/utils/telegram.d.ts.map +1 -1
- package/dist/utils/telegram.js +45 -29
- package/package.json +5 -3
- package/dist/core/session.d.ts +0 -13
- package/dist/core/session.d.ts.map +0 -1
- package/dist/core/session.js +0 -63
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BaseTracker } from "./base-tracker";
|
|
2
2
|
import { throttle } from "../utils/helpers";
|
|
3
|
-
import { getScrollDepth } from "../utils/device";
|
|
4
3
|
import { subscribeToTelegramEvent } from "../utils/telegram";
|
|
5
4
|
export class DeepTracker extends BaseTracker {
|
|
6
5
|
constructor(config, trackCallback) {
|
|
@@ -9,6 +8,7 @@ export class DeepTracker extends BaseTracker {
|
|
|
9
8
|
this.observers = [];
|
|
10
9
|
this.clickTracker = new Map();
|
|
11
10
|
this.maxScrollDepth = 0;
|
|
11
|
+
this.trackedMedia = new WeakSet();
|
|
12
12
|
}
|
|
13
13
|
setup() {
|
|
14
14
|
if (typeof window === "undefined") {
|
|
@@ -19,6 +19,9 @@ export class DeepTracker extends BaseTracker {
|
|
|
19
19
|
this.setupRageClickTracking();
|
|
20
20
|
this.setupLongTaskTracking();
|
|
21
21
|
this.setupWebVitals();
|
|
22
|
+
this.setupNetworkTracking();
|
|
23
|
+
this.setupOrientationTracking();
|
|
24
|
+
this.setupMediaTracking();
|
|
22
25
|
this.setupTelegramTracking();
|
|
23
26
|
}
|
|
24
27
|
teardown() {
|
|
@@ -28,9 +31,20 @@ export class DeepTracker extends BaseTracker {
|
|
|
28
31
|
this.observers = [];
|
|
29
32
|
this.clickTracker.clear();
|
|
30
33
|
}
|
|
34
|
+
getScrollDepth() {
|
|
35
|
+
const windowHeight = window.innerHeight;
|
|
36
|
+
const documentHeight = document.documentElement.scrollHeight;
|
|
37
|
+
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
|
38
|
+
if (documentHeight <= windowHeight) {
|
|
39
|
+
return 100;
|
|
40
|
+
}
|
|
41
|
+
const maxScroll = documentHeight - windowHeight;
|
|
42
|
+
const scrollPercentage = (scrollTop / maxScroll) * 100;
|
|
43
|
+
return Math.min(Math.round(scrollPercentage), 100);
|
|
44
|
+
}
|
|
31
45
|
setupScrollTracking() {
|
|
32
46
|
const handleScroll = throttle(() => {
|
|
33
|
-
const depth = getScrollDepth();
|
|
47
|
+
const depth = this.getScrollDepth();
|
|
34
48
|
if (depth > this.maxScrollDepth) {
|
|
35
49
|
this.maxScrollDepth = depth;
|
|
36
50
|
const milestones = [25, 50, 75, 100];
|
|
@@ -218,24 +232,560 @@ export class DeepTracker extends BaseTracker {
|
|
|
218
232
|
this.log("CLS tracking not supported");
|
|
219
233
|
}
|
|
220
234
|
}
|
|
235
|
+
setupNetworkTracking() {
|
|
236
|
+
const handleOnline = () => {
|
|
237
|
+
this.track("network_status", {
|
|
238
|
+
status: "online",
|
|
239
|
+
effective_type: navigator.connection?.effectiveType,
|
|
240
|
+
downlink: navigator.connection?.downlink,
|
|
241
|
+
rtt: navigator.connection?.rtt
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
const handleOffline = () => {
|
|
245
|
+
this.track("network_status", {
|
|
246
|
+
status: "offline"
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
window.addEventListener("online", handleOnline);
|
|
250
|
+
window.addEventListener("offline", handleOffline);
|
|
251
|
+
this.unsubscribers.push(() => {
|
|
252
|
+
window.removeEventListener("online", handleOnline);
|
|
253
|
+
window.removeEventListener("offline", handleOffline);
|
|
254
|
+
});
|
|
255
|
+
const connection = navigator.connection;
|
|
256
|
+
if (connection) {
|
|
257
|
+
const handleConnectionChange = () => {
|
|
258
|
+
this.track("network_change", {
|
|
259
|
+
effective_type: connection.effectiveType,
|
|
260
|
+
downlink: connection.downlink,
|
|
261
|
+
rtt: connection.rtt,
|
|
262
|
+
save_data: connection.saveData
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
connection.addEventListener("change", handleConnectionChange);
|
|
266
|
+
this.unsubscribers.push(() => {
|
|
267
|
+
connection.removeEventListener("change", handleConnectionChange);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
setupOrientationTracking() {
|
|
272
|
+
const handleOrientationChange = () => {
|
|
273
|
+
const orientation = screen.orientation?.type || (window.innerWidth > window.innerHeight ? "landscape" : "portrait");
|
|
274
|
+
this.track("orientation_change", {
|
|
275
|
+
orientation: orientation,
|
|
276
|
+
angle: screen.orientation?.angle,
|
|
277
|
+
width: window.innerWidth,
|
|
278
|
+
height: window.innerHeight
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
if (screen.orientation) {
|
|
282
|
+
screen.orientation.addEventListener("change", handleOrientationChange);
|
|
283
|
+
this.unsubscribers.push(() => {
|
|
284
|
+
screen.orientation.removeEventListener("change", handleOrientationChange);
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
window.addEventListener("orientationchange", handleOrientationChange);
|
|
289
|
+
this.unsubscribers.push(() => {
|
|
290
|
+
window.removeEventListener("orientationchange", handleOrientationChange);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
setupMediaTracking() {
|
|
295
|
+
const trackMediaEvent = (event) => {
|
|
296
|
+
const media = event.target;
|
|
297
|
+
if (!media || this.trackedMedia.has(media))
|
|
298
|
+
return;
|
|
299
|
+
const mediaType = media.tagName.toLowerCase();
|
|
300
|
+
const eventType = event.type;
|
|
301
|
+
const baseProps = {
|
|
302
|
+
media_type: mediaType,
|
|
303
|
+
src: media.currentSrc || media.src,
|
|
304
|
+
duration: isFinite(media.duration) ? Math.round(media.duration) : undefined,
|
|
305
|
+
current_time: Math.round(media.currentTime),
|
|
306
|
+
muted: media.muted,
|
|
307
|
+
volume: Math.round(media.volume * 100)
|
|
308
|
+
};
|
|
309
|
+
if (eventType === "play") {
|
|
310
|
+
this.track("media_play", baseProps);
|
|
311
|
+
}
|
|
312
|
+
else if (eventType === "pause") {
|
|
313
|
+
this.track("media_pause", {
|
|
314
|
+
...baseProps,
|
|
315
|
+
percent_played: media.duration ? Math.round((media.currentTime / media.duration) * 100) : 0
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
else if (eventType === "ended") {
|
|
319
|
+
this.track("media_ended", {
|
|
320
|
+
...baseProps,
|
|
321
|
+
completed: true
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
else if (eventType === "error") {
|
|
325
|
+
this.track("media_error", {
|
|
326
|
+
media_type: mediaType,
|
|
327
|
+
src: media.currentSrc || media.src,
|
|
328
|
+
error: media.error?.message || "unknown"
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
const setupMediaElement = (media) => {
|
|
333
|
+
if (this.trackedMedia.has(media))
|
|
334
|
+
return;
|
|
335
|
+
this.trackedMedia.add(media);
|
|
336
|
+
media.addEventListener("play", trackMediaEvent);
|
|
337
|
+
media.addEventListener("pause", trackMediaEvent);
|
|
338
|
+
media.addEventListener("ended", trackMediaEvent);
|
|
339
|
+
media.addEventListener("error", trackMediaEvent);
|
|
340
|
+
};
|
|
341
|
+
document.querySelectorAll("video, audio").forEach(media => {
|
|
342
|
+
setupMediaElement(media);
|
|
343
|
+
});
|
|
344
|
+
const observer = new MutationObserver(mutations => {
|
|
345
|
+
mutations.forEach(mutation => {
|
|
346
|
+
mutation.addedNodes.forEach(node => {
|
|
347
|
+
if (node instanceof HTMLMediaElement) {
|
|
348
|
+
setupMediaElement(node);
|
|
349
|
+
}
|
|
350
|
+
if (node instanceof Element) {
|
|
351
|
+
node.querySelectorAll("video, audio").forEach(media => {
|
|
352
|
+
setupMediaElement(media);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
observer.observe(document.body, {
|
|
359
|
+
childList: true,
|
|
360
|
+
subtree: true
|
|
361
|
+
});
|
|
362
|
+
this.observers.push(observer);
|
|
363
|
+
}
|
|
221
364
|
setupTelegramTracking() {
|
|
365
|
+
const webApp = window.Telegram?.WebApp;
|
|
366
|
+
const trackEvent = (eventName, data) => {
|
|
367
|
+
this.track(`telegram_${eventName}`, data || {});
|
|
368
|
+
};
|
|
222
369
|
const unsubTheme = subscribeToTelegramEvent("themeChanged", () => {
|
|
223
|
-
|
|
370
|
+
trackEvent("theme_changed", {
|
|
371
|
+
color_scheme: webApp?.colorScheme,
|
|
372
|
+
theme_params: webApp?.themeParams
|
|
373
|
+
});
|
|
224
374
|
});
|
|
225
375
|
this.unsubscribers.push(unsubTheme);
|
|
226
|
-
const unsubViewport = subscribeToTelegramEvent("viewportChanged", () => {
|
|
227
|
-
|
|
228
|
-
|
|
376
|
+
const unsubViewport = subscribeToTelegramEvent("viewportChanged", (eventData) => {
|
|
377
|
+
trackEvent("viewport_changed", {
|
|
378
|
+
is_state_stable: eventData?.isStateStable,
|
|
379
|
+
is_expanded: webApp?.isExpanded,
|
|
380
|
+
viewport_height: webApp?.viewportHeight,
|
|
381
|
+
viewport_stable_height: webApp?.viewportStableHeight
|
|
229
382
|
});
|
|
230
383
|
});
|
|
231
384
|
this.unsubscribers.push(unsubViewport);
|
|
232
|
-
const
|
|
233
|
-
|
|
385
|
+
const unsubSafeArea = subscribeToTelegramEvent("safeAreaChanged", () => {
|
|
386
|
+
trackEvent("safe_area_changed", {
|
|
387
|
+
safe_area: webApp?.safeAreaInset
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
this.unsubscribers.push(unsubSafeArea);
|
|
391
|
+
const unsubContentSafeArea = subscribeToTelegramEvent("contentSafeAreaChanged", () => {
|
|
392
|
+
trackEvent("content_safe_area_changed", {
|
|
393
|
+
content_safe_area: webApp?.contentSafeAreaInset
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
this.unsubscribers.push(unsubContentSafeArea);
|
|
397
|
+
const unsubBackButton = subscribeToTelegramEvent("backButtonClicked", () => {
|
|
398
|
+
trackEvent("back_button_clicked", {});
|
|
399
|
+
});
|
|
400
|
+
this.unsubscribers.push(unsubBackButton);
|
|
401
|
+
const unsubMainButton = subscribeToTelegramEvent("mainButtonClicked", () => {
|
|
402
|
+
trackEvent("main_button_clicked", {
|
|
403
|
+
button_text: webApp?.MainButton?.text
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
this.unsubscribers.push(unsubMainButton);
|
|
407
|
+
const unsubInvoice = subscribeToTelegramEvent("invoiceClosed", (eventData) => {
|
|
408
|
+
trackEvent("invoice_closed", {
|
|
409
|
+
url: eventData?.url,
|
|
410
|
+
status: eventData?.status
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
this.unsubscribers.push(unsubInvoice);
|
|
414
|
+
const unsubPopup = subscribeToTelegramEvent("popupClosed", (eventData) => {
|
|
415
|
+
trackEvent("popup_closed", {
|
|
416
|
+
button_id: eventData?.button_id
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
this.unsubscribers.push(unsubPopup);
|
|
420
|
+
const unsubQrText = subscribeToTelegramEvent("qrTextReceived", (eventData) => {
|
|
421
|
+
trackEvent("qr_text_received", {
|
|
422
|
+
data: eventData?.data
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
this.unsubscribers.push(unsubQrText);
|
|
426
|
+
const unsubScanQr = subscribeToTelegramEvent("scanQrPopupClosed", () => {
|
|
427
|
+
trackEvent("scan_qr_popup_closed", {});
|
|
428
|
+
});
|
|
429
|
+
this.unsubscribers.push(unsubScanQr);
|
|
430
|
+
const unsubClipboard = subscribeToTelegramEvent("clipboardTextReceived", (eventData) => {
|
|
431
|
+
trackEvent("clipboard_text_received", {
|
|
432
|
+
data: eventData?.data
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
this.unsubscribers.push(unsubClipboard);
|
|
436
|
+
const unsubWriteAccess = subscribeToTelegramEvent("writeAccessRequested", (eventData) => {
|
|
437
|
+
trackEvent("write_access_requested", {
|
|
438
|
+
status: eventData?.status
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
this.unsubscribers.push(unsubWriteAccess);
|
|
442
|
+
const unsubFileDownload = subscribeToTelegramEvent("fileDownloadRequested", (eventData) => {
|
|
443
|
+
trackEvent("file_download_requested", {
|
|
444
|
+
status: eventData?.status
|
|
445
|
+
});
|
|
446
|
+
});
|
|
447
|
+
this.unsubscribers.push(unsubFileDownload);
|
|
448
|
+
const unsubCustomMethod = subscribeToTelegramEvent("customMethodInvoked", (eventData) => {
|
|
449
|
+
trackEvent("custom_method_invoked", {
|
|
450
|
+
req_id: eventData?.req_id,
|
|
451
|
+
result: eventData?.result,
|
|
452
|
+
error: eventData?.error
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
this.unsubscribers.push(unsubCustomMethod);
|
|
456
|
+
const unsubFullscreen = subscribeToTelegramEvent("fullscreenChanged", (eventData) => {
|
|
457
|
+
trackEvent("fullscreen_changed", {
|
|
458
|
+
is_fullscreen: eventData?.isFullscreen
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
this.unsubscribers.push(unsubFullscreen);
|
|
462
|
+
const unsubFullscreenFailed = subscribeToTelegramEvent("fullscreenFailed", (eventData) => {
|
|
463
|
+
trackEvent("fullscreen_failed", {
|
|
464
|
+
error: eventData?.error
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
this.unsubscribers.push(unsubFullscreenFailed);
|
|
468
|
+
const unsubHomeScreenAdded = subscribeToTelegramEvent("homeScreenAdded", () => {
|
|
469
|
+
trackEvent("home_screen_added", {});
|
|
470
|
+
});
|
|
471
|
+
this.unsubscribers.push(unsubHomeScreenAdded);
|
|
472
|
+
const unsubHomeScreenChecked = subscribeToTelegramEvent("homeScreenChecked", (eventData) => {
|
|
473
|
+
trackEvent("home_screen_checked", {
|
|
474
|
+
status: eventData?.status
|
|
475
|
+
});
|
|
234
476
|
});
|
|
235
|
-
this.unsubscribers.push(
|
|
236
|
-
const
|
|
237
|
-
|
|
477
|
+
this.unsubscribers.push(unsubHomeScreenChecked);
|
|
478
|
+
const unsubPreparedMessageSent = subscribeToTelegramEvent("preparedMessageSent", () => {
|
|
479
|
+
trackEvent("prepared_message_sent", {});
|
|
238
480
|
});
|
|
239
|
-
this.unsubscribers.push(
|
|
481
|
+
this.unsubscribers.push(unsubPreparedMessageSent);
|
|
482
|
+
const unsubPreparedMessageFailed = subscribeToTelegramEvent("preparedMessageFailed", (eventData) => {
|
|
483
|
+
trackEvent("prepared_message_failed", {
|
|
484
|
+
error: eventData?.error
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
this.unsubscribers.push(unsubPreparedMessageFailed);
|
|
488
|
+
const unsubEmojiStatusSet = subscribeToTelegramEvent("emojiStatusSet", () => {
|
|
489
|
+
trackEvent("emoji_status_set", {});
|
|
490
|
+
});
|
|
491
|
+
this.unsubscribers.push(unsubEmojiStatusSet);
|
|
492
|
+
const unsubEmojiStatusFailed = subscribeToTelegramEvent("emojiStatusFailed", (eventData) => {
|
|
493
|
+
trackEvent("emoji_status_failed", {
|
|
494
|
+
error: eventData?.error
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
this.unsubscribers.push(unsubEmojiStatusFailed);
|
|
498
|
+
const unsubEmojiStatusAccess = subscribeToTelegramEvent("emojiStatusAccessRequested", (eventData) => {
|
|
499
|
+
trackEvent("emoji_status_access_requested", {
|
|
500
|
+
status: eventData?.status
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
this.unsubscribers.push(unsubEmojiStatusAccess);
|
|
504
|
+
const unsubSettingsButton = subscribeToTelegramEvent("settingsButtonClicked", () => {
|
|
505
|
+
trackEvent("settings_button_clicked", {});
|
|
506
|
+
});
|
|
507
|
+
this.unsubscribers.push(unsubSettingsButton);
|
|
508
|
+
const unsubSecondaryButton = subscribeToTelegramEvent("secondaryButtonClicked", () => {
|
|
509
|
+
trackEvent("secondary_button_clicked", {});
|
|
510
|
+
});
|
|
511
|
+
this.unsubscribers.push(unsubSecondaryButton);
|
|
512
|
+
const unsubShareMessageSent = subscribeToTelegramEvent("shareMessageSent", () => {
|
|
513
|
+
trackEvent("share_message_sent", {});
|
|
514
|
+
});
|
|
515
|
+
this.unsubscribers.push(unsubShareMessageSent);
|
|
516
|
+
const unsubShareMessageFailed = subscribeToTelegramEvent("shareMessageFailed", (eventData) => {
|
|
517
|
+
trackEvent("share_message_failed", {
|
|
518
|
+
error: eventData?.error
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
this.unsubscribers.push(unsubShareMessageFailed);
|
|
522
|
+
const unsubLocationManager = subscribeToTelegramEvent("locationManagerUpdated", () => {
|
|
523
|
+
const locationManager = webApp?.LocationManager;
|
|
524
|
+
trackEvent("location_manager_updated", {
|
|
525
|
+
is_inited: locationManager?.isInited,
|
|
526
|
+
is_location_available: locationManager?.isLocationAvailable,
|
|
527
|
+
is_access_requested: locationManager?.isAccessRequested,
|
|
528
|
+
is_access_granted: locationManager?.isAccessGranted
|
|
529
|
+
});
|
|
530
|
+
});
|
|
531
|
+
this.unsubscribers.push(unsubLocationManager);
|
|
532
|
+
const unsubLocationRequested = subscribeToTelegramEvent("locationRequested", (eventData) => {
|
|
533
|
+
trackEvent("location_requested", {
|
|
534
|
+
available: eventData?.available !== false,
|
|
535
|
+
latitude: eventData?.latitude,
|
|
536
|
+
longitude: eventData?.longitude,
|
|
537
|
+
altitude: eventData?.altitude,
|
|
538
|
+
course: eventData?.course,
|
|
539
|
+
speed: eventData?.speed,
|
|
540
|
+
horizontal_accuracy: eventData?.horizontal_accuracy,
|
|
541
|
+
vertical_accuracy: eventData?.vertical_accuracy,
|
|
542
|
+
course_accuracy: eventData?.course_accuracy,
|
|
543
|
+
speed_accuracy: eventData?.speed_accuracy
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
this.unsubscribers.push(unsubLocationRequested);
|
|
547
|
+
const unsubAccelerometerStarted = subscribeToTelegramEvent("accelerometerStarted", () => {
|
|
548
|
+
trackEvent("accelerometer_started", {});
|
|
549
|
+
});
|
|
550
|
+
this.unsubscribers.push(unsubAccelerometerStarted);
|
|
551
|
+
const unsubAccelerometerStopped = subscribeToTelegramEvent("accelerometerStopped", () => {
|
|
552
|
+
trackEvent("accelerometer_stopped", {});
|
|
553
|
+
});
|
|
554
|
+
this.unsubscribers.push(unsubAccelerometerStopped);
|
|
555
|
+
const unsubAccelerometerChanged = subscribeToTelegramEvent("accelerometerChanged", () => {
|
|
556
|
+
const accelerometer = webApp?.Accelerometer;
|
|
557
|
+
trackEvent("accelerometer_changed", {
|
|
558
|
+
x: accelerometer?.x,
|
|
559
|
+
y: accelerometer?.y,
|
|
560
|
+
z: accelerometer?.z
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
this.unsubscribers.push(unsubAccelerometerChanged);
|
|
564
|
+
const unsubAccelerometerFailed = subscribeToTelegramEvent("accelerometerFailed", (eventData) => {
|
|
565
|
+
trackEvent("accelerometer_failed", {
|
|
566
|
+
error: eventData?.error
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
this.unsubscribers.push(unsubAccelerometerFailed);
|
|
570
|
+
const unsubDeviceOrientationStarted = subscribeToTelegramEvent("deviceOrientationStarted", () => {
|
|
571
|
+
trackEvent("device_orientation_started", {});
|
|
572
|
+
});
|
|
573
|
+
this.unsubscribers.push(unsubDeviceOrientationStarted);
|
|
574
|
+
const unsubDeviceOrientationStopped = subscribeToTelegramEvent("deviceOrientationStopped", () => {
|
|
575
|
+
trackEvent("device_orientation_stopped", {});
|
|
576
|
+
});
|
|
577
|
+
this.unsubscribers.push(unsubDeviceOrientationStopped);
|
|
578
|
+
const unsubDeviceOrientationChanged = subscribeToTelegramEvent("deviceOrientationChanged", () => {
|
|
579
|
+
const deviceOrientation = webApp?.DeviceOrientation;
|
|
580
|
+
trackEvent("device_orientation_changed", {
|
|
581
|
+
absolute: deviceOrientation?.absolute,
|
|
582
|
+
alpha: deviceOrientation?.alpha,
|
|
583
|
+
beta: deviceOrientation?.beta,
|
|
584
|
+
gamma: deviceOrientation?.gamma
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
this.unsubscribers.push(unsubDeviceOrientationChanged);
|
|
588
|
+
const unsubDeviceOrientationFailed = subscribeToTelegramEvent("deviceOrientationFailed", (eventData) => {
|
|
589
|
+
trackEvent("device_orientation_failed", {
|
|
590
|
+
error: eventData?.error
|
|
591
|
+
});
|
|
592
|
+
});
|
|
593
|
+
this.unsubscribers.push(unsubDeviceOrientationFailed);
|
|
594
|
+
const unsubGyroscopeStarted = subscribeToTelegramEvent("gyroscopeStarted", () => {
|
|
595
|
+
trackEvent("gyroscope_started", {});
|
|
596
|
+
});
|
|
597
|
+
this.unsubscribers.push(unsubGyroscopeStarted);
|
|
598
|
+
const unsubGyroscopeStopped = subscribeToTelegramEvent("gyroscopeStopped", () => {
|
|
599
|
+
trackEvent("gyroscope_stopped", {});
|
|
600
|
+
});
|
|
601
|
+
this.unsubscribers.push(unsubGyroscopeStopped);
|
|
602
|
+
const unsubGyroscopeChanged = subscribeToTelegramEvent("gyroscopeChanged", () => {
|
|
603
|
+
const gyroscope = webApp?.Gyroscope;
|
|
604
|
+
trackEvent("gyroscope_changed", {
|
|
605
|
+
x: gyroscope?.x,
|
|
606
|
+
y: gyroscope?.y,
|
|
607
|
+
z: gyroscope?.z
|
|
608
|
+
});
|
|
609
|
+
});
|
|
610
|
+
this.unsubscribers.push(unsubGyroscopeChanged);
|
|
611
|
+
const unsubGyroscopeFailed = subscribeToTelegramEvent("gyroscopeFailed", (eventData) => {
|
|
612
|
+
trackEvent("gyroscope_failed", {
|
|
613
|
+
error: eventData?.error
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
this.unsubscribers.push(unsubGyroscopeFailed);
|
|
617
|
+
const unsubContactRequested = subscribeToTelegramEvent("contactRequested", (eventData) => {
|
|
618
|
+
trackEvent("contact_requested", {
|
|
619
|
+
status: eventData?.status
|
|
620
|
+
});
|
|
621
|
+
});
|
|
622
|
+
this.unsubscribers.push(unsubContactRequested);
|
|
623
|
+
const unsubActivated = subscribeToTelegramEvent("activated", () => {
|
|
624
|
+
trackEvent("activated", {});
|
|
625
|
+
});
|
|
626
|
+
this.unsubscribers.push(unsubActivated);
|
|
627
|
+
const unsubDeactivated = subscribeToTelegramEvent("deactivated", () => {
|
|
628
|
+
trackEvent("deactivated", {});
|
|
629
|
+
});
|
|
630
|
+
this.unsubscribers.push(unsubDeactivated);
|
|
631
|
+
const unsubBiometricManager = subscribeToTelegramEvent("biometricManagerUpdated", () => {
|
|
632
|
+
const biometricManager = webApp?.BiometricManager;
|
|
633
|
+
trackEvent("biometric_manager_updated", {
|
|
634
|
+
is_inited: biometricManager?.isInited,
|
|
635
|
+
is_biometric_available: biometricManager?.isBiometricAvailable,
|
|
636
|
+
biometric_type: biometricManager?.biometricType,
|
|
637
|
+
is_access_requested: biometricManager?.isAccessRequested,
|
|
638
|
+
is_access_granted: biometricManager?.isAccessGranted,
|
|
639
|
+
is_biometric_token_saved: biometricManager?.isBiometricTokenSaved,
|
|
640
|
+
device_id: biometricManager?.deviceId
|
|
641
|
+
});
|
|
642
|
+
});
|
|
643
|
+
this.unsubscribers.push(unsubBiometricManager);
|
|
644
|
+
const unsubBiometricAuth = subscribeToTelegramEvent("biometricAuthRequested", (eventData) => {
|
|
645
|
+
trackEvent("biometric_auth_requested", {
|
|
646
|
+
is_authenticated: eventData?.isAuthenticated,
|
|
647
|
+
biometric_token: eventData?.biometricToken
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
this.unsubscribers.push(unsubBiometricAuth);
|
|
651
|
+
const unsubBiometricToken = subscribeToTelegramEvent("biometricTokenUpdated", (eventData) => {
|
|
652
|
+
trackEvent("biometric_token_updated", {
|
|
653
|
+
is_updated: eventData?.isUpdated
|
|
654
|
+
});
|
|
655
|
+
});
|
|
656
|
+
this.unsubscribers.push(unsubBiometricToken);
|
|
657
|
+
this.patchWebAppMethods(webApp, trackEvent);
|
|
658
|
+
}
|
|
659
|
+
patchWebAppMethods(webApp, trackEvent) {
|
|
660
|
+
if (!webApp)
|
|
661
|
+
return;
|
|
662
|
+
if (webApp.openLink?._dashgramPatched) {
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
if (webApp.openLink && typeof webApp.openLink === "function") {
|
|
666
|
+
const originalOpenLink = webApp.openLink.bind(webApp);
|
|
667
|
+
const patchedOpenLink = (url, options) => {
|
|
668
|
+
trackEvent("open_link", {
|
|
669
|
+
url: url,
|
|
670
|
+
options: options
|
|
671
|
+
});
|
|
672
|
+
return originalOpenLink(url, options);
|
|
673
|
+
};
|
|
674
|
+
patchedOpenLink._dashgramPatched = true;
|
|
675
|
+
webApp.openLink = patchedOpenLink;
|
|
676
|
+
}
|
|
677
|
+
if (webApp.openTelegramLink && typeof webApp.openTelegramLink === "function") {
|
|
678
|
+
const originalOpenTelegramLink = webApp.openTelegramLink.bind(webApp);
|
|
679
|
+
const patchedOpenTelegramLink = (url) => {
|
|
680
|
+
trackEvent("open_telegram_link", {
|
|
681
|
+
url: url
|
|
682
|
+
});
|
|
683
|
+
return originalOpenTelegramLink(url);
|
|
684
|
+
};
|
|
685
|
+
patchedOpenTelegramLink._dashgramPatched = true;
|
|
686
|
+
webApp.openTelegramLink = patchedOpenTelegramLink;
|
|
687
|
+
}
|
|
688
|
+
if (webApp.switchInlineQuery && typeof webApp.switchInlineQuery === "function") {
|
|
689
|
+
const originalSwitchInlineQuery = webApp.switchInlineQuery.bind(webApp);
|
|
690
|
+
const patchedSwitchInlineQuery = (query, chooseChatTypes) => {
|
|
691
|
+
trackEvent("switch_inline_query", {
|
|
692
|
+
query: query,
|
|
693
|
+
choose_chat_types: chooseChatTypes
|
|
694
|
+
});
|
|
695
|
+
return originalSwitchInlineQuery(query, chooseChatTypes);
|
|
696
|
+
};
|
|
697
|
+
patchedSwitchInlineQuery._dashgramPatched = true;
|
|
698
|
+
webApp.switchInlineQuery = patchedSwitchInlineQuery;
|
|
699
|
+
}
|
|
700
|
+
if (webApp.shareToStory && typeof webApp.shareToStory === "function") {
|
|
701
|
+
const originalShareToStory = webApp.shareToStory.bind(webApp);
|
|
702
|
+
const patchedShareToStory = (mediaUrl, params) => {
|
|
703
|
+
trackEvent("share_story", {
|
|
704
|
+
media_url: mediaUrl,
|
|
705
|
+
params: params
|
|
706
|
+
});
|
|
707
|
+
return originalShareToStory(mediaUrl, params);
|
|
708
|
+
};
|
|
709
|
+
patchedShareToStory._dashgramPatched = true;
|
|
710
|
+
webApp.shareToStory = patchedShareToStory;
|
|
711
|
+
}
|
|
712
|
+
if (webApp.close && typeof webApp.close === "function") {
|
|
713
|
+
const originalClose = webApp.close.bind(webApp);
|
|
714
|
+
const patchedClose = (options) => {
|
|
715
|
+
trackEvent("webapp_close", {
|
|
716
|
+
return_back: options?.return_back
|
|
717
|
+
});
|
|
718
|
+
return originalClose(options);
|
|
719
|
+
};
|
|
720
|
+
patchedClose._dashgramPatched = true;
|
|
721
|
+
webApp.close = patchedClose;
|
|
722
|
+
}
|
|
723
|
+
if (webApp.exitFullscreen && typeof webApp.exitFullscreen === "function") {
|
|
724
|
+
const originalExitFullscreen = webApp.exitFullscreen.bind(webApp);
|
|
725
|
+
const patchedExitFullscreen = () => {
|
|
726
|
+
trackEvent("webapp_exit_fullscreen", {});
|
|
727
|
+
return originalExitFullscreen();
|
|
728
|
+
};
|
|
729
|
+
patchedExitFullscreen._dashgramPatched = true;
|
|
730
|
+
webApp.exitFullscreen = patchedExitFullscreen;
|
|
731
|
+
}
|
|
732
|
+
if (webApp.openInvoice && typeof webApp.openInvoice === "function") {
|
|
733
|
+
const originalOpenInvoice = webApp.openInvoice.bind(webApp);
|
|
734
|
+
const patchedOpenInvoice = (slug, callback) => {
|
|
735
|
+
trackEvent("open_invoice", {
|
|
736
|
+
slug: slug
|
|
737
|
+
});
|
|
738
|
+
return originalOpenInvoice(slug, callback);
|
|
739
|
+
};
|
|
740
|
+
patchedOpenInvoice._dashgramPatched = true;
|
|
741
|
+
webApp.openInvoice = patchedOpenInvoice;
|
|
742
|
+
}
|
|
743
|
+
if (webApp.requestAccess && typeof webApp.requestAccess === "function") {
|
|
744
|
+
const originalRequestAccess = webApp.requestAccess.bind(webApp);
|
|
745
|
+
const patchedRequestAccess = (accessType, callback) => {
|
|
746
|
+
trackEvent("request_access", {
|
|
747
|
+
access_type: accessType
|
|
748
|
+
});
|
|
749
|
+
return originalRequestAccess(accessType, callback);
|
|
750
|
+
};
|
|
751
|
+
patchedRequestAccess._dashgramPatched = true;
|
|
752
|
+
webApp.requestAccess = patchedRequestAccess;
|
|
753
|
+
}
|
|
754
|
+
if (webApp.requestContact && typeof webApp.requestContact === "function") {
|
|
755
|
+
const originalRequestContact = webApp.requestContact.bind(webApp);
|
|
756
|
+
const patchedRequestContact = (callback) => {
|
|
757
|
+
trackEvent("request_contact", {});
|
|
758
|
+
return originalRequestContact(callback);
|
|
759
|
+
};
|
|
760
|
+
patchedRequestContact._dashgramPatched = true;
|
|
761
|
+
webApp.requestContact = patchedRequestContact;
|
|
762
|
+
}
|
|
763
|
+
if (webApp.requestPhone && typeof webApp.requestPhone === "function") {
|
|
764
|
+
const originalRequestPhone = webApp.requestPhone.bind(webApp);
|
|
765
|
+
const patchedRequestPhone = (callback) => {
|
|
766
|
+
trackEvent("request_phone", {});
|
|
767
|
+
return originalRequestPhone(callback);
|
|
768
|
+
};
|
|
769
|
+
patchedRequestPhone._dashgramPatched = true;
|
|
770
|
+
webApp.requestPhone = patchedRequestPhone;
|
|
771
|
+
}
|
|
772
|
+
if (webApp.requestLocation && typeof webApp.requestLocation === "function") {
|
|
773
|
+
const originalRequestLocation = webApp.requestLocation.bind(webApp);
|
|
774
|
+
const patchedRequestLocation = (callback) => {
|
|
775
|
+
trackEvent("request_location", {});
|
|
776
|
+
return originalRequestLocation(callback);
|
|
777
|
+
};
|
|
778
|
+
patchedRequestLocation._dashgramPatched = true;
|
|
779
|
+
webApp.requestLocation = patchedRequestLocation;
|
|
780
|
+
}
|
|
781
|
+
if (webApp.checkLocation && typeof webApp.checkLocation === "function") {
|
|
782
|
+
const originalCheckLocation = webApp.checkLocation.bind(webApp);
|
|
783
|
+
const patchedCheckLocation = (callback) => {
|
|
784
|
+
trackEvent("check_location", {});
|
|
785
|
+
return originalCheckLocation(callback);
|
|
786
|
+
};
|
|
787
|
+
patchedCheckLocation._dashgramPatched = true;
|
|
788
|
+
webApp.checkLocation = patchedCheckLocation;
|
|
789
|
+
}
|
|
240
790
|
}
|
|
241
791
|
}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { BaseTracker } from
|
|
2
|
-
import type { Config } from
|
|
3
|
-
import type { TrackCallback } from
|
|
1
|
+
import { BaseTracker } from "./base-tracker";
|
|
2
|
+
import type { Config } from "../core/config";
|
|
3
|
+
import type { TrackCallback } from "./base-tracker";
|
|
4
4
|
export declare class InteractionTracker extends BaseTracker {
|
|
5
5
|
private unsubscribers;
|
|
6
6
|
private lastPath;
|
|
7
|
+
private inputValues;
|
|
7
8
|
constructor(config: Config, trackCallback: TrackCallback);
|
|
8
9
|
protected setup(): void;
|
|
9
10
|
protected teardown(): void;
|
|
10
11
|
private trackScreenView;
|
|
11
12
|
private setupHistoryTracking;
|
|
12
13
|
private setupClickTracking;
|
|
14
|
+
private isExternalLink;
|
|
13
15
|
private setupFormTracking;
|
|
14
16
|
private setupInputTracking;
|
|
17
|
+
private setupClipboardTracking;
|
|
18
|
+
private setupSelectionTracking;
|
|
15
19
|
private setupErrorTracking;
|
|
16
20
|
}
|
|
17
21
|
//# sourceMappingURL=interaction-tracker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interaction-tracker.d.ts","sourceRoot":"","sources":["../../src/trackers/interaction-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"interaction-tracker.d.ts","sourceRoot":"","sources":["../../src/trackers/interaction-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAUnD,qBAAa,kBAAmB,SAAQ,WAAW;IACjD,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,WAAW,CAAiC;gBAExC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa;IAIxD,SAAS,CAAC,KAAK,IAAI,IAAI;IAkBvB,SAAS,CAAC,QAAQ,IAAI,IAAI;IAQ1B,OAAO,CAAC,eAAe;IAoBvB,OAAO,CAAC,oBAAoB;IAgC5B,OAAO,CAAC,kBAAkB;IA4C1B,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,iBAAiB;IAuBzB,OAAO,CAAC,kBAAkB;IA8D1B,OAAO,CAAC,sBAAsB;IA6C9B,OAAO,CAAC,sBAAsB;IA6B9B,OAAO,CAAC,kBAAkB;CAgC3B"}
|