-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Magento interferes with the function queue declaration in Google Analytics #13267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
People who are similarly irate: I am going to get around this by simply stubbing the function queue directly after the snippet. This will catch these cases. Admins, would you accept a PR to do the function queue before the analytics code, and be displayed regardless if it's enabled? It would not resolve the aforementioned add blocker issues (I think we need to take it out of require for that), but it would at least re-establish the function queue. Wiser people than me: Don't couple your analytics to GA it's more fragile than you'd guess. API usage limits cause critical failures (for example) |
Stubbing the function queue prevents fatal errors, but events lodged before analytics declares it's first So, best solution to this:
In the case GA is disabled, the function queue will still be declared, but will harmlessly accrue events. |
HI @andrewhowdencom , thank you for your report. |
Hi @engcom-backlog-nazar To reproduce this issue would require extensive effort. The above describes the technical nature of the problem; to reproduce it it should be a case of inserting
to the page HTML somewhere immediately after the |
@andrewhowdencom I'm no able to reproduce following steps you described. Have no error you are described in actual result. |
Hola @engcom-backlog-nazar Do you have a test environment (with admin rights)? I can probably just drop it in some sort of custom HTML field, and repro it there. |
@andrewhowdencom Which version you tested ? 2.2-develop ? |
Nah, this would have been against a project directly, and it was before the GA changes that suppressed errors. It should still be reproduce against |
@andrewhowdencom Ok i will try again. |
All good. If you cant repro it close it, as we can just reopen it again in future if someone else finds it. I myself no longer work on Magento 2! |
@andrewhowdencom I'm closing this issue due to inactivity. If you'd like to update it, please reopen the issue. |
Google Analytics implements the function queue pattern. I explain this pattern in some depth here:
#8837 (comment)
However, the TLDR is that Google Analyics declares a global variable on the window object very early in the page load:
Paraphrased as:
It immediately stores events in this queue, of the form:
However, and critically, it does not execute this queue. It simply stores the view, and appends the JavaScript to the
<head>
block.<script async src='//www.google-analytics.com/analytics.js'></script>
The async attribute defers the execution of the analytics block until the browser decides it's appropriate to pull these resources down, but it does not block browser parsing the document fetching other resources (unless the browser is old and crap and you probably should block anyway.
The absence of the function queue means that
ga
events must all be wrapped in the bosomy cushion of require, which creates a nasty dependency tree that does not need to exist.Putting back the function queue will resolve any issues with adblockers (#12428). It does not need to be wrapped in require; it's more efficient simply left to its own devices.
Preconditions
Steps to reproduce
Expected result
ga
should work in all cases, regardless of the loading state of the site.Actual result
I apologise for the snark in this comment. I stubbed the
ga
function queue when GA was disabled, so I did not find this until late in the development lifecycle and I have ... strong feelings.The text was updated successfully, but these errors were encountered: