diff --git a/.env.example b/.env.example index cbfc529..91cebfe 100644 --- a/.env.example +++ b/.env.example @@ -8,6 +8,7 @@ VITE_V3_TOKEN_ADDRESS= VITE_TOKEN_MIGRATION_URI= AMPLITUDE_API_KEY= +AMPLITUDE_SERVER_URL= BUGSNAG_API_KEY= IOS_APP_ID= INTERCOM_APP_ID= diff --git a/scripts/inject-amplitude.js b/scripts/inject-amplitude.js index 6848b45..77945a2 100644 --- a/scripts/inject-amplitude.js +++ b/scripts/inject-amplitude.js @@ -3,12 +3,13 @@ import path from 'path'; import { fileURLToPath } from 'url'; const AMPLITUDE_API_KEY = process.env.AMPLITUDE_API_KEY; +const AMPLITUDE_SERVER_URL = process.env.AMPLITUDE_SERVER_URL; const currentPath = fileURLToPath(import.meta.url); const projectRoot = path.dirname(currentPath); const htmlFilePath = path.resolve(projectRoot, '../dist/index.html'); -if(AMPLITUDE_API_KEY){ +if (AMPLITUDE_API_KEY) { try { const html = await fs.readFile(htmlFilePath, 'utf-8'); @@ -18,8 +19,34 @@ if(AMPLITUDE_API_KEY){ `; const amplitudeListenerScript = ``; + !(function () { + var e = "${AMPLITUDE_API_KEY}"; + e && + (globalThis.amplitude.init(e${ + AMPLITUDE_SERVER_URL + ? `, undefined, { + serverUrl: ${AMPLITUDE_SERVER_URL} + }` + : '' + }), + globalThis.amplitude.setOptOut(!1), + globalThis.addEventListener("dydx:track", function (e) { + var t = e.detail.eventType, + d = e.detail.eventData; + globalThis.amplitude.track(t, d); + }), + globalThis.addEventListener("dydx:identify", function (e) { + var t = e.detail.property, + d = e.detail.propertyValue; + if ("walletAddress" === t) globalThis.amplitude.setUserId(d); + else { + var i = new globalThis.amplitude.Identify(); + i.set(t, d), globalThis.amplitude.identify(i); + } + }), + console.log("Amplitude enabled.")); + })(); + `; const injectedHtml = html.replace( '
',