fixing GA implementation race condition for account id retrieval
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 59s

This commit is contained in:
Tudor
2026-01-12 09:10:36 +00:00
parent 9cd36a0b15
commit a18ec04227

View File

@@ -140,10 +140,9 @@
<div class="location-input-group">
<input type="text" id="postcode-search" class="search-input postcode-input" placeholder="Enter postcode...">
<select id="radius-select" class="filter-select radius-select">
<option value="0.5">1/2 mile</option>
<option value="1" selected>1 mile</option>
<option value="0.5" selected>1/2 mile</option>
<option value="1">1 mile</option>
<option value="2">2 miles</option>
<option value="5">5 miles</option>
</select>
<button id="location-search-btn" class="btn btn-primary location-btn">Find Nearby</button>
</div>
@@ -358,32 +357,39 @@
<!-- Google Analytics (loaded conditionally after consent) -->
<script>
var GA_MEASUREMENT_ID = null;
// Fetch GA ID from server config
fetch('/api/config')
.then(function(response) { return response.json(); })
.then(function(config) {
if (config.ga_measurement_id) {
GA_MEASUREMENT_ID = config.ga_measurement_id;
}
})
.catch(function(err) { console.warn('Failed to load config:', err); });
var analyticsConsentGiven = false;
function loadGoogleAnalytics() {
if (window.gaLoaded || !GA_MEASUREMENT_ID) return;
window.gaLoaded = true;
// Load gtag.js script
var script = document.createElement('script');
script.async = true;
script.src = 'https://www.googletagmanager.com/gtag/js?id=' + GA_MEASUREMENT_ID;
document.head.appendChild(script);
// Initialize dataLayer and gtag function
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
window.gtag = gtag;
gtag('js', new Date());
gtag('config', GA_MEASUREMENT_ID);
}
// Fetch GA ID from server config, then load GA if consent already given
fetch('/api/config')
.then(function(response) { return response.json(); })
.then(function(config) {
if (config.ga_measurement_id) {
GA_MEASUREMENT_ID = config.ga_measurement_id;
// If consent was already given before config loaded, load GA now
if (analyticsConsentGiven) {
loadGoogleAnalytics();
}
}
})
.catch(function(err) { console.warn('Failed to load config:', err); });
</script>
<!-- Cookie Consent Banner -->
@@ -415,6 +421,14 @@
},
onConsentChange: function(consent) {
if (consent.analytics) {
analyticsConsentGiven = true;
loadGoogleAnalytics();
}
},
onReady: function(consent) {
// Called on page load with existing consent state
if (consent && consent.analytics) {
analyticsConsentGiven = true;
loadGoogleAnalytics();
}
}