From f53c642888a9e270aaf350949b9192584d1db533 Mon Sep 17 00:00:00 2001 From: Viet Date: Tue, 2 Dec 2025 16:23:03 +0700 Subject: [PATCH] Track event attribute --- package.json | 2 +- src/utils/index.ts | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2cf9e4c..2aab7c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aesirx-analytics", - "version": "2.4.3", + "version": "2.4.4", "license": "GPL-3.0-only", "author": "AesirX", "repository": "https://gitlab.redweb.dk/aesirx/analytics", diff --git a/src/utils/index.ts b/src/utils/index.ts index 16b5dfb..6110edb 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -104,7 +104,7 @@ const startTracker = async ( } }; -const trackEvent = async (endpoint: string, referer?: string, data?: object, _url?: string) => { +const trackEvent = async (endpoint: string, referer?: string, data?: any, _url?: string) => { const allow = sessionStorage.getItem('aesirx-analytics-allow'); const reject = sessionStorage.getItem('aesirx-analytics-rejected'); if (allow === '0' || reject === 'true') { @@ -131,6 +131,22 @@ const trackEvent = async (endpoint: string, referer?: string, data?: object, _ur const ip = ''; const userTimeZone = Intl.DateTimeFormat().resolvedOptions()?.timeZone; + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const attributesVisit = data?.attributes; + const attributes = []; + for (const key of urlParams.keys()) { + if (key.startsWith('utm_') || key.startsWith('gad_')) { + urlParams.get(key) && attributes.push({ name: key, value: urlParams.get(key) }); + } + } + if (attributesVisit?.length) { + attributesVisit?.forEach((element: any) => { + element?.name && attributes.push({ name: element?.name, value: element?.value }); + }); + } + data.attributes = attributes; + const fingerprint = getFingerprint(); const headers = { type: 'application/json' }; const blobData = new Blob(