@usereq/widget 0.1.5 → 0.1.6

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": "@usereq/widget",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -7,6 +7,8 @@ import type {
7
7
  } from "../shared/analytics";
8
8
  import { getWidgetApiBase } from "./api-origin";
9
9
 
10
+ const ANALYTICS_ENABLED = false;
11
+
10
12
  const ANALYTICS_ENDPOINT = "/api/widget/events/batch";
11
13
  const DEFAULT_BATCH_SIZE = 10;
12
14
  const DEFAULT_FLUSH_INTERVAL_MS = 2500;
@@ -92,7 +94,7 @@ export class WidgetAnalyticsTracker {
92
94
  options.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS,
93
95
  );
94
96
 
95
- if (this.mode === "embed") {
97
+ if (ANALYTICS_ENABLED && this.mode === "embed") {
96
98
  window.addEventListener("pagehide", this.handlePageHide, {
97
99
  capture: true,
98
100
  });
@@ -108,6 +110,7 @@ export class WidgetAnalyticsTracker {
108
110
  if (this.disposed) return;
109
111
  this.disposed = true;
110
112
  this.clearFlushTimer();
113
+ if (!ANALYTICS_ENABLED) return;
111
114
  window.removeEventListener("pagehide", this.handlePageHide, true);
112
115
  document.removeEventListener(
113
116
  "visibilitychange",
@@ -122,6 +125,7 @@ export class WidgetAnalyticsTracker {
122
125
  }
123
126
 
124
127
  trackUniqueScriptLoaded() {
128
+ if (!ANALYTICS_ENABLED) return;
125
129
  const sessionToken = this.getSession()?.sessionToken?.trim();
126
130
  if (!sessionToken) return;
127
131
  const uniqueKey = `${this.agentId}:${sessionToken}`;
@@ -161,6 +165,7 @@ export class WidgetAnalyticsTracker {
161
165
  track(event: Omit<WidgetAnalyticsBatchEvent, "occurredAt"> & {
162
166
  occurredAt?: string;
163
167
  }) {
168
+ if (!ANALYTICS_ENABLED) return;
164
169
  if (this.disposed || this.mode !== "embed") return;
165
170
 
166
171
  const sessionToken = this.getSession()?.sessionToken?.trim();
@@ -208,6 +213,7 @@ export class WidgetAnalyticsTracker {
208
213
  async flush(options?: {
209
214
  transport?: "default" | "beacon";
210
215
  }): Promise<void> {
216
+ if (!ANALYTICS_ENABLED) return;
211
217
  if (this.disposed) return;
212
218
 
213
219
  const now = Date.now();