@formo/analytics 1.11.6-alpha.4 → 1.11.6-alpha.6
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/dist/cjs/src/FormoAnalytics.d.ts.map +1 -1
- package/dist/cjs/src/FormoAnalytics.js +50 -24
- package/dist/cjs/src/FormoAnalytics.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/src/FormoAnalytics.d.ts.map +1 -1
- package/dist/esm/src/FormoAnalytics.js +50 -24
- package/dist/esm/src/FormoAnalytics.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/FormoAnalytics.ts +79 -59
package/package.json
CHANGED
package/src/FormoAnalytics.ts
CHANGED
|
@@ -133,60 +133,61 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
133
133
|
this.setSessionCookie();
|
|
134
134
|
const address = await this.getCurrentWallet();
|
|
135
135
|
|
|
136
|
+
console.log('Wallet address before sending event:', address); // Add this log
|
|
137
|
+
|
|
136
138
|
const requestData = {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
address: address,
|
|
140
|
+
session_id: this.getSessionId(),
|
|
141
|
+
timestamp: new Date().toISOString(),
|
|
142
|
+
action,
|
|
143
|
+
version: '1',
|
|
144
|
+
payload,
|
|
143
145
|
};
|
|
144
146
|
|
|
145
147
|
const sendRequest = async (): Promise<void> => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
148
|
+
try {
|
|
149
|
+
const response = await axios.post(
|
|
150
|
+
EVENTS_API_URL,
|
|
151
|
+
JSON.stringify(requestData),
|
|
152
|
+
{
|
|
153
|
+
headers: {
|
|
154
|
+
'Content-Type': 'application/json',
|
|
155
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
156
|
+
},
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
if (response.status >= 200 && response.status < 300) {
|
|
161
|
+
console.log('address:', address);
|
|
162
|
+
console.log('Event sent successfully:', action);
|
|
163
|
+
} else {
|
|
164
|
+
throw new Error(`Failed with status: ${response.status}`);
|
|
165
|
+
}
|
|
166
|
+
} catch (error) {
|
|
167
|
+
attempt++;
|
|
168
|
+
|
|
169
|
+
if (attempt <= maxRetries) {
|
|
170
|
+
const retryDelay = Math.pow(2, attempt) * 1000;
|
|
171
|
+
console.error(
|
|
172
|
+
`Attempt ${attempt}: Retrying event "${action}" in ${
|
|
173
|
+
retryDelay / 1000
|
|
174
|
+
} seconds...`
|
|
175
|
+
);
|
|
176
|
+
setTimeout(sendRequest, retryDelay);
|
|
177
|
+
} else {
|
|
178
|
+
H.consumeError(
|
|
179
|
+
error as Error,
|
|
180
|
+
`Request data: ${JSON.stringify(requestData)}`
|
|
181
|
+
);
|
|
182
|
+
console.error(
|
|
183
|
+
`Event "${action}" failed after ${maxRetries} attempts. Error: ${error}`
|
|
184
|
+
);
|
|
185
|
+
}
|
|
163
186
|
}
|
|
164
|
-
} catch (error) {
|
|
165
|
-
attempt++;
|
|
166
|
-
|
|
167
|
-
if (attempt <= maxRetries) {
|
|
168
|
-
const retryDelay = Math.pow(2, attempt) * 1000;
|
|
169
|
-
console.error(
|
|
170
|
-
`Attempt ${attempt}: Retrying event "${action}" in ${
|
|
171
|
-
retryDelay / 1000
|
|
172
|
-
} seconds...`
|
|
173
|
-
);
|
|
174
|
-
setTimeout(sendRequest, retryDelay);
|
|
175
|
-
} else {
|
|
176
|
-
H.consumeError(
|
|
177
|
-
error as Error,
|
|
178
|
-
`Request data: ${JSON.stringify(requestData)}`
|
|
179
|
-
);
|
|
180
|
-
console.error(
|
|
181
|
-
`Event "${action}" failed after ${maxRetries} attempts. Error: ${error}`
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
187
|
};
|
|
186
188
|
|
|
187
|
-
this.getCurrentWallet();
|
|
188
189
|
await sendRequest();
|
|
189
|
-
|
|
190
|
+
}
|
|
190
191
|
|
|
191
192
|
// Function to track page hits
|
|
192
193
|
private trackPageHit() {
|
|
@@ -227,41 +228,56 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
227
228
|
|
|
228
229
|
private trackProvider(provider: EIP1193Provider) {
|
|
229
230
|
if (provider === this._provider) {
|
|
230
|
-
|
|
231
|
+
console.log('Provider already tracked.');
|
|
232
|
+
return;
|
|
231
233
|
}
|
|
232
234
|
|
|
233
235
|
this.currentChainId = undefined;
|
|
234
236
|
this.currentConnectedAddress = undefined;
|
|
235
237
|
|
|
236
238
|
if (this._provider) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
239
|
+
const eventNames = Object.keys(this._registeredProviderListeners);
|
|
240
|
+
for (const eventName of eventNames) {
|
|
241
|
+
this._provider.removeListener(
|
|
242
|
+
eventName,
|
|
243
|
+
this._registeredProviderListeners[eventName]
|
|
244
|
+
);
|
|
245
|
+
delete this._registeredProviderListeners[eventName];
|
|
246
|
+
}
|
|
245
247
|
}
|
|
246
248
|
|
|
249
|
+
console.log('Tracking new provider:', provider);
|
|
247
250
|
this._provider = provider;
|
|
248
251
|
|
|
249
252
|
this.getCurrentWallet();
|
|
250
253
|
this.registerAddressChangedListener();
|
|
251
254
|
this.registerChainChangedListener();
|
|
252
|
-
|
|
255
|
+
}
|
|
253
256
|
|
|
254
257
|
private async getCurrentWallet() {
|
|
255
258
|
if (!this.provider) {
|
|
256
259
|
console.warn('FormoAnalytics::getCurrentWallet: the provider is not set');
|
|
257
260
|
return;
|
|
258
261
|
}
|
|
262
|
+
|
|
259
263
|
const sessionData = sessionStorage.getItem(this.walletAddressSessionKey);
|
|
264
|
+
|
|
260
265
|
if (!sessionData) {
|
|
266
|
+
console.warn('Session data missing. Attempting to fetch address from provider.');
|
|
267
|
+
try {
|
|
268
|
+
const accounts = await this.provider.request<string[]>({
|
|
269
|
+
method: 'eth_accounts',
|
|
270
|
+
});
|
|
271
|
+
if (accounts && accounts.length > 0) {
|
|
272
|
+
const address = accounts[0];
|
|
273
|
+
this.storeWalletAddress(address);
|
|
274
|
+
return address;
|
|
275
|
+
}
|
|
276
|
+
} catch (err) {
|
|
277
|
+
console.error('Failed to fetch accounts from provider:', err);
|
|
278
|
+
}
|
|
261
279
|
return null;
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
console.warn(sessionData);
|
|
280
|
+
}
|
|
265
281
|
|
|
266
282
|
const parsedData = JSON.parse(sessionData);
|
|
267
283
|
const sessionExpiry = 30 * 60 * 1000; // 30 minutes
|
|
@@ -314,6 +330,7 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
314
330
|
}
|
|
315
331
|
|
|
316
332
|
private async onAddressChanged(addresses: string[]) {
|
|
333
|
+
console.log('onAddressChanged');
|
|
317
334
|
if (addresses.length > 0) {
|
|
318
335
|
const newAccount = addresses[0];
|
|
319
336
|
if (newAccount !== this.currentConnectedAddress) {
|
|
@@ -325,6 +342,7 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
325
342
|
}
|
|
326
343
|
|
|
327
344
|
private async onAddressConnected(address: string) {
|
|
345
|
+
console.log('onAddressConnected');
|
|
328
346
|
if (address === this.currentConnectedAddress) {
|
|
329
347
|
// We have already reported this address
|
|
330
348
|
return;
|
|
@@ -332,6 +350,8 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
332
350
|
this.currentConnectedAddress = address;
|
|
333
351
|
}
|
|
334
352
|
|
|
353
|
+
console.log('this.currentConnectedAddress: ', this.currentConnectedAddress);
|
|
354
|
+
|
|
335
355
|
this.currentChainId = await this.getCurrentChainId();
|
|
336
356
|
|
|
337
357
|
this.connect({ chainId: this.currentChainId, address });
|