Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(amplitude): Updates initialization.

Дамян Минков0097e08d6070
diff --git a/react/features/analytics/handlers/amplitude/lib.web.ts b/react/features/analytics/handlers/amplitude/lib.web.ts
index 704339d37b..4782bf174a 100644
--- a/react/features/analytics/handlers/amplitude/lib.web.ts
+++ b/react/features/analytics/handlers/amplitude/lib.web.ts
@@ -1,9 +1,50 @@
import { createInstance } from '@amplitude/analytics-browser';
+import { EnrichmentPlugin, Event, PluginType } from '@amplitude/analytics-types';
const amplitude = createInstance();
export default amplitude;
+function stripParam(url?: string): string | undefined {
+ if (!url) return url;
+
+ try {
+ const u = new URL(url);
+
+ u.hash = '';
+ u.search = '';
+
+ return u.toString();
+ } catch {
+ return url.split('#')[0].split('?')[0];
+ }
+}
+
+class StripParamsPlugin implements EnrichmentPlugin {
+ name: 'strip-params-plugin';
+ type: PluginType.ENRICHMENT;
+
+ async setup(): Promise<void> {
+ return undefined;
+ }
+
+ async execute(event: Event): Promise<Event | null> {
+ const { event_properties } = event;
+
+ if (event_properties) {
+ // These are only needed to make TS happy.
+ type EventPropertiesKey = keyof typeof event_properties;
+ const PAGE_LOCATION_KEY = '[Amplitude] Page Location' as EventPropertiesKey;
+ const PAGE_URL_KEY = '[Amplitude] Page URL' as EventPropertiesKey;
+
+ event_properties[PAGE_LOCATION_KEY] = stripParam(event_properties[PAGE_LOCATION_KEY]);
+ event_properties[PAGE_URL_KEY] = stripParam(event_properties[PAGE_URL_KEY]);
+ }
+
+ return event;
+ }
+}
+
/**
* Initializes the Amplitude instance.
*
@@ -31,8 +72,9 @@ export function initAmplitude(
formInteractions: false,
elementInteractions: false
},
- defaultTracking: false
};
+ amplitude.add(new StripParamsPlugin());
+
return amplitude.init(amplitudeAPPKey, user, options).promise;
}