Shopify analytics and mail conversions do not work since last year

Shopify analytics and mail conversions do not work since last year

stanlegebeke
Excursionist
26 0 2

Hello, 

My shopify analytics do not work since optimizing my theme last year february 2023. 

I did not make the right back-up and since then shopify tracking does not work. Also my email conversions are not measured since then. 

Does anybody know how I, can get them up and running again? 

I would almost rebuild my entire store
My store is www.uwdiervoeding.nl
Kind regards
Stan Legebeke

UwDiervoeding.nl | Founder
Reply 1 (1)

tim
Shopify Expert
3627 314 1341

 

Hi Stan, 

 

I believe that this code in your theme.liquid is a culprit:

 

<script type="text/javascript">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})</script>

 

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 <script> 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 <script> 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 }}

 

<script class="analytics">(window.gaDevIds=window.gaDevIds||[]).push('BwiEti');

 

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:

 

       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...

 

 

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com