mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-01 17:08:30 +02:00
adding GA4 properties to Segment analytics events (#1253)
This commit is contained in:
@@ -98,3 +98,9 @@ export function tagCloudUILinksWithAnonymousId() {
|
||||
link.href = addOrUpdateQueryParam(link.href, CROSS_SITE_URL_PARAM_KEY, anonymousId);
|
||||
});
|
||||
}
|
||||
|
||||
export function addGA4Properties(properties) {
|
||||
const gaMeasurementId = getCookie('ga_measurement_id')?.replace('G-', '');
|
||||
properties.ga_session_id = getCookie('_ga_' + gaMeasurementId)?.replace('GS1.1.','').split('.')[0];
|
||||
properties.ga_client_id = getCookie('_ga')?.replace('GA1.1.','');
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getCookie, devLog, tagCloudUILinksWithAnonymousId } from './helpers';
|
||||
import { addGA4Properties, getCookie, devLog, tagCloudUILinksWithAnonymousId } from './helpers';
|
||||
|
||||
const WRITE_KEY = 'segmentWriteKey';
|
||||
const PAGES_SESSION_STORAGE_KEY = 'segmentPages';
|
||||
@@ -125,6 +125,8 @@ const trackStoredPageViews = () => {
|
||||
const originalTimestamp = properties.storedEvent ? properties.storedTimestamp : null;
|
||||
delete properties['storedTimestamp'];
|
||||
|
||||
addGA4Properties(properties);
|
||||
|
||||
if(window.analytics) {
|
||||
window.analytics.page(
|
||||
category,
|
||||
@@ -151,6 +153,8 @@ const trackEvent = (name, properties = {}) => {
|
||||
const originalTimestamp = properties.storedEvent ? properties.storedTimestamp : null;
|
||||
delete properties['storedTimestamp'];
|
||||
|
||||
addGA4Properties(properties);
|
||||
|
||||
if(window.analytics) {
|
||||
window.analytics.track({
|
||||
event: name,
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import * as params from '@params';
|
||||
import { setCookie } from './helpers';
|
||||
import { setSegmentWriteKey } from './segment-helpers';
|
||||
|
||||
if (params.segmentWriteKey) {
|
||||
setSegmentWriteKey(params.segmentWriteKey);
|
||||
}
|
||||
|
||||
if (params.gaMeasurementId) {
|
||||
setCookie('ga_measurement_id', params.gaMeasurementId, 365);
|
||||
}
|
||||
Reference in New Issue
Block a user