mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
only track required params
This commit is contained in:
@@ -6,7 +6,7 @@ import { user } from '$lib/stores/user';
|
||||
import { ENV, MODE, VARS, isCloud } from '$lib/system';
|
||||
import { AppwriteException } from '@appwrite.io/console';
|
||||
import { browser } from '$app/environment';
|
||||
import { getReferrerAndUtmSource, getAllQueryParams } from '$lib/helpers/utm';
|
||||
import { getReferrerAndUtmSource, getTrackedQueryParams } from '$lib/helpers/utm';
|
||||
|
||||
function plausible(domain: string): AnalyticsPlugin {
|
||||
if (!browser) return { name: 'analytics-plugin-plausible' };
|
||||
@@ -65,7 +65,7 @@ export function trackEvent(name: string, data: object = null): void {
|
||||
};
|
||||
}
|
||||
|
||||
data = { ...data, ...getReferrerAndUtmSource(), params: getAllQueryParams() };
|
||||
data = { ...data, ...getReferrerAndUtmSource(), ...getTrackedQueryParams() };
|
||||
|
||||
if (ENV.DEV || ENV.PREVIEW) {
|
||||
console.debug(`[Analytics] Event ${name} ${path}`, data);
|
||||
|
||||
+28
-15
@@ -1,3 +1,17 @@
|
||||
const LINKEDIN_TRACKING_ID = 'li_fat_id';
|
||||
const GOOGLE_TRACKING_ID = 'gclid';
|
||||
const TWITTER_TRACKING_ID = 'twclid';
|
||||
const REDDIT_TRACKING_ID = 'rdt_cid';
|
||||
|
||||
const TRACKED_QUERY_PARAMS = [
|
||||
LINKEDIN_TRACKING_ID,
|
||||
GOOGLE_TRACKING_ID,
|
||||
TWITTER_TRACKING_ID,
|
||||
REDDIT_TRACKING_ID
|
||||
] as const;
|
||||
|
||||
type TrackedParams = Record<(typeof TRACKED_QUERY_PARAMS)[number], string>;
|
||||
|
||||
export function getReferrerAndUtmSource() {
|
||||
if (sessionStorage) {
|
||||
let values = {};
|
||||
@@ -16,26 +30,25 @@ export function getReferrerAndUtmSource() {
|
||||
return {};
|
||||
}
|
||||
|
||||
export function getAllQueryParams() {
|
||||
if (typeof window !== 'undefined' && window.location) {
|
||||
export function getTrackedQueryParams(): Partial<TrackedParams> {
|
||||
if (typeof window === 'undefined' || !window.location) {
|
||||
return {};
|
||||
}
|
||||
|
||||
try {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const params = {};
|
||||
const params: Partial<TrackedParams> = {};
|
||||
|
||||
const utmParams = new Set([
|
||||
'utm_source',
|
||||
'utm_medium',
|
||||
'utm_campaign',
|
||||
'utm_term',
|
||||
'utm_content'
|
||||
]);
|
||||
|
||||
for (const [key, value] of urlParams.entries()) {
|
||||
if (!utmParams.has(key.toLowerCase())) {
|
||||
params[key] = value;
|
||||
for (const paramName of TRACKED_QUERY_PARAMS) {
|
||||
const value = urlParams.get(paramName);
|
||||
if (value) {
|
||||
params[paramName] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
} catch (error) {
|
||||
console.warn('Failed to parse URL search parameters:', error);
|
||||
return {};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user