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
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 59s
This commit is contained in:
@@ -140,10 +140,9 @@
|
|||||||
<div class="location-input-group">
|
<div class="location-input-group">
|
||||||
<input type="text" id="postcode-search" class="search-input postcode-input" placeholder="Enter postcode...">
|
<input type="text" id="postcode-search" class="search-input postcode-input" placeholder="Enter postcode...">
|
||||||
<select id="radius-select" class="filter-select radius-select">
|
<select id="radius-select" class="filter-select radius-select">
|
||||||
<option value="0.5">1/2 mile</option>
|
<option value="0.5" selected>1/2 mile</option>
|
||||||
<option value="1" selected>1 mile</option>
|
<option value="1">1 mile</option>
|
||||||
<option value="2">2 miles</option>
|
<option value="2">2 miles</option>
|
||||||
<option value="5">5 miles</option>
|
|
||||||
</select>
|
</select>
|
||||||
<button id="location-search-btn" class="btn btn-primary location-btn">Find Nearby</button>
|
<button id="location-search-btn" class="btn btn-primary location-btn">Find Nearby</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -358,32 +357,39 @@
|
|||||||
<!-- Google Analytics (loaded conditionally after consent) -->
|
<!-- Google Analytics (loaded conditionally after consent) -->
|
||||||
<script>
|
<script>
|
||||||
var GA_MEASUREMENT_ID = null;
|
var GA_MEASUREMENT_ID = null;
|
||||||
|
var analyticsConsentGiven = false;
|
||||||
// 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); });
|
|
||||||
|
|
||||||
function loadGoogleAnalytics() {
|
function loadGoogleAnalytics() {
|
||||||
if (window.gaLoaded || !GA_MEASUREMENT_ID) return;
|
if (window.gaLoaded || !GA_MEASUREMENT_ID) return;
|
||||||
window.gaLoaded = true;
|
window.gaLoaded = true;
|
||||||
|
|
||||||
|
// Load gtag.js script
|
||||||
var script = document.createElement('script');
|
var script = document.createElement('script');
|
||||||
script.async = true;
|
script.async = true;
|
||||||
script.src = 'https://www.googletagmanager.com/gtag/js?id=' + GA_MEASUREMENT_ID;
|
script.src = 'https://www.googletagmanager.com/gtag/js?id=' + GA_MEASUREMENT_ID;
|
||||||
document.head.appendChild(script);
|
document.head.appendChild(script);
|
||||||
|
|
||||||
|
// Initialize dataLayer and gtag function
|
||||||
window.dataLayer = window.dataLayer || [];
|
window.dataLayer = window.dataLayer || [];
|
||||||
function gtag(){dataLayer.push(arguments);}
|
function gtag(){dataLayer.push(arguments);}
|
||||||
window.gtag = gtag;
|
window.gtag = gtag;
|
||||||
gtag('js', new Date());
|
gtag('js', new Date());
|
||||||
gtag('config', GA_MEASUREMENT_ID);
|
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>
|
</script>
|
||||||
|
|
||||||
<!-- Cookie Consent Banner -->
|
<!-- Cookie Consent Banner -->
|
||||||
@@ -415,6 +421,14 @@
|
|||||||
},
|
},
|
||||||
onConsentChange: function(consent) {
|
onConsentChange: function(consent) {
|
||||||
if (consent.analytics) {
|
if (consent.analytics) {
|
||||||
|
analyticsConsentGiven = true;
|
||||||
|
loadGoogleAnalytics();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onReady: function(consent) {
|
||||||
|
// Called on page load with existing consent state
|
||||||
|
if (consent && consent.analytics) {
|
||||||
|
analyticsConsentGiven = true;
|
||||||
loadGoogleAnalytics();
|
loadGoogleAnalytics();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user