@base44-preview/sdk 0.8.6-pr.57.0298afb → 0.8.6-pr.57.346f67a
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.
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import { getSharedInstance
|
|
1
|
+
import { getSharedInstance } from "../utils/sharedInstance";
|
|
2
|
+
const defaultConfiguration = {
|
|
3
|
+
enabled: true,
|
|
4
|
+
maxQueueSize: 1000,
|
|
5
|
+
throttleTime: 1000,
|
|
6
|
+
batchSize: 30,
|
|
7
|
+
};
|
|
2
8
|
///////////////////////////////////////////////
|
|
3
9
|
//// shared queue for analytics events ////
|
|
4
10
|
///////////////////////////////////////////////
|
|
@@ -7,21 +13,24 @@ const ANALYTICS_SHARED_STATE_NAME = "analytics";
|
|
|
7
13
|
const analyticsSharedState = getSharedInstance(ANALYTICS_SHARED_STATE_NAME, () => ({
|
|
8
14
|
requestsQueue: [],
|
|
9
15
|
isProcessing: false,
|
|
16
|
+
sessionContext: null,
|
|
17
|
+
config: {
|
|
18
|
+
...defaultConfiguration,
|
|
19
|
+
...getAnalyticsModuleOptionsFromUrlParams(),
|
|
20
|
+
},
|
|
10
21
|
}));
|
|
11
22
|
export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthModule, }) => {
|
|
12
|
-
var _a;
|
|
13
23
|
// prevent overflow of events //
|
|
14
|
-
const { enabled
|
|
24
|
+
const { enabled, maxQueueSize, throttleTime, batchSize } = analyticsSharedState.config;
|
|
15
25
|
const trackBatchUrl = `${serverUrl}/api/apps/${appId}/analytics/track/batch`;
|
|
16
|
-
let sessionContext = null;
|
|
17
26
|
const getSessionContext = async () => {
|
|
18
|
-
if (sessionContext)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
return sessionContext;
|
|
27
|
+
if (!analyticsSharedState.sessionContext) {
|
|
28
|
+
const user = await userAuthModule.me();
|
|
29
|
+
analyticsSharedState.sessionContext = {
|
|
30
|
+
user_id: user.id,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return analyticsSharedState.sessionContext;
|
|
25
34
|
};
|
|
26
35
|
const track = (params) => {
|
|
27
36
|
if (!enabled || analyticsSharedState.requestsQueue.length >= maxQueueSize) {
|
|
@@ -41,7 +50,7 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
|
|
|
41
50
|
});
|
|
42
51
|
};
|
|
43
52
|
const flush = async (eventsData) => {
|
|
44
|
-
const sessionContext_ =
|
|
53
|
+
const sessionContext_ = await getSessionContext();
|
|
45
54
|
const events = eventsData.map(transformEventDataToApiRequestData(sessionContext_));
|
|
46
55
|
const beaconPayload = JSON.stringify({ events });
|
|
47
56
|
if (typeof navigator === "undefined" ||
|
|
@@ -9,13 +9,7 @@ export function getSharedInstance(name, factory) {
|
|
|
9
9
|
if (!windowObj.base44SharedInstances[name]) {
|
|
10
10
|
windowObj.base44SharedInstances[name] = {
|
|
11
11
|
instance: factory(),
|
|
12
|
-
_refCount: 0,
|
|
13
12
|
};
|
|
14
13
|
}
|
|
15
|
-
windowObj.base44SharedInstances[name]._refCount++;
|
|
16
14
|
return windowObj.base44SharedInstances[name].instance;
|
|
17
15
|
}
|
|
18
|
-
export function getSharedInstanceRefCount(name) {
|
|
19
|
-
var _a, _b, _c;
|
|
20
|
-
return (_c = (_b = (_a = windowObj.base44SharedInstances) === null || _a === void 0 ? void 0 : _a[name]) === null || _b === void 0 ? void 0 : _b._refCount) !== null && _c !== void 0 ? _c : 0;
|
|
21
|
-
}
|