@metrone-io/sdk 1.0.1 → 1.2.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,27 @@ 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;
49
- constructor(config: AnalyticsConfig);
52
+ private flushTimerId;
53
+ private boundVisibilityHandler;
54
+ private boundBeforeUnloadHandler;
55
+ private lastTrackedPath;
56
+ constructor(config: AnalyticsConfig | string);
57
+ /**
58
+ * Explicitly start tracking. Called automatically by the constructor unless
59
+ * tracking is blocked by DNT or consent. Can also be called manually if you
60
+ * want to separate initialization from activation.
61
+ */
62
+ start(): void;
63
+ private activate;
64
+ /**
65
+ * Whether the SDK is actively tracking events (not disabled by DNT/consent).
66
+ */
67
+ isActive(): boolean;
50
68
  /**
51
69
  * Track a page view
52
70
  */
@@ -122,110 +140,51 @@ export declare class Metrone {
122
140
  duration?: number;
123
141
  metadata?: EventData;
124
142
  }): void;
125
- /**
126
- * Send event to analytics API
127
- */
128
143
  private sendEvent;
129
- /**
130
- * Send request to analytics API
131
- */
132
144
  private sendRequest;
133
- /**
134
- * Flush batch of events
135
- */
136
145
  private flushBatch;
137
146
  private sendBatchRequest;
138
147
  /**
139
- * Queue event for offline processing
148
+ * Flush queued events using sendBeacon (survives page unload).
140
149
  */
150
+ private beaconFlush;
141
151
  private queueEvent;
142
- /**
143
- * Process offline queue when back online
144
- */
145
152
  private processQueue;
146
- /**
147
- * Set up online/offline detection
148
- */
149
153
  private setupOnlineDetection;
150
- /**
151
- * Set up batch processing
152
- */
153
154
  private setupBatchProcessing;
154
155
  /**
155
- * Set up auto-updates
156
+ * Flush pending events on page hide / beforeunload using sendBeacon.
156
157
  */
157
- private setupAutoUpdates;
158
+ private setupPageUnloadFlush;
158
159
  /**
159
- * Check for SDK updates
160
+ * Auto-track SPA route changes via History API and popstate.
160
161
  */
161
- checkForUpdates(): Promise<UpdateInfo>;
162
+ private setupSPATracking;
162
163
  /**
163
- * Handle SDK update
164
+ * Check for SDK updates (only relevant for script-tag installations).
164
165
  */
166
+ checkForUpdates(): Promise<UpdateInfo>;
165
167
  private handleUpdate;
166
- /**
167
- * Load new SDK version
168
- */
169
168
  private loadNewVersion;
170
- /**
171
- * Notify about available update
172
- */
173
169
  private notifyUpdate;
174
170
  /**
175
- * Generate session ID
171
+ * Detect whether the SDK is running inside a bundler/module context
172
+ * vs. a plain script-tag.
176
173
  */
174
+ private isModuleContext;
177
175
  private generateSessionId;
178
- /**
179
- * Check if Do Not Track is enabled
180
- */
181
176
  private isDoNotTrackEnabled;
182
- /**
183
- * Check if user has given consent
184
- */
185
177
  hasConsent(): boolean;
186
- /**
187
- * Request user consent
188
- */
189
178
  requestConsent(): Promise<boolean>;
190
- /**
191
- * Revoke user consent
192
- */
193
179
  revokeConsent(): void;
194
- /**
195
- * Anonymize data
196
- */
197
180
  anonymize(data: string): string;
198
- /**
199
- * Simple hash function
200
- */
201
181
  private simpleHash;
202
- /**
203
- * Check if running on mobile device
204
- */
205
182
  isMobile(): boolean;
206
- /**
207
- * Get screen size
208
- */
209
183
  getScreenSize(): string;
210
- /**
211
- * Flush pending events
212
- */
213
184
  flush(): void;
214
- /**
215
- * Destroy SDK instance
216
- */
217
185
  destroy(): void;
218
- /**
219
- * Get current version
220
- */
221
186
  getVersion(): string;
222
- /**
223
- * Get session ID
224
- */
225
187
  getSessionId(): string;
226
- /**
227
- * Get configuration
228
- */
229
188
  getConfig(): AnalyticsConfig;
230
189
  }
231
190
  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.2.0";
9
9
  export default Metrone;