wisetrack 2.0.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.
Files changed (178) hide show
  1. package/LICENSE +5 -0
  2. package/README.md +128 -0
  3. package/dist/cdn/constants/constants.d.ts +20 -0
  4. package/dist/cdn/constants/endpoints.d.ts +11 -0
  5. package/dist/cdn/constants/environments.d.ts +25 -0
  6. package/dist/cdn/core/caching/queue-data.d.ts +25 -0
  7. package/dist/cdn/core/caching/request-queue-manager.d.ts +54 -0
  8. package/dist/cdn/core/fields/event-fields-builder.d.ts +8 -0
  9. package/dist/cdn/core/fields/fields-builder.d.ts +9 -0
  10. package/dist/cdn/core/network/api-client.d.ts +9 -0
  11. package/dist/cdn/core/network/network-error.d.ts +17 -0
  12. package/dist/cdn/core/network/network-manager.d.ts +22 -0
  13. package/dist/cdn/core/network/retry-policy.d.ts +8 -0
  14. package/dist/cdn/core/storage/storage-manager.d.ts +52 -0
  15. package/dist/cdn/core/wisetrack.d.ts +125 -0
  16. package/dist/cdn/core/wt-tracker.d.ts +25 -0
  17. package/dist/cdn/index.d.ts +4 -0
  18. package/dist/cdn/sdk.bundle.js +3604 -0
  19. package/dist/cdn/sdk.bundle.js.map +1 -0
  20. package/dist/cdn/sdk.bundle.min.js +1 -0
  21. package/dist/cdn/types/config/initial-config.d.ts +43 -0
  22. package/dist/cdn/types/config/wt-app-settings.d.ts +15 -0
  23. package/dist/cdn/types/config/wt-config.d.ts +18 -0
  24. package/dist/cdn/types/event/revenue-currency.d.ts +39 -0
  25. package/dist/cdn/types/event/wt-event.d.ts +94 -0
  26. package/dist/cdn/utils/activity-ticker.d.ts +12 -0
  27. package/dist/cdn/utils/country-finder.d.ts +9 -0
  28. package/dist/cdn/utils/crypto-helper.d.ts +4 -0
  29. package/dist/cdn/utils/device-detector.d.ts +41 -0
  30. package/dist/cdn/utils/logger.d.ts +36 -0
  31. package/dist/cdn/utils/storage-support.d.ts +16 -0
  32. package/dist/cdn/utils/utils.d.ts +5 -0
  33. package/dist/cdn/utils/webgl-fingerprint.d.ts +7 -0
  34. package/dist/cjs/constants/constants.d.ts +20 -0
  35. package/dist/cjs/constants/endpoints.d.ts +11 -0
  36. package/dist/cjs/constants/environments.d.ts +25 -0
  37. package/dist/cjs/core/caching/queue-data.d.ts +25 -0
  38. package/dist/cjs/core/caching/request-queue-manager.d.ts +54 -0
  39. package/dist/cjs/core/fields/event-fields-builder.d.ts +8 -0
  40. package/dist/cjs/core/fields/fields-builder.d.ts +9 -0
  41. package/dist/cjs/core/network/api-client.d.ts +9 -0
  42. package/dist/cjs/core/network/network-error.d.ts +17 -0
  43. package/dist/cjs/core/network/network-manager.d.ts +22 -0
  44. package/dist/cjs/core/network/retry-policy.d.ts +8 -0
  45. package/dist/cjs/core/storage/storage-manager.d.ts +52 -0
  46. package/dist/cjs/core/wisetrack.d.ts +125 -0
  47. package/dist/cjs/core/wt-tracker.d.ts +25 -0
  48. package/dist/cjs/index.d.ts +4 -0
  49. package/dist/cjs/index.js +3599 -0
  50. package/dist/cjs/index.js.map +1 -0
  51. package/dist/cjs/types/config/initial-config.d.ts +43 -0
  52. package/dist/cjs/types/config/wt-app-settings.d.ts +15 -0
  53. package/dist/cjs/types/config/wt-config.d.ts +18 -0
  54. package/dist/cjs/types/event/revenue-currency.d.ts +39 -0
  55. package/dist/cjs/types/event/wt-event.d.ts +94 -0
  56. package/dist/cjs/utils/activity-ticker.d.ts +12 -0
  57. package/dist/cjs/utils/country-finder.d.ts +9 -0
  58. package/dist/cjs/utils/crypto-helper.d.ts +4 -0
  59. package/dist/cjs/utils/device-detector.d.ts +41 -0
  60. package/dist/cjs/utils/logger.d.ts +36 -0
  61. package/dist/cjs/utils/storage-support.d.ts +16 -0
  62. package/dist/cjs/utils/utils.d.ts +5 -0
  63. package/dist/cjs/utils/webgl-fingerprint.d.ts +7 -0
  64. package/dist/constants/constants.d.ts +20 -0
  65. package/dist/constants/constants.js +19 -0
  66. package/dist/constants/constants.js.map +1 -0
  67. package/dist/constants/endpoints.d.ts +11 -0
  68. package/dist/constants/endpoints.js +10 -0
  69. package/dist/constants/endpoints.js.map +1 -0
  70. package/dist/constants/environments.d.ts +25 -0
  71. package/dist/constants/environments.js +37 -0
  72. package/dist/constants/environments.js.map +1 -0
  73. package/dist/core/caching/queue-data.d.ts +25 -0
  74. package/dist/core/caching/queue-data.js +50 -0
  75. package/dist/core/caching/queue-data.js.map +1 -0
  76. package/dist/core/caching/request-queue-manager.d.ts +54 -0
  77. package/dist/core/caching/request-queue-manager.js +333 -0
  78. package/dist/core/caching/request-queue-manager.js.map +1 -0
  79. package/dist/core/fields/event-fields-builder.d.ts +8 -0
  80. package/dist/core/fields/event-fields-builder.js +29 -0
  81. package/dist/core/fields/event-fields-builder.js.map +1 -0
  82. package/dist/core/fields/fields-builder.d.ts +9 -0
  83. package/dist/core/fields/fields-builder.js +120 -0
  84. package/dist/core/fields/fields-builder.js.map +1 -0
  85. package/dist/core/network/api-client.d.ts +9 -0
  86. package/dist/core/network/api-client.js +88 -0
  87. package/dist/core/network/api-client.js.map +1 -0
  88. package/dist/core/network/network-error.d.ts +17 -0
  89. package/dist/core/network/network-error.js +35 -0
  90. package/dist/core/network/network-error.js.map +1 -0
  91. package/dist/core/network/network-manager.d.ts +22 -0
  92. package/dist/core/network/network-manager.js +72 -0
  93. package/dist/core/network/network-manager.js.map +1 -0
  94. package/dist/core/network/retry-policy.d.ts +8 -0
  95. package/dist/core/network/retry-policy.js +26 -0
  96. package/dist/core/network/retry-policy.js.map +1 -0
  97. package/dist/core/storage/storage-manager.d.ts +52 -0
  98. package/dist/core/storage/storage-manager.js +221 -0
  99. package/dist/core/storage/storage-manager.js.map +1 -0
  100. package/dist/core/wisetrack.d.ts +125 -0
  101. package/dist/core/wisetrack.js +277 -0
  102. package/dist/core/wisetrack.js.map +1 -0
  103. package/dist/core/wt-tracker.d.ts +25 -0
  104. package/dist/core/wt-tracker.js +239 -0
  105. package/dist/core/wt-tracker.js.map +1 -0
  106. package/dist/esm/constants/constants.d.ts +20 -0
  107. package/dist/esm/constants/endpoints.d.ts +11 -0
  108. package/dist/esm/constants/environments.d.ts +25 -0
  109. package/dist/esm/core/caching/queue-data.d.ts +25 -0
  110. package/dist/esm/core/caching/request-queue-manager.d.ts +54 -0
  111. package/dist/esm/core/fields/event-fields-builder.d.ts +8 -0
  112. package/dist/esm/core/fields/fields-builder.d.ts +9 -0
  113. package/dist/esm/core/network/api-client.d.ts +9 -0
  114. package/dist/esm/core/network/network-error.d.ts +17 -0
  115. package/dist/esm/core/network/network-manager.d.ts +22 -0
  116. package/dist/esm/core/network/retry-policy.d.ts +8 -0
  117. package/dist/esm/core/storage/storage-manager.d.ts +52 -0
  118. package/dist/esm/core/wisetrack.d.ts +125 -0
  119. package/dist/esm/core/wt-tracker.d.ts +25 -0
  120. package/dist/esm/index.d.ts +4 -0
  121. package/dist/esm/index.js +3594 -0
  122. package/dist/esm/index.js.map +1 -0
  123. package/dist/esm/types/config/initial-config.d.ts +43 -0
  124. package/dist/esm/types/config/wt-app-settings.d.ts +15 -0
  125. package/dist/esm/types/config/wt-config.d.ts +18 -0
  126. package/dist/esm/types/event/revenue-currency.d.ts +39 -0
  127. package/dist/esm/types/event/wt-event.d.ts +94 -0
  128. package/dist/esm/utils/activity-ticker.d.ts +12 -0
  129. package/dist/esm/utils/country-finder.d.ts +9 -0
  130. package/dist/esm/utils/crypto-helper.d.ts +4 -0
  131. package/dist/esm/utils/device-detector.d.ts +41 -0
  132. package/dist/esm/utils/logger.d.ts +36 -0
  133. package/dist/esm/utils/storage-support.d.ts +16 -0
  134. package/dist/esm/utils/utils.d.ts +5 -0
  135. package/dist/esm/utils/webgl-fingerprint.d.ts +7 -0
  136. package/dist/index.d.ts +4 -0
  137. package/dist/index.js +4 -0
  138. package/dist/index.js.map +1 -0
  139. package/dist/types/config/initial-config.d.ts +43 -0
  140. package/dist/types/config/initial-config.js +2 -0
  141. package/dist/types/config/initial-config.js.map +1 -0
  142. package/dist/types/config/wt-app-settings.d.ts +15 -0
  143. package/dist/types/config/wt-app-settings.js +25 -0
  144. package/dist/types/config/wt-app-settings.js.map +1 -0
  145. package/dist/types/config/wt-config.d.ts +18 -0
  146. package/dist/types/config/wt-config.js +28 -0
  147. package/dist/types/config/wt-config.js.map +1 -0
  148. package/dist/types/event/revenue-currency.d.ts +39 -0
  149. package/dist/types/event/revenue-currency.js +39 -0
  150. package/dist/types/event/revenue-currency.js.map +1 -0
  151. package/dist/types/event/wt-event.d.ts +94 -0
  152. package/dist/types/event/wt-event.js +93 -0
  153. package/dist/types/event/wt-event.js.map +1 -0
  154. package/dist/utils/activity-ticker.d.ts +12 -0
  155. package/dist/utils/activity-ticker.js +37 -0
  156. package/dist/utils/activity-ticker.js.map +1 -0
  157. package/dist/utils/country-finder.d.ts +9 -0
  158. package/dist/utils/country-finder.js +71 -0
  159. package/dist/utils/country-finder.js.map +1 -0
  160. package/dist/utils/crypto-helper.d.ts +4 -0
  161. package/dist/utils/crypto-helper.js +7 -0
  162. package/dist/utils/crypto-helper.js.map +1 -0
  163. package/dist/utils/device-detector.d.ts +41 -0
  164. package/dist/utils/device-detector.js +101 -0
  165. package/dist/utils/device-detector.js.map +1 -0
  166. package/dist/utils/logger.d.ts +36 -0
  167. package/dist/utils/logger.js +84 -0
  168. package/dist/utils/logger.js.map +1 -0
  169. package/dist/utils/storage-support.d.ts +16 -0
  170. package/dist/utils/storage-support.js +86 -0
  171. package/dist/utils/storage-support.js.map +1 -0
  172. package/dist/utils/utils.d.ts +5 -0
  173. package/dist/utils/utils.js +95 -0
  174. package/dist/utils/utils.js.map +1 -0
  175. package/dist/utils/webgl-fingerprint.d.ts +7 -0
  176. package/dist/utils/webgl-fingerprint.js +100 -0
  177. package/dist/utils/webgl-fingerprint.js.map +1 -0
  178. package/package.json +71 -0
package/LICENSE ADDED
@@ -0,0 +1,5 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 WiseTrack
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy...
package/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # WiseTrack Web SDK
2
+
3
+ A lightweight JavaScript SDK for tracking user behavior and events in your web applications.
4
+
5
+ ---
6
+
7
+ ## 🚀 Features
8
+
9
+ - Lightweight and easy to integrate
10
+ - Supports custom and revenue events
11
+ - Environment-based configuration (Sandbox & Production)
12
+ - Automatic or manual tracking control
13
+ - Customizable logging level
14
+
15
+ ---
16
+
17
+ ## 📦 Installation
18
+
19
+ ```bash
20
+ # via npm
21
+ npm install @your-scope/wisetrack-web
22
+
23
+ # via yarn
24
+ yarn add @your-scope/wisetrack-web
25
+ ````
26
+
27
+ ---
28
+
29
+ ## ✅ Basic Usage
30
+
31
+ ### 1️⃣ Initialize the SDK
32
+
33
+ ```ts
34
+ import { WiseTrack, WTUserEnvironment, WTLogLevel } from "@your-scope/wisetrack-web";
35
+
36
+ await WiseTrack.instance.init({
37
+ appToken: "YOUR_APP_TOKEN",
38
+ appVersion: "1.0.0",
39
+ appFrameWork: "Next.js",
40
+ userEnvironment: WTUserEnvironment.SANDBOX,
41
+ logLevel: WTLogLevel.DEBUG,
42
+ });
43
+ ```
44
+
45
+ ### 2️⃣ Start Tracking (Optional)
46
+
47
+ ```ts
48
+ // Starts automatically if `startTrackerAutomatically` is true.
49
+ // Otherwise, you can start manually:
50
+ await WiseTrack.instance.startTracking();
51
+ ```
52
+
53
+ ### 3️⃣ Track a Custom Event
54
+
55
+ ```ts
56
+ import { WTEvent } from "@your-scope/wisetrack-web";
57
+
58
+ const signupEvent = new WTEvent.Default("signup");
59
+ signupEvent.addParam("method", "Google");
60
+
61
+ await WiseTrack.instance.trackEvent(signupEvent);
62
+ ```
63
+
64
+ ### 4️⃣ Track a Revenue Event
65
+
66
+ ```ts
67
+ import { WTEvent, RevenueCurrency } from "@your-scope/wisetrack-web";
68
+
69
+ const purchase = new WTEvent.Revenue("order_completed", 99.99, RevenueCurrency.USD);
70
+ purchase.addParam("item_id", "SKU-123");
71
+
72
+ await WiseTrack.instance.trackEvent(purchase);
73
+ ```
74
+
75
+ ---
76
+
77
+ ## ⚙️ Configuration Options
78
+
79
+ | Key | Required | Description |
80
+ | --------------------------- | -------- | -------------------------------------------------------------- |
81
+ | `appToken` | ✅ | Your unique WiseTrack app token |
82
+ | `appVersion` | ✅ | Your app version |
83
+ | `appFrameWork` | ✅ | The framework/platform name |
84
+ | `userEnvironment` | ❌ | `WTUserEnvironment.SANDBOX` or `WTUserEnvironment.PRODUCTION` |
85
+ | `trackingWaitingTime` | ❌ | Time in seconds to wait before tracking starts automatically |
86
+ | `startTrackerAutomatically` | ❌ | Whether to start tracking automatically (default: `true`) |
87
+ | `customDeviceId` | ❌ | Provide your own device ID |
88
+ | `defaultTracker` | ❌ | Optional tracker name |
89
+ | `logLevel` | ❌ | Logging level (`WTLogLevel.DEBUG` / `INFO` / `WARN` / `ERROR`) |
90
+
91
+ ---
92
+
93
+ ## 🧹 Flush / Stop Tracking
94
+
95
+ ```ts
96
+ // Stop tracking and clear stored data
97
+ WiseTrack.instance.flush();
98
+ ```
99
+
100
+ ---
101
+
102
+ ## 🔍 Log Level
103
+
104
+ Set the SDK log level for debugging:
105
+
106
+ ```ts
107
+ WiseTrack.instance.setLogLevel(WTLogLevel.DEBUG);
108
+ ```
109
+
110
+ ---
111
+
112
+ ## 📚 API Reference
113
+
114
+ For detailed TypeDocs, see [📖 Full API Reference](./docs).
115
+
116
+ ---
117
+
118
+ ## 🛟 Support
119
+
120
+ * [Documentation](./docs)
121
+ * [Issues](https://github.com/wisetrack-io/web-sdk/issues)
122
+ * Contact: [your-email@example.com](mailto:support@wisetrack.io)
123
+
124
+ ---
125
+
126
+ ## 📝 License
127
+
128
+ MIT © [WiseTrack](https://wisetrack.io)
@@ -0,0 +1,20 @@
1
+ import { WTLogLevel } from "../utils/logger";
2
+ import { WTSDKEnvironment } from "./environments";
3
+ /** @internal */
4
+ export declare const WTConstants: {
5
+ readonly SDK: {
6
+ readonly HASH: "997bfbb583c1245a426a53dc1899ec779ff354f9";
7
+ readonly PLATFORM: "web";
8
+ readonly VERSION: "2.0.0";
9
+ };
10
+ readonly CONFIG: {
11
+ readonly BASE_URL: "https://config.wisetrack.io";
12
+ readonly DEFAULT_ENVIRONMENT: WTSDKEnvironment;
13
+ };
14
+ readonly DEFAULTS: {
15
+ readonly LOG_LEVEL: WTLogLevel;
16
+ readonly SESSION_INTERVAL: "1800000";
17
+ readonly SUBSESSION_INTERVAL: "300000";
18
+ readonly PARAMETERS_VALUE: string | undefined;
19
+ };
20
+ };
@@ -0,0 +1,11 @@
1
+ /** @internal */
2
+ export declare const WTEndpoints: {
3
+ readonly EVENTS: "/api/v1/events";
4
+ readonly SESSIONS: "/api/v1/sessions";
5
+ readonly SDK_CLICKS: "/api/v1/sdk_clicks";
6
+ readonly SDK_INFOS: "/api/v1/sdk_infos";
7
+ readonly ATTRIBUTIONS: "/api/v1/attributions";
8
+ readonly APP_SETTINGS: "/api/v1/app_settings";
9
+ };
10
+ /** @internal */
11
+ export type WTEndpoints = (typeof WTEndpoints)[keyof typeof WTEndpoints];
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Defines the user environment in which the SDK is running.
3
+ *
4
+ * - `SANDBOX`: Use this for testing and development.
5
+ * - `PRODUCTION`: Use this for production deployment.
6
+ */
7
+ export declare const WTUserEnvironment: {
8
+ readonly SANDBOX: "sandbox";
9
+ readonly PRODUCTION: "production";
10
+ };
11
+ export type WTUserEnvironment = (typeof WTUserEnvironment)[keyof typeof WTUserEnvironment];
12
+ /** @internal */
13
+ export declare const WTSDKEnvironment: {
14
+ readonly DEBUG: "debug";
15
+ readonly STAGE: "stage";
16
+ readonly PRODUCTION: "production";
17
+ };
18
+ /** @internal */
19
+ export type WTSDKEnvironment = (typeof WTSDKEnvironment)[keyof typeof WTSDKEnvironment];
20
+ /** @internal */
21
+ export declare const EnvironmentUtils: {
22
+ sdkEnvironment: WTSDKEnvironment;
23
+ needAppSettings(): boolean;
24
+ baseUrl(): string;
25
+ };
@@ -0,0 +1,25 @@
1
+ import { WTEndpoints } from "../../constants/endpoints";
2
+ import { FieldsBuilder } from "../fields/fields-builder";
3
+ /** @internal */
4
+ export interface RequestRecordCreator {
5
+ endpoint: WTEndpoints;
6
+ fBuilder?: FieldsBuilder;
7
+ queueType?: "main" | "pending";
8
+ }
9
+ /** @internal */
10
+ export declare class RequestRecord {
11
+ readonly id: string;
12
+ readonly endpoint: WTEndpoints;
13
+ readonly parameters: Record<string, any>;
14
+ readonly createdAt: number;
15
+ retryCount: number;
16
+ maxRetries: number;
17
+ constructor(endpoint: WTEndpoints, parameters: Record<string, any>);
18
+ }
19
+ /** @internal */
20
+ export declare class Mutex {
21
+ private locked;
22
+ private waitingQueue;
23
+ acquire(): Promise<void>;
24
+ release(): void;
25
+ }
@@ -0,0 +1,54 @@
1
+ import { RequestRecord } from "./queue-data";
2
+ /** @internal */
3
+ export declare class RequestsQueueManager {
4
+ private isInitialized;
5
+ private isProcessing;
6
+ private isCurrentlyProcessing;
7
+ private mutex;
8
+ private processingInterval;
9
+ private readonly PROCESSING_INTERVAL_MS;
10
+ private failedRequestDelay;
11
+ private readonly MAX_DELAY_MS;
12
+ private readonly BACKOFF_MULTIPLIER;
13
+ private readonly BASE_DELAY_MS;
14
+ constructor();
15
+ initialize(): Promise<void>;
16
+ shutdown(): Promise<void>;
17
+ private startProcessing;
18
+ private stopProcessing;
19
+ addRequest(request: RequestRecord): Promise<void>;
20
+ addPendingRequest(request: RequestRecord): Promise<void>;
21
+ private processQueues;
22
+ private processMainQueue;
23
+ private calculateBackoffDelay;
24
+ private processPendingQueue;
25
+ private sendRequest;
26
+ private getMainQueue;
27
+ private saveMainQueue;
28
+ private getPendingQueue;
29
+ private savePendingQueue;
30
+ private getMainRequestsSentFlag;
31
+ private postRequestCheck;
32
+ getQueueStatus(): {
33
+ mainQueueLength: number;
34
+ pendingQueueLength: number;
35
+ isProcessing: boolean;
36
+ mainRequestsSent: boolean;
37
+ isInBackoffDelay: boolean;
38
+ backoffEndsAt: number | null;
39
+ };
40
+ /**
41
+ * Manually reset backoff delay (useful for testing or manual recovery)
42
+ */
43
+ resetBackoffDelay(): void;
44
+ /**
45
+ * Get current backoff delay configuration
46
+ */
47
+ getBackoffConfig(): {
48
+ baseDelayMs: number;
49
+ multiplier: number;
50
+ maxDelayMs: number;
51
+ };
52
+ }
53
+ /** @internal */
54
+ export declare const queueManager: RequestsQueueManager;
@@ -0,0 +1,8 @@
1
+ import { WTEvent } from "../../types/event/wt-event";
2
+ import { FieldsBuilder } from "./fields-builder";
3
+ /** @internal */
4
+ export declare class EventFieldsBuilder extends FieldsBuilder {
5
+ event: WTEvent.Default | WTEvent.Revenue;
6
+ constructor(event: WTEvent.Default | WTEvent.Revenue);
7
+ build(): Promise<Record<string, any>>;
8
+ }
@@ -0,0 +1,9 @@
1
+ /** @internal */
2
+ export declare class FieldsBuilder {
3
+ build(): Promise<Record<string, any>>;
4
+ private getApplicationFields;
5
+ private getLocalFields;
6
+ private getDeviceFields;
7
+ }
8
+ /** @internal */
9
+ export declare const fieldsBuilder: FieldsBuilder;
@@ -0,0 +1,9 @@
1
+ import { WTEndpoints } from "../../constants/endpoints";
2
+ import { WTAppSettings } from "../../types/config/wt-app-settings";
3
+ import { WTConfig } from "../../types/config/wt-config";
4
+ /** @internal */
5
+ export declare const apiClient: {
6
+ doGetConfig(): Promise<WTConfig>;
7
+ doGetAppSettings(): Promise<WTAppSettings>;
8
+ doCallRequest(endpoint: WTEndpoints, params: Record<string, any>): Promise<boolean>;
9
+ };
@@ -0,0 +1,17 @@
1
+ /** @internal */
2
+ export declare namespace ApiError {
3
+ class InvalidUrl extends Error {
4
+ constructor(url: string);
5
+ }
6
+ class ServerError extends Error {
7
+ statusCode: number;
8
+ message: string;
9
+ constructor(statusCode: number, message: string);
10
+ }
11
+ class NetworkError extends Error {
12
+ constructor(message: string);
13
+ }
14
+ class DecodingError extends Error {
15
+ constructor(message: string);
16
+ }
17
+ }
@@ -0,0 +1,22 @@
1
+ import { RetryPolicy } from "./retry-policy";
2
+ type HttpMethod = "GET" | "POST" | "PUT";
3
+ /** @internal */
4
+ export interface RequestOptions {
5
+ method?: HttpMethod;
6
+ headers?: Record<string, string>;
7
+ params?: Record<string, any>;
8
+ formData?: Record<string, any>;
9
+ retryAttempt?: number;
10
+ }
11
+ /** @internal */
12
+ export interface ApiResponseWrapper {
13
+ success: boolean;
14
+ message?: string;
15
+ result?: any;
16
+ }
17
+ /** @internal */
18
+ export declare const networkManager: {
19
+ readonly retryPolicy: () => RetryPolicy;
20
+ readonly sendRequest: (endpoint: string, options?: RequestOptions) => Promise<ApiResponseWrapper>;
21
+ };
22
+ export {};
@@ -0,0 +1,8 @@
1
+ /** @internal */
2
+ export declare class RetryPolicy {
3
+ private maxRetries;
4
+ private retryInterval;
5
+ constructor(maxRetries?: number, retryInterval?: number);
6
+ canRetry(attempt: number): boolean;
7
+ waitBeforeRetry(): Promise<void>;
8
+ }
@@ -0,0 +1,52 @@
1
+ import { WTInitialConfig } from "../../types/config/initial-config";
2
+ import { WTAppSettings } from "../../types/config/wt-app-settings";
3
+ import { WTConfig } from "../../types/config/wt-config";
4
+ import { RequestRecord } from "../caching/queue-data";
5
+ declare class StorageManager {
6
+ clear(): void;
7
+ private setJson;
8
+ private getJson;
9
+ private optionalNumber;
10
+ private optionalBool;
11
+ get deviceId(): string | null;
12
+ set deviceId(value: string | null);
13
+ get initialDate(): string | null;
14
+ set initialDate(value: string | null);
15
+ get initialConfig(): WTInitialConfig | null;
16
+ set initialConfig(value: WTInitialConfig | null);
17
+ get config(): WTConfig | null;
18
+ set config(value: WTConfig | null);
19
+ get appSettings(): WTAppSettings | null;
20
+ set appSettings(value: WTAppSettings | null);
21
+ get sdkEnabled(): boolean;
22
+ set sdkEnabled(value: boolean);
23
+ get sdkClickSubmit(): boolean;
24
+ set sdkClickSubmit(value: boolean);
25
+ get firstSessionSubmit(): boolean;
26
+ set firstSessionSubmit(value: boolean);
27
+ get fcmToken(): string | null;
28
+ set fcmToken(value: string | null);
29
+ get pushToken(): string | null;
30
+ set pushToken(value: string | null);
31
+ get sessionCount(): number;
32
+ set sessionCount(value: number);
33
+ get subSessionCount(): number;
34
+ set subSessionCount(value: number);
35
+ get activeDuration(): number;
36
+ set activeDuration(value: number);
37
+ get inactiveDuration(): number;
38
+ set inactiveDuration(value: number);
39
+ get inactiveTime(): number | null;
40
+ set inactiveTime(value: number | null);
41
+ get activeTime(): number | null;
42
+ set activeTime(value: number | null);
43
+ get requestRecords(): RequestRecord[];
44
+ set requestRecords(value: RequestRecord[]);
45
+ get pendingRequestRecords(): RequestRecord[];
46
+ set pendingRequestRecords(value: RequestRecord[]);
47
+ get eventCount(): number;
48
+ set eventCount(value: number);
49
+ }
50
+ /** @internal */
51
+ export declare const storageManager: StorageManager;
52
+ export {};
@@ -0,0 +1,125 @@
1
+ import { WTInitialConfig } from "../types/config/initial-config";
2
+ import { WTEvent } from "../types/event/wt-event";
3
+ import { WTLogLevel } from "../utils/logger";
4
+ /**
5
+ * The main entry point for the WiseTrack Web SDK.
6
+ *
7
+ * Use this singleton to initialize the SDK, configure its behavior, and track events.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const initialConfig: WTInitialConfig = {
12
+ * appToken: appToken ?? "rMN5ZCwpOzY7",
13
+ * appFrameWork: "native",
14
+ * appVersion: "1.0.0",
15
+ * };
16
+ * await WiseTrack.instance.init(initialConfig);
17
+ * ```
18
+ */
19
+ export declare class WiseTrack {
20
+ private static _instance?;
21
+ /**
22
+ * Returns the singleton instance of the WiseTrack SDK.
23
+ */
24
+ static get instance(): WiseTrack;
25
+ private constructor();
26
+ private sdkInitialized;
27
+ /**
28
+ * Initializes the WiseTrack SDK with the given configuration.
29
+ *
30
+ * This method must be called before using any tracking features.
31
+ *
32
+ * @param initConfig - The initial configuration object.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * const initialConfig: WTInitialConfig = {
37
+ * appToken: appToken ?? "rMN5ZCwpOzY7",
38
+ * appFrameWork: "native", // your current web app framework (native, reactjs, nextjs, ...)
39
+ * appVersion: "1.0.0", // your current web app version
40
+ * };
41
+ *
42
+ * ```
43
+ */
44
+ init(initConfig: WTInitialConfig): Promise<void>;
45
+ /**
46
+ * Sets the log level for internal SDK logging.
47
+ *
48
+ * @param level - The desired log level.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * WiseTrack.instance.setLogLevel(WTLogLevel.WARN)
53
+ * // or
54
+ * WiseTrack.instance.setLogLevel("warn")
55
+ *
56
+ * ```
57
+ */
58
+ setLogLevel(level: WTLogLevel): void;
59
+ /**
60
+ * Clears all stored data and stops the tracker.
61
+ */
62
+ flush(): void;
63
+ /**
64
+ * Returns whether the SDK is currently enabled.
65
+ */
66
+ isEnabled(): boolean;
67
+ /**
68
+ * Enables or disables the SDK.
69
+ *
70
+ * Throws an error if the SDK is disabled by the server or needs an update.
71
+ *
72
+ * @param enabled - Whether to enable the SDK.
73
+ * @throws If the server has disabled the SDK or a forced update is required.
74
+ */
75
+ setEnabled(enabled: boolean): void;
76
+ /**
77
+ * Starts the tracking process.
78
+ *
79
+ * @remarks
80
+ * The SDK must be initialized and enabled before calling this method.
81
+ *
82
+ * NOTE: call this method just if you set startTrackerAutomatically=false in WTInitialConfig
83
+ */
84
+ startTracking(): Promise<void>;
85
+ /**
86
+ * Stops the tracking process.
87
+ */
88
+ stopTracking(): Promise<void>;
89
+ /**
90
+ * Sets the Firebase Cloud Messaging (FCM) push token for server.
91
+ *
92
+ * @param token - The FCM token.
93
+ */
94
+ setFCMToken(token: string): Promise<void>;
95
+ /**
96
+ * Tracks a custom event or revenue event.
97
+ *
98
+ * @param event - The event object to be tracked.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * // Create a Default Event
103
+ * const defaultEvent = new WTEvent.Default("default-event");
104
+ * defaultEvent.addParam("key1", "value1");
105
+ * defaultEvent.addParam("key2", 123);
106
+ * defaultEvent.addParam("key3", true);
107
+ * await WiseTrack.instance.trackEvent(defaultEvent);
108
+ *
109
+ * // Create a Revenue Event
110
+ * const revenueEvent = new WTEvent.Revenue("revenue-event", 100, "USD");
111
+ * revenueEvent.addParam("item_id", "item123");
112
+ * revenueEvent.addParam("quantity", 2);
113
+ * await WiseTrack.instance.trackEvent(revenueEvent);
114
+ * ```
115
+ */
116
+ trackEvent(event: WTEvent.Default | WTEvent.Revenue): Promise<void>;
117
+ /** @internal */
118
+ private getConfig;
119
+ /** @internal */
120
+ private updateAppSettings;
121
+ /** @internal */
122
+ private checkSdkEnabled;
123
+ /** @internal */
124
+ private checkSdkUpdate;
125
+ }
@@ -0,0 +1,25 @@
1
+ import { WTEvent } from "../types/event/wt-event";
2
+ /** @internal */
3
+ declare class WTTracker {
4
+ private isRunning;
5
+ private initialized;
6
+ private get isEnabled();
7
+ initialize(): Promise<void>;
8
+ startTracking(): Promise<void>;
9
+ stopTracking(): Promise<void>;
10
+ checkPushToken(token: string): Promise<void>;
11
+ trackEvent(event: WTEvent.Default | WTEvent.Revenue): Promise<void>;
12
+ private getCountryCode;
13
+ private createAttribution;
14
+ private checkFirstSession;
15
+ private checkSdkClicks;
16
+ private createRequest;
17
+ private createDeviceID;
18
+ private setActivityTimes;
19
+ private checkSessionIntervals;
20
+ private isVisibleFocused;
21
+ private addObservers;
22
+ }
23
+ /** @internal */
24
+ export declare const tracker: WTTracker;
25
+ export {};
@@ -0,0 +1,4 @@
1
+ export { WiseTrack } from "./core/wisetrack";
2
+ export { WTInitialConfig } from "./types/config/initial-config";
3
+ export { WTEvent } from "./types/event/wt-event";
4
+ export { WTLogEngine, WTLogger, WTLogLevel } from "./utils/logger";