Skip to content

Commit df87308

Browse files
author
Benjamin Davison
committed
Modified event recording
1 parent 4ca502c commit df87308

2 files changed

Lines changed: 41 additions & 21 deletions

File tree

client/src/components/CookieBanner.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@ const loadGoogleAnalytics = () => {
3030
script.async = true;
3131
document.head.appendChild(script);
3232
33+
// We must attach dataLayer and gtag to 'window' explicitly
34+
// so that MapView.vue can access them.
3335
window.dataLayer = window.dataLayer || [];
34-
function gtag(){dataLayer.push(arguments);}
35-
gtag('js', new Date());
36-
gtag('config', GA_MEASUREMENT_ID);
36+
37+
window.gtag = function(){
38+
window.dataLayer.push(arguments);
39+
};
40+
41+
window.gtag('js', new Date());
42+
window.gtag('config', GA_MEASUREMENT_ID);
3743
3844
console.log("?? Google Analytics Loaded via Custom Component");
3945
};

client/src/views/MapView.vue

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ import axios from 'axios';
412412
import Plotly from 'plotly.js-dist-min';
413413
import JSZip from 'jszip';
414414
import { saveAs } from 'file-saver';
415-
import { event } from "vue-gtag";
416415
417416
// --- API CONFIGURATION ---
418417
// 1. Get the URL (Localhost in dev, Ngrok in prod)
@@ -428,6 +427,16 @@ const apiClient = axios.create({
428427
}
429428
});
430429
430+
// --- NATIVE GOOGLE ANALYTICS TRACKING ---
431+
const trackEvent = (eventName, params = {}) => {
432+
if (typeof window.gtag === 'function') {
433+
window.gtag('event', eventName, params);
434+
console.log(`?? GA Event Sent: ${eventName}`, params);
435+
} else {
436+
console.log(`?? GA Event Skipped (Not loaded): ${eventName}`);
437+
}
438+
};
439+
431440
// --- CONSTANTS ---
432441
// Colors for selected points (cycles through this list)
433442
const COLORS = [
@@ -654,11 +663,13 @@ const onMapClick = async (e) => {
654663
if (selectedPoints.value.length >= 10) return;
655664
656665
// Track clicks
657-
event("map_click", {
658-
event_category: "interaction",
659-
event_label: "extract_timeseries",
660-
region: currentRegion.value // Tracks 'Greenland' or 'Antarctica'
661-
});
666+
trackEvent("map_click", {
667+
event_category: "interaction",
668+
event_label: "extract_timeseries",
669+
region: currentRegion.value,
670+
lat: e.latlng.lat.toFixed(4),
671+
lon: e.latlng.lng.toFixed(4)
672+
});
662673
663674
const newId = Date.now();
664675
const color = COLORS[selectedPoints.value.length % COLORS.length];
@@ -863,12 +874,13 @@ const downloadChartImage = async () => {
863874
}
864875
865876
// Track png downloads
866-
event("download", {
867-
event_category: "export",
868-
event_label: "png_chart",
869-
plot_type: currentPlotVar.value
870-
});
871-
877+
trackEvent("file_download", {
878+
event_category: "export",
879+
event_label: "png_chart",
880+
file_extension: "png",
881+
file_name: `velocity_plots_${currentRegion.value}`,
882+
plot_type: currentPlotVar.value
883+
});
872884
873885
statusMessage.value = "Generating image(s)...";
874886
@@ -931,12 +943,14 @@ const handleDownload = async () => {
931943
if (selectedPoints.value.length === 0) return;
932944
933945
// Track csv downloads
934-
event("download", {
935-
event_category: "export",
936-
event_label: "csv_data",
937-
region: currentRegion.value,
938-
count: selectedPoints.value.length
939-
});
946+
trackEvent("file_download", {
947+
event_category: "export",
948+
event_label: "csv_data",
949+
file_extension: "zip", // or csv
950+
file_name: "velocity_data_batch",
951+
region: currentRegion.value,
952+
count: selectedPoints.value.length
953+
});
940954
941955
// Single File: Direct CSV download
942956
if (selectedPoints.value.length === 1) {

0 commit comments

Comments
 (0)