Hi Stan,
I believe that this code in your theme.liquid is a culprit:
When split into lines it looks like:
const observer = new MutationObserver((e) => {
e.forEach(({ addedNodes: e }) => {
e.forEach((e) => {
1 === e.nodeType &&
"SCRIPT" === e.tagName &&
(e.innerHTML.includes("asyncLoad") &&
(e.innerHTML = e.innerHTML
.replace(
"if(window.attachEvent)",
"document.addEventListener('asyncLazyLoad',function(event){asyncLoad();});if(window.attachEvent)"
)
.replaceAll(", asyncLoad", ", function(){}")),
e.innerHTML.includes("PreviewBarInjector") &&
(e.innerHTML = e.innerHTML.replace(
"DOMContentLoaded",
"asyncLazyLoad"
)),
e.className == "analytics" && (e.type = "text/lazyload"),
(e.src.includes("assets/storefront/features") ||
e.src.includes("assets/shopify_pay") ||
e.src.includes("connect.facebook.net")) &&
(e.setAttribute("data-src", e.src), e.removeAttribute("src")));
});
});
});
observer.observe(document.documentElement, { childList: !0, subtree: !0 });
The code basically runs on every element added to the page and modifies it to delay loading of some components.
The offensive part is this line:
e.className == "analytics" && (e.type = "text/lazyload"),
which makes browser to ignore all elements by changing their type to a wrong value.
There is code in assets/speedimize.js which restores some of those elements to their original format and type to make browser run them at a later time, but it does not process all of them.
Shopify tracking is initialized by the JS code which starts like this and output as part of {{ content_for_header }}
And it's affected by the code I mentioned above and therefore never runs.
Not sure from the top of my head what would be the best way to fix it, but you may start by replacing the offensive line with:
```markup
e.className == "analytics" && e.src != '' && (e.type = "text/lazyload"),
and check if this will restore Shopify analytics etc.
Or simply comment out entire first snippet of JS to see if it will help.
Of course, your PageSpeed will suffer.
One thing about your PageSpeed bothers me though, where it says “Discover what your real users are experiencing – No data” which I believe there must be since your are running your shop for more than a year.
Do you see Web Vitals reports in your search console?
Because it’s exactly this data which matters and why we’re doing speed optimization…