forked from JackHamer09/zksync-plus
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a33d94
commit 8d99b0b
Showing
8 changed files
with
54 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
WALLET_CONNECT_PROJECT_ID=373a8744ceaac00934aec708a3fceea6 | ||
ANKR_TOKEN= | ||
DATAPLANE_URL= | ||
RUDDER_KEY= | ||
ANKR_TOKEN= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,46 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let rudderanalytics: any = null; | ||
let analyticsLoaded = false; | ||
|
||
export async function initAnalytics(): Promise<boolean> { | ||
const runtimeConfig = useRuntimeConfig(); | ||
|
||
if (runtimeConfig.public.rudderKey && runtimeConfig.public.dataplaneUrl) { | ||
if (rudderanalytics) { | ||
return true; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
while (!(window as any).rudderanalytics) { | ||
await setTimeout(() => { | ||
return; | ||
}, 500); | ||
const isReady = (): Promise<void> => { | ||
return new Promise((resolve, reject) => { | ||
if (!window.rudderanalytics) { | ||
reject(new Error("Rudder not loaded")); | ||
} | ||
window.rudderanalytics?.ready(() => { | ||
resolve(); | ||
}); | ||
}); | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
rudderanalytics = (window as any).rudderanalytics; | ||
export async function initAnalytics(): Promise<boolean> { | ||
const runtimeConfig = useRuntimeConfig(); | ||
if (!runtimeConfig.public.rudderKey || !runtimeConfig.public.dataplaneUrl) { | ||
return false; | ||
} | ||
|
||
await rudderanalytics.load(runtimeConfig.public.rudderKey, runtimeConfig.public.dataplaneUrl); | ||
await rudderanalytics.ready(); | ||
if (analyticsLoaded) { | ||
await isReady(); | ||
return true; | ||
} | ||
return false; | ||
await retry(async () => { | ||
if (!window.rudderanalytics) { | ||
await new Promise((resolve) => setTimeout(resolve, 250)); | ||
throw new Error("Rudder not loaded"); | ||
} | ||
}); | ||
window.rudderanalytics?.load(runtimeConfig.public.rudderKey, runtimeConfig.public.dataplaneUrl); | ||
analyticsLoaded = true; | ||
await isReady(); | ||
return true; | ||
} | ||
|
||
export async function trackPage(): Promise<void> { | ||
if (await initAnalytics()) { | ||
await rudderanalytics.page(); | ||
window.rudderanalytics?.page(); | ||
} | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export async function trackEvent(eventName: string, params?: any): Promise<void> { | ||
export async function trackEvent(eventName: string, params?: unknown): Promise<void> { | ||
if (await initAnalytics()) { | ||
await rudderanalytics.track(eventName, params); | ||
window.rudderanalytics?.track(eventName, params); | ||
} | ||
} |