@base44/sdk 0.8.12 → 0.8.13

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 base44
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -2,6 +2,8 @@ import { AxiosInstance } from "axios";
2
2
  import { TrackEventParams, AnalyticsModuleOptions } from "./analytics.types";
3
3
  import type { AuthModule } from "./auth.types";
4
4
  export declare const USER_HEARTBEAT_EVENT_NAME = "__user_heartbeat_event__";
5
+ export declare const ANALYTICS_INITIALIZATION_EVENT_NAME = "__initialization_event__";
6
+ export declare const ANALYTICS_SESSION_DURATION_EVENT_NAME = "__session_duration_event__";
5
7
  export declare const ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY = "analytics-enable";
6
8
  export declare const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "base44_analytics_session_id";
7
9
  export interface AnalyticsModuleArgs {
@@ -1,6 +1,8 @@
1
1
  import { getSharedInstance } from "../utils/sharedInstance.js";
2
2
  import { generateUuid } from "../utils/common.js";
3
3
  export const USER_HEARTBEAT_EVENT_NAME = "__user_heartbeat_event__";
4
+ export const ANALYTICS_INITIALIZATION_EVENT_NAME = "__initialization_event__";
5
+ export const ANALYTICS_SESSION_DURATION_EVENT_NAME = "__session_duration_event__";
4
6
  export const ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY = "analytics-enable";
5
7
  export const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "base44_analytics_session_id";
6
8
  const defaultConfiguration = {
@@ -20,7 +22,9 @@ const analyticsSharedState = getSharedInstance(ANALYTICS_SHARED_STATE_NAME, () =
20
22
  requestsQueue: [],
21
23
  isProcessing: false,
22
24
  isHeartBeatProcessing: false,
25
+ wasInitializationTracked: false,
23
26
  sessionContext: null,
27
+ sessionStartTime: null,
24
28
  config: {
25
29
  ...defaultConfiguration,
26
30
  ...getAnalyticsConfigFromUrlParams(),
@@ -95,10 +99,12 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
95
99
  batchSize,
96
100
  });
97
101
  clearHeartBeatProcessor = startHeartBeatProcessor(track);
102
+ setSessionDurationTimerStart();
98
103
  };
99
104
  const onDocHidden = () => {
100
105
  stopAnalyticsProcessor();
101
106
  clearHeartBeatProcessor === null || clearHeartBeatProcessor === void 0 ? void 0 : clearHeartBeatProcessor();
107
+ trackSessionDurationEvent(track);
102
108
  // flush entire queue on visibility change and hope for the best //
103
109
  const eventsData = analyticsSharedState.requestsQueue.splice(0);
104
110
  flush(eventsData, { isBeacon: true });
@@ -124,6 +130,8 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
124
130
  startProcessing();
125
131
  // start the heart beat processor //
126
132
  clearHeartBeatProcessor = startHeartBeatProcessor(track);
133
+ // track the referrer event //
134
+ trackInitializationEvent(track);
127
135
  // start the visibility change listener //
128
136
  if (typeof window !== "undefined") {
129
137
  window.addEventListener("visibilitychange", onVisibilityChange);
@@ -166,6 +174,38 @@ function startHeartBeatProcessor(track) {
166
174
  analyticsSharedState.isHeartBeatProcessing = false;
167
175
  };
168
176
  }
177
+ function trackInitializationEvent(track) {
178
+ if (typeof window === "undefined" ||
179
+ analyticsSharedState.wasInitializationTracked) {
180
+ return;
181
+ }
182
+ analyticsSharedState.wasInitializationTracked = true;
183
+ track({
184
+ eventName: ANALYTICS_INITIALIZATION_EVENT_NAME,
185
+ properties: {
186
+ referrer: document === null || document === void 0 ? void 0 : document.referrer,
187
+ },
188
+ });
189
+ }
190
+ function setSessionDurationTimerStart() {
191
+ if (typeof window === "undefined" ||
192
+ analyticsSharedState.sessionStartTime !== null) {
193
+ return;
194
+ }
195
+ analyticsSharedState.sessionStartTime = new Date().toISOString();
196
+ }
197
+ function trackSessionDurationEvent(track) {
198
+ if (typeof window === "undefined" ||
199
+ analyticsSharedState.sessionStartTime === null)
200
+ return;
201
+ const sessionDuration = new Date().getTime() -
202
+ new Date(analyticsSharedState.sessionStartTime).getTime();
203
+ analyticsSharedState.sessionStartTime = null;
204
+ track({
205
+ eventName: ANALYTICS_SESSION_DURATION_EVENT_NAME,
206
+ properties: { sessionDuration },
207
+ });
208
+ }
169
209
  function getEventIntrinsicData() {
170
210
  return {
171
211
  timestamp: new Date().toISOString(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44/sdk",
3
- "version": "0.8.12",
3
+ "version": "0.8.13",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -55,10 +55,10 @@
55
55
  "license": "MIT",
56
56
  "repository": {
57
57
  "type": "git",
58
- "url": "git+https://github.com/base44/sdk.git"
58
+ "url": "git+https://github.com/base44/javascript-sdk.git"
59
59
  },
60
60
  "bugs": {
61
- "url": "https://github.com/base44/sdk/issues"
61
+ "url": "https://github.com/base44/javascript-sdk/issues"
62
62
  },
63
- "homepage": "https://github.com/base44/sdk#readme"
63
+ "homepage": "https://github.com/base44/javascript-sdk#readme"
64
64
  }