@metrone-io/sdk 1.0.1 → 1.1.0

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.
@@ -6,8 +6,10 @@ export interface AnalyticsConfig {
6
6
  apiKey: string;
7
7
  projectId?: string;
8
8
  endpoint?: string;
9
+ batchEndpoint?: string;
9
10
  debug?: boolean;
10
11
  autoTrack?: boolean;
12
+ autoTrackSPA?: boolean;
11
13
  autoUpdate?: boolean;
12
14
  batchSize?: number;
13
15
  flushInterval?: number;
@@ -42,11 +44,20 @@ export declare class Metrone {
42
44
  private config;
43
45
  private sessionId;
44
46
  private isInitialized;
47
+ private trackingActive;
45
48
  private eventQueue;
46
49
  private isOnline;
47
50
  private version;
48
51
  private updateCheckInterval;
52
+ private flushTimerId;
53
+ private boundVisibilityHandler;
54
+ private boundBeforeUnloadHandler;
55
+ private lastTrackedPath;
49
56
  constructor(config: AnalyticsConfig);
57
+ /**
58
+ * Whether the SDK is actively tracking events (not disabled by DNT/consent).
59
+ */
60
+ isActive(): boolean;
50
61
  /**
51
62
  * Track a page view
52
63
  */
@@ -122,110 +133,51 @@ export declare class Metrone {
122
133
  duration?: number;
123
134
  metadata?: EventData;
124
135
  }): void;
125
- /**
126
- * Send event to analytics API
127
- */
128
136
  private sendEvent;
129
- /**
130
- * Send request to analytics API
131
- */
132
137
  private sendRequest;
133
- /**
134
- * Flush batch of events
135
- */
136
138
  private flushBatch;
137
139
  private sendBatchRequest;
138
140
  /**
139
- * Queue event for offline processing
141
+ * Flush queued events using sendBeacon (survives page unload).
140
142
  */
143
+ private beaconFlush;
141
144
  private queueEvent;
142
- /**
143
- * Process offline queue when back online
144
- */
145
145
  private processQueue;
146
- /**
147
- * Set up online/offline detection
148
- */
149
146
  private setupOnlineDetection;
150
- /**
151
- * Set up batch processing
152
- */
153
147
  private setupBatchProcessing;
154
148
  /**
155
- * Set up auto-updates
149
+ * Flush pending events on page hide / beforeunload using sendBeacon.
156
150
  */
157
- private setupAutoUpdates;
151
+ private setupPageUnloadFlush;
158
152
  /**
159
- * Check for SDK updates
153
+ * Auto-track SPA route changes via History API and popstate.
160
154
  */
161
- checkForUpdates(): Promise<UpdateInfo>;
155
+ private setupSPATracking;
162
156
  /**
163
- * Handle SDK update
157
+ * Check for SDK updates (only relevant for script-tag installations).
164
158
  */
159
+ checkForUpdates(): Promise<UpdateInfo>;
165
160
  private handleUpdate;
166
- /**
167
- * Load new SDK version
168
- */
169
161
  private loadNewVersion;
170
- /**
171
- * Notify about available update
172
- */
173
162
  private notifyUpdate;
174
163
  /**
175
- * Generate session ID
164
+ * Detect whether the SDK is running inside a bundler/module context
165
+ * vs. a plain script-tag.
176
166
  */
167
+ private isModuleContext;
177
168
  private generateSessionId;
178
- /**
179
- * Check if Do Not Track is enabled
180
- */
181
169
  private isDoNotTrackEnabled;
182
- /**
183
- * Check if user has given consent
184
- */
185
170
  hasConsent(): boolean;
186
- /**
187
- * Request user consent
188
- */
189
171
  requestConsent(): Promise<boolean>;
190
- /**
191
- * Revoke user consent
192
- */
193
172
  revokeConsent(): void;
194
- /**
195
- * Anonymize data
196
- */
197
173
  anonymize(data: string): string;
198
- /**
199
- * Simple hash function
200
- */
201
174
  private simpleHash;
202
- /**
203
- * Check if running on mobile device
204
- */
205
175
  isMobile(): boolean;
206
- /**
207
- * Get screen size
208
- */
209
176
  getScreenSize(): string;
210
- /**
211
- * Flush pending events
212
- */
213
177
  flush(): void;
214
- /**
215
- * Destroy SDK instance
216
- */
217
178
  destroy(): void;
218
- /**
219
- * Get current version
220
- */
221
179
  getVersion(): string;
222
- /**
223
- * Get session ID
224
- */
225
180
  getSessionId(): string;
226
- /**
227
- * Get configuration
228
- */
229
181
  getConfig(): AnalyticsConfig;
230
182
  }
231
183
  export declare function initAnalytics(config: AnalyticsConfig): Metrone;
package/dist/index.d.ts CHANGED
@@ -5,5 +5,5 @@
5
5
  import { Metrone } from './core/Metrone';
6
6
  export { Metrone, initAnalytics, getAnalytics } from './core/Metrone';
7
7
  export type { AnalyticsConfig, EventData, CampaignData, UpdateInfo, AnalyticsEvent, BatchEvent, ConversionEvent, InteractionEvent, ProductViewEvent, WhatsAppClickEvent, PageViewEvent, DeviceInfo, LocationInfo, SessionInfo, AnalyticsStats, CampaignStats, ProjectInfo, ErrorInfo, ConsentInfo, AnalyticsCustomEvent, AnalyticsEventListener, AnalyticsSDK, AnalyticsProviderProps, AnalyticsContextValue, UseAnalyticsReturn, AnalyticsHookOptions, AnalyticsMiddleware, AnalyticsPlugin, AnalyticsConfigValidation, AnalyticsPerformanceMetrics, AnalyticsDebugInfo } from './types';
8
- export declare const VERSION = "1.0.1";
8
+ export declare const VERSION = "1.1.0";
9
9
  export default Metrone;