Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove masa analytics #174

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ jobs:
echo "SCREENING_API_URL=${{ secrets.SCREENING_API_URL }}" >> .env
echo "DATAPLANE_URL=${{ secrets.DATAPLANE_URL }}" >> .env
echo "RUDDER_KEY=${{ secrets.RUDDER_KEY }}" >> .env
echo "MASA_KEY=${{ secrets.MASA_KEY }}" >> .env
echo "MASA_APP_ID=${{ secrets.MASA_APP_ID }}" >> .env
- name: Build
run: |
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ jobs:
echo "SCREENING_API_URL=${{ secrets.SCREENING_API_URL }}" >> .env
echo "DATAPLANE_URL=${{ secrets.DATAPLANE_URL }}" >> .env
echo "RUDDER_KEY=${{ secrets.RUDDER_KEY }}" >> .env
echo "MASA_KEY=${{ secrets.MASA_KEY }}" >> .env
echo "MASA_APP_ID=${{ secrets.MASA_APP_ID }}" >> .env
- name: Build
run: |
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ jobs:
echo "SCREENING_API_URL=${{ secrets.SCREENING_API_URL }}" >> .env
echo "DATAPLANE_URL=${{ secrets.DATAPLANE_URL }}" >> .env
echo "RUDDER_KEY=${{ secrets.RUDDER_KEY }}" >> .env
echo "MASA_KEY=${{ secrets.MASA_KEY }}" >> .env
echo "MASA_APP_ID=${{ secrets.MASA_APP_ID }}" >> .env
- name: Build
run: |
Expand Down
12 changes: 0 additions & 12 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,11 @@ export default defineNuxtConfig({
},
],
script: [
{
src: "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",
},
{
hid: "Rudder-JS",
src: "https://cdn.rudderlabs.com/v1.1/rudder-analytics.min.js",
defer: true,
},
{
hid: "MASA-JS",
src: "https://cdn.jsdelivr.net/npm/@masa-finance/analytics-sdk@latest/dist/browser/masa-analytics.min.js",
defer: true,
},
],
},
},
Expand Down Expand Up @@ -89,10 +81,6 @@ export default defineNuxtConfig({
key: process.env.RUDDER_KEY,
dataplaneUrl: process.env.DATAPLANE_URL,
},
masa: {
clientId: process.env.MASA_KEY,
appId: process.env.MASA_APP_ID,
},
},
},
},
Expand Down
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
26 changes: 0 additions & 26 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,38 +124,12 @@ export declare namespace Api {

declare global {
interface Window {
turnstile?: {
render: (
element: string | HTMLElement,
options: {
sitekey: string;
theme: "light" | "dark" | "auto";
language: string;
appearance: "always" | "execute" | "interaction-only";
callback: (response: string) => void;
"expired-callback": (response: string) => void;
"error-callback": (response: string) => void;
}
) => string | undefined;
reset: (widgetId: string) => void;
};
rudderanalytics?: {
load: (key: string, url: string) => void;
ready: (callback: () => void) => void;
page: () => void;
track: (eventName: string, params?: unknown) => void;
initialized: boolean;
};
MA?: {
MasaAnalytics: {
new ({ clientId });
};
};
masaAnalytics?: {
trackCustomEvent: ({ eventName, additionalEventData }) => void;
firePageViewEvent: ({ page, additionalEventData }) => void;
fireConnectWalletEvent: ({ user_address, wallet_type, additionalEventData }) => void;
initialized: boolean;
};
}
}
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 },
});
}
}
Loading