Recently, I discovered that the conversion tracking in Google Analytics for a website we developed and maintain has been inaccurate by 20% - 40% daily.
After testing in various browsers except Firefox, conversions are reflected in Analytics immediately without any issues.
However, when using Firefox with Enhanced Privacy Protection enabled (default setting), an error occurs:
Cross-Origin Request Blocked: The Same Origin Policy restricts access to the remote resource at . (Reason: CORS request did not succeed).
Disabling Enhanced Privacy Protection resolves the issue.
The code snippet used to push to datalayer is:
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
window.dataLayer.push({
"event" : "cf7submission",
"eventAction": "FormSubmission",
"eventCategory": "Contact Form Submission",
"eventCallback" : function() {
// Callback to redirect page is never executed in Firefox.
window.location.href = "https://www.domain.co.uk/thank-you/";
return false;
},
"eventTimeout" : 2000
});
}, false );
</script>
The listener checks for email submission on the site, pushes data to Data Layer for tracking, and redirects to a thank you page upon completion.
This does not seem like a CORS
related issue as other browsers execute the code flawlessly.
Firefox's explanation of the error can be found here.
TLDR: Firefox is blocking datalayer push due to Enhanced Privacy being toggled on, contradicting standard conversion tracking scripts. How do I bypass this block?
UPDATE
A reference from Mozilla https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Privacy/Tracking_Protection states:
How does Firefox choose what to block?
Content is blocked based on the domain it originates from.
When tracking protection is active, sites engaged in cross-site tracking are blocked.
Sites mostly affected are third-party advertising and analytics sites.
Is Firefox indeed obstructing Google Analytics for standard conversion tracking now?