Over the past few weeks I've realised that the conversion tracking in Google Analytics of a website we built and maintain has been off by about 20% - 40% each day.
When testing in any browser but Firefox, everything works fine and you can see conversions pushing into Analytics straight away.
However, in Firefox, when you have Enhanced Privacy Protection turned ON, (it comes switched on as default now) you get the following error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.googleadservices.com/pagead/conversion/957837126/wcm?cc=ZZ&dn=01858439338&cl=ITVOCP2S_34Qxt7dyAM&ct_eid=2. (Reason: CORS request did not succeed).
As soon as you switch off Enhanced Privacy Protection it works perfectly.
The code I am using to push to datalayer, if its of any relevance is:
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
window.dataLayer.push({
"event" : "cf7submission",
"eventAction": "FormSubmission",
"eventCategory": "Contact Form Submission",
"eventCallback" : function() {
// Firefox never gets to run this callback to redirect page - which is what triggered further investigation.
window.location.href = "https://www.domain.co.uk/thank-you/";
return false;
},
"eventTimeout" : 2000 // I had to add this in so that it still redirects to thank you when datalayer push fails.
});
}, false );
</script>
The event listener is just to check when the email has been sent by the site, and then the rest is to push into Data Layer for tracking and then redirect to thank you page upon completion.
In my opinion this is definitely not a CORS
related error in the sense that the request is coming from our local script with the correct headers. Code works in all other browsers with no issue.
Firefox has this page https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSDidNotSucceed to try to explain why we're getting the error:
Reason 1:
Its Certificate error : Its Google, it's not a cert error
Reason 2:
HTTP to HTTPS request : HTTPS on site with Let's Encrypt SSL
Reason 3:
Not permitted to access localhost : This isn't localhost and is live site
Reason 4:
Server didn't respond : Again, it's Google, it responds to everything.
TLDR: Firefox is blocking datalayer push when Enhanced Privacy is turned on, but should be allowing a standard conversion tracking script to run in line with their own docs. Why is it blocking us and what code do I need to get around it?
UPDATE
I've found this link https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Privacy/Tracking_Protection which says:
How does Firefox choose what to block?
Content is blocked based on the domain from which it is to be loaded.
Firefox ships with a list of sites which have been identified as engaging in cross-site tracking of users. When tracking protection is enabled, Firefox blocks content from sites in the list.
Sites that track users are most commonly third-party advertising and analytics sites.
Is Firefox seriously blocking Google Analytics on standard conversion tracking now?