@base44-preview/sdk 0.8.6-pr.57.5d40d85 → 0.8.6-pr.57.bb6a61e

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.
@@ -32,16 +32,6 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
32
32
  }
33
33
  return analyticsSharedState.sessionContext;
34
34
  };
35
- const track = (params) => {
36
- if (!enabled || analyticsSharedState.requestsQueue.length >= maxQueueSize) {
37
- return;
38
- }
39
- const intrinsicData = getEventIntrinsicData();
40
- analyticsSharedState.requestsQueue.push({
41
- ...params,
42
- ...intrinsicData,
43
- });
44
- };
45
35
  const batchRequestFallback = async (events) => {
46
36
  await axiosClient.request({
47
37
  method: "POST",
@@ -85,19 +75,33 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
85
75
  if (typeof window !== "undefined" && enabled) {
86
76
  window.addEventListener("visibilitychange", onVisibilityChange);
87
77
  }
88
- // start analytics processor only if it's the first instance and analytics is enabled //
89
- if (enabled) {
78
+ const startProcessing = () => {
79
+ if (!enabled)
80
+ return;
90
81
  startAnalyticsProcessor(flush, {
91
82
  throttleTime,
92
83
  batchSize,
93
84
  });
94
- }
85
+ };
86
+ const track = (params) => {
87
+ if (!enabled || analyticsSharedState.requestsQueue.length >= maxQueueSize) {
88
+ return;
89
+ }
90
+ const intrinsicData = getEventIntrinsicData();
91
+ analyticsSharedState.requestsQueue.push({
92
+ ...params,
93
+ ...intrinsicData,
94
+ });
95
+ startProcessing();
96
+ };
95
97
  const cleanup = () => {
96
98
  if (typeof window === "undefined")
97
99
  return;
98
100
  window.removeEventListener("visibilitychange", onVisibilityChange);
99
101
  stopAnalyticsProcessor();
100
102
  };
103
+ // start the flusing process ///
104
+ startProcessing();
101
105
  return {
102
106
  track,
103
107
  cleanup,
@@ -108,11 +112,13 @@ function stopAnalyticsProcessor() {
108
112
  }
109
113
  async function startAnalyticsProcessor(handleTrack, options) {
110
114
  if (analyticsSharedState.isProcessing) {
115
+ // only one instance of the analytics processor can be running at a time //
111
116
  return;
112
117
  }
113
118
  analyticsSharedState.isProcessing = true;
114
119
  const { throttleTime = 1000, batchSize = 30 } = options !== null && options !== void 0 ? options : {};
115
- while (analyticsSharedState.isProcessing) {
120
+ while (analyticsSharedState.isProcessing &&
121
+ analyticsSharedState.requestsQueue.length > 0) {
116
122
  const requests = analyticsSharedState.requestsQueue.splice(0, batchSize);
117
123
  if (requests.length > 0) {
118
124
  try {
@@ -125,6 +131,7 @@ async function startAnalyticsProcessor(handleTrack, options) {
125
131
  }
126
132
  await new Promise((resolve) => setTimeout(resolve, throttleTime));
127
133
  }
134
+ analyticsSharedState.isProcessing = false;
128
135
  }
129
136
  function getEventIntrinsicData() {
130
137
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.6-pr.57.5d40d85",
3
+ "version": "0.8.6-pr.57.bb6a61e",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",