Add custom amplitude server URL (#282)
* Add custom amplitude server URL * string * add to readme
This commit is contained in:
parent
e453977299
commit
3b75e60bd2
@ -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=
|
||||
|
||||
@ -78,6 +78,7 @@ Set environment variables via `.env`.
|
||||
- `VITE_V3_TOKEN_ADDRESS` (optional): Address of the V3 $DYDX token.
|
||||
- `VITE_TOKEN_MIGRATION_URI` (optional): The URL of the token migration website.
|
||||
- `AMPLITUDE_API_KEY` (optional): Amplitude API key for enabling Amplitude; used with `pnpm run build:inject-amplitude`.
|
||||
- `AMPLITUDE_SERVER_URL` (optional): Custom Amplitude server URL
|
||||
- `BUGSNAG_API_KEY` (optional): API key for enabling Bugsnag; used with `pnpm run build:inject-bugsnag`.
|
||||
- `IOS_APP_ID` (optional): iOS app ID used for enabling deep linking to the iOS app; used with `pnpm run build:inject-app-deeplinks`.
|
||||
- `INTERCOM_APP_ID` (optional): Used for enabling Intercom; utilized with `pnpm run build:inject-intercom`.
|
||||
|
||||
@ -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 = `<script type="module">
|
||||
!function(){var e="${AMPLITUDE_API_KEY}";e&&(globalThis.amplitude.init(e),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."))}();
|
||||
</script>`;
|
||||
!(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."));
|
||||
})();
|
||||
</script>`;
|
||||
|
||||
const injectedHtml = html.replace(
|
||||
'<div id="root"></div>',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user