Skip to content

Commit

Permalink
feat(chore): removing masa analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
githubdoramon committed May 20, 2024
1 parent 1d461dc commit caed8c8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 38 deletions.
1 change: 0 additions & 1 deletion store/onboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export const useOnboardStore = defineStore("onboard", () => {
await identifyWalletName();
account.value = updatedAccount;
connectorName.value = updatedAccount.connector?.name;
identifyWallet(updatedAccount.address, walletName.value);
} catch (err) {
disconnect();
const error = formatError(err as Error);
Expand Down
39 changes: 2 additions & 37 deletions utils/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Hash } from "@/types";

let analyticsLoaded = false;

async function loadRudder() {
Expand All @@ -14,32 +12,20 @@ async function loadRudder() {
);
}

async function loadMasa() {
if (!window.MA) {
await new Promise((resolve) => setTimeout(resolve, 250));
throw new Error("Masa not loaded");
}
const runtimeConfig = useRuntimeConfig();
window.masaAnalytics = new window.MA.MasaAnalytics({
clientId: runtimeConfig.public.analytics.masa.clientId,
});
}

export async function initAnalytics(): Promise<boolean> {
if (analyticsLoaded) return true;

const runtimeConfig = useRuntimeConfig();
const useRudder = Boolean(
runtimeConfig.public.analytics.rudder.key && runtimeConfig.public.analytics.rudder.dataplaneUrl
);
const useMasa = Boolean(runtimeConfig.public.analytics.masa.clientId && runtimeConfig.public.analytics.masa.appId);
if ((!useRudder && !useMasa) || analyticsLoaded) {

if (!useRudder || analyticsLoaded) {
return false;
}

const services = [];
if (useRudder) services.push(loadRudder());
if (useMasa) services.push(loadMasa());

await Promise.all(services);
analyticsLoaded = true;
Expand All @@ -48,33 +34,12 @@ export async function initAnalytics(): Promise<boolean> {

export async function trackPage(): Promise<void> {
if (await initAnalytics()) {
const runtimeConfig = useRuntimeConfig();
window.rudderanalytics?.page();
window.masaAnalytics?.firePageViewEvent({
page: window.location.href,
additionalEventData: { appId: runtimeConfig.public.analytics.masa.appId },
});
}
}

export async function trackEvent(eventName: string, params?: object): Promise<void> {
if (await initAnalytics()) {
const runtimeConfig = useRuntimeConfig();
window.rudderanalytics?.track(eventName, params);
window.masaAnalytics?.trackCustomEvent({
eventName,
additionalEventData: { appId: runtimeConfig.public.analytics.masa.appId, ...params },
});
}
}

export async function identifyWallet(userAddress: Hash | undefined, walletType?: string): Promise<void> {
if (await initAnalytics()) {
const runtimeConfig = useRuntimeConfig();
window.masaAnalytics?.fireConnectWalletEvent({
user_address: userAddress,
wallet_type: walletType,
additionalEventData: { appId: runtimeConfig.public.analytics.masa.appId },
});
}
}

0 comments on commit caed8c8

Please sign in to comment.