@temps-sdk/react-analytics 0.0.1-beta.12 → 0.0.1-beta.14
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.
|
@@ -25,6 +25,7 @@ export declare class EngagementTracker {
|
|
|
25
25
|
private inactivityTimeout;
|
|
26
26
|
private engagementThreshold;
|
|
27
27
|
private isVisible;
|
|
28
|
+
private isFocused;
|
|
28
29
|
private isActive;
|
|
29
30
|
private heartbeatTimer;
|
|
30
31
|
private inactivityTimer;
|
|
@@ -36,6 +37,9 @@ export declare class EngagementTracker {
|
|
|
36
37
|
constructor(options?: EngagementTrackerOptions);
|
|
37
38
|
private setupEventListeners;
|
|
38
39
|
private handleVisibilityChange;
|
|
40
|
+
private handleFocus;
|
|
41
|
+
private handleBlur;
|
|
42
|
+
private pauseEngagement;
|
|
39
43
|
private handleUserActivity;
|
|
40
44
|
private resetInactivityTimer;
|
|
41
45
|
private updateEngagementTime;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EngagementTracker.d.ts","sourceRoot":"","sources":["../src/EngagementTracker.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;IAC7C,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;CAC9C;AAED,MAAM,WAAW,cAAc;IAC7B,uBAAuB,EAAE,MAAM,CAAC;IAChC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EA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B;IAClD,OAAO,CAAC,cAAc,CAAa;IACnC,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,cAAc,CAA+C;IACrE,OAAO,CAAC,eAAe,CAA8C;IACrE,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAiC;IAC9D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAiC;gBAElD,OAAO,GAAE,wBAA6B;IAsBlD,OAAO,CAAC,mBAAmB;IA6B3B,OAAO,CAAC,sBAAsB,CAW5B;IAEF,OAAO,CAAC,WAAW,CAEjB;IAEF,OAAO,CAAC,UAAU,CAIhB;IAEF,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,kBAAkB,CAexB;IAEF,OAAO,CAAC,oBAAoB;IAc5B,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,aAAa;YAOP,aAAa;IA+B3B,OAAO,CAAC,eAAe,CAyBrB;IAEF,OAAO,CAAC,gBAAgB,CAGtB;IAEF,OAAO,CAAC,iBAAiB;IAczB,OAAO,CAAC,KAAK;IAeN,OAAO,IAAI,IAAI;CAoBvB"}
|
|
@@ -17,15 +17,24 @@ export class EngagementTracker {
|
|
|
17
17
|
this.startHeartbeat();
|
|
18
18
|
}
|
|
19
19
|
else if (wasVisible && !this.isVisible) {
|
|
20
|
-
// Tab became hidden
|
|
21
|
-
this.
|
|
22
|
-
this.lastEngagementStart = null;
|
|
23
|
-
this.stopHeartbeat();
|
|
20
|
+
// Tab became hidden - pause engagement
|
|
21
|
+
this.pauseEngagement();
|
|
24
22
|
}
|
|
25
23
|
};
|
|
24
|
+
this.handleFocus = () => {
|
|
25
|
+
this.isFocused = true;
|
|
26
|
+
};
|
|
27
|
+
this.handleBlur = () => {
|
|
28
|
+
this.isFocused = false;
|
|
29
|
+
// When window loses focus, pause engagement tracking
|
|
30
|
+
this.pauseEngagement();
|
|
31
|
+
};
|
|
26
32
|
this.handleUserActivity = () => {
|
|
33
|
+
// Only track activity if tab is visible AND focused
|
|
34
|
+
if (!this.isVisible || !this.isFocused)
|
|
35
|
+
return;
|
|
27
36
|
const now = Date.now();
|
|
28
|
-
if (!this.isActive
|
|
37
|
+
if (!this.isActive) {
|
|
29
38
|
// Resume from inactive state
|
|
30
39
|
this.isActive = true;
|
|
31
40
|
this.lastEngagementStart = now;
|
|
@@ -72,6 +81,7 @@ export class EngagementTracker {
|
|
|
72
81
|
this.startTime = Date.now();
|
|
73
82
|
this.lastActivityTime = Date.now();
|
|
74
83
|
this.isVisible = document.visibilityState === "visible";
|
|
84
|
+
this.isFocused = document.hasFocus();
|
|
75
85
|
// Don't start engagement tracking until first user interaction
|
|
76
86
|
this.lastEngagementStart = null;
|
|
77
87
|
this.isActive = false;
|
|
@@ -81,8 +91,11 @@ export class EngagementTracker {
|
|
|
81
91
|
setupEventListeners() {
|
|
82
92
|
// Visibility change
|
|
83
93
|
document.addEventListener("visibilitychange", this.handleVisibilityChange);
|
|
84
|
-
//
|
|
85
|
-
|
|
94
|
+
// Focus/blur for better multi-monitor support
|
|
95
|
+
window.addEventListener("focus", this.handleFocus);
|
|
96
|
+
window.addEventListener("blur", this.handleBlur);
|
|
97
|
+
// User activity tracking - use more specific events to avoid false positives
|
|
98
|
+
const activityEvents = ["mousedown", "keypress", "scroll", "touchstart", "click"];
|
|
86
99
|
activityEvents.forEach(event => {
|
|
87
100
|
document.addEventListener(event, this.handleUserActivity, { passive: true });
|
|
88
101
|
});
|
|
@@ -98,6 +111,13 @@ export class EngagementTracker {
|
|
|
98
111
|
};
|
|
99
112
|
window.addEventListener("popstate", this.handleNavigation);
|
|
100
113
|
}
|
|
114
|
+
pauseEngagement() {
|
|
115
|
+
this.updateEngagementTime();
|
|
116
|
+
this.lastEngagementStart = null;
|
|
117
|
+
if (!this.isVisible) {
|
|
118
|
+
this.stopHeartbeat();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
101
121
|
resetInactivityTimer() {
|
|
102
122
|
if (this.inactivityTimer) {
|
|
103
123
|
clearTimeout(this.inactivityTimer);
|
|
@@ -120,6 +140,7 @@ export class EngagementTracker {
|
|
|
120
140
|
if (this.heartbeatTimer)
|
|
121
141
|
return;
|
|
122
142
|
this.heartbeatTimer = setInterval(() => {
|
|
143
|
+
// Only send heartbeat if tab is visible AND user has been active
|
|
123
144
|
if (this.isVisible && this.isActive) {
|
|
124
145
|
this.sendHeartbeat();
|
|
125
146
|
}
|
|
@@ -189,10 +210,12 @@ export class EngagementTracker {
|
|
|
189
210
|
clearTimeout(this.inactivityTimer);
|
|
190
211
|
}
|
|
191
212
|
document.removeEventListener("visibilitychange", this.handleVisibilityChange);
|
|
213
|
+
window.removeEventListener("focus", this.handleFocus);
|
|
214
|
+
window.removeEventListener("blur", this.handleBlur);
|
|
192
215
|
window.removeEventListener("pagehide", this.handlePageLeave);
|
|
193
216
|
window.removeEventListener("beforeunload", this.handlePageLeave);
|
|
194
217
|
window.removeEventListener("popstate", this.handleNavigation);
|
|
195
|
-
const activityEvents = ["mousedown", "
|
|
218
|
+
const activityEvents = ["mousedown", "keypress", "scroll", "touchstart", "click"];
|
|
196
219
|
activityEvents.forEach(event => {
|
|
197
220
|
document.removeEventListener(event, this.handleUserActivity);
|
|
198
221
|
});
|
package/dist/Provider.js
CHANGED
|
@@ -35,7 +35,7 @@ export function TempsAnalyticsProvider({ basePath = "/api/_temps", disabled = fa
|
|
|
35
35
|
if (!enabled)
|
|
36
36
|
return;
|
|
37
37
|
void sendAnalytics("event", {
|
|
38
|
-
event_name: "
|
|
38
|
+
event_name: "page_view",
|
|
39
39
|
request_query: window.location.search,
|
|
40
40
|
request_path: window.location.pathname,
|
|
41
41
|
domain: domain || window.location.hostname,
|