introducing isFirstPageView property in Page event and in new identity call for Marketing traffic source attribution (#1719)

This commit is contained in:
jasonbryant84
2025-06-19 13:25:56 +01:00
committed by GitHub
parent 465dc8e4e3
commit 4e4fcdc134
3 changed files with 27 additions and 3 deletions
@@ -105,7 +105,7 @@ export function addGA4Properties(properties) {
properties.ga_client_id = getCookie('_ga')?.replace('GA1.1.','');
}
export function addUTMToLinks() {
export function getUTMParams() {
const urlParams = new URLSearchParams(window.location.search);
// Gather all GTM related params
@@ -122,6 +122,12 @@ export function addUTMToLinks() {
content: urlParams.get('utm_content')
};
return [utmIds, utmParams];
}
export function addUTMToLinks() {
const [utmIds, utmParams] = getUTMParams();
// Create new params string for outbound links and store in sessionStorage
let newParams = '';
for (const key in utmIds) {
@@ -1,4 +1,4 @@
import { addGA4Properties, addUTMToLinks, getCookie, tagCloudUILinksWithAnonymousId } from './helpers';
import { addGA4Properties, addUTMToLinks, getCookie, getUTMParams, tagCloudUILinksWithAnonymousId } from './helpers';
import { registerAndCall } from './onetrust-helpers';
const PAGES_SESSION_STORAGE_KEY = 'segmentPages';
@@ -96,7 +96,8 @@ const trackPageView = () => {
const category = 'Qdrant.tech';
const name = nameMapper(window.location.href);
const properties = {};
const isFirstPageView = localStorage.getItem('isFirstPageView');
const properties = { isFirstPageView };
addGA4Properties(properties);
window.analytics.page(category, name, properties);
@@ -143,6 +144,19 @@ export function handleSegmentReady() {
addUTMToLinks();
analytics.ready(() => {
const [utmIds, utmParams] = getUTMParams();
const isFirstPageView = localStorage.getItem('isFirstPageView');
if (isFirstPageView === 'true') {
analytics.identify({
firstVisitAttribution: {
referrer: document.referrer,
...utmParams,
...utmIds
}
});
}
registerAndCall();
tagCloudUILinksWithAnonymousId();
tagAllAnchors();