📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Add a timeout for psid / sid fetch
Blue Moused4f509097c11
diff --git a/web/app/utils/analytics.ts b/web/app/utils/analytics.tsindex 5d5f9b5bb..38a235400 100644--- a/web/app/utils/analytics.ts+++ b/web/app/utils/analytics.ts@@ -17,6 +17,7 @@ import { isBrowser, isDevelopment, isSelfhosted } from '~/lib/constants'export const SWETRIX_PID = 'STEzHcB1rALV'const SWETRIX_API_PROXY_PATH = '/_internal_data_inngest_proxy'+const REVENUE_ATTRIBUTION_TIMEOUT_MS = 2_000const isIframe = isBrowser ? window.self !== window.top : falsetype SessionReplayActions = Awaited<ReturnType<typeof startSessionReplay>>@@ -239,11 +240,24 @@ export const getRevenueAttribution = async (): Promise<{return {}}+ let timeoutId: ReturnType<typeof setTimeout> | undefined+try {- const [profileId, sessionId] = await Promise.all([- getProfileId(),- getSessionId(),- ])+ const attributionPromise = Promise.all([getProfileId(), getSessionId()])+ const timeoutPromise = new Promise<null>((resolve) => {+ timeoutId = setTimeout(+ () => resolve(null),+ REVENUE_ATTRIBUTION_TIMEOUT_MS,+ )+ })++ const attribution = await Promise.race([attributionPromise, timeoutPromise])++ if (!attribution) {+ return {}+ }++ const [profileId, sessionId] = attributionreturn {...(profileId ? { swetrixProfileId: profileId } : {}),@@ -252,5 +266,9 @@ export const getRevenueAttribution = async (): Promise<{} catch (reason) {console.error('Failed to get revenue attribution:', reason)return {}+ } finally {+ if (timeoutId) {+ clearTimeout(timeoutId)+ }}}