0

When I navigate to the product detail page I get a console error

"Uncaught ReferenceError: jQuery is not defined"

only on these pages. I've tried adding the dependency trough the head.tpl file and the javascript.tpl file but no success so far.

Example URL : https://naturata.pt/en/mesh/27-379-teste.html#/6-color-brown/43-size-34

Habib
  • 563
  • 8
  • 25
  • 2
    Is this a project that's already online? If so, please paste the page where the error happens. Also, can you please paste the example on how you're loading the jquery on said page? – marcogmonteiro Jul 20 '20 at 10:11
  • 2
    How is this related to PHP? What have you tried to debug the problem? – Nico Haase Jul 20 '20 at 10:11
  • @NicoHaase Already removed the php tag, waiting on it being approved. :) – marcogmonteiro Jul 20 '20 at 10:14
  • It seems that the problem is on the detail template that adds an inline script for google analytics about the product. When that is being declared jquery is not loaded yet. You can either add jquery to your header, or remove that script from there and add it to your footer. – marcogmonteiro Jul 20 '20 at 10:17
  • From what I see that google analytics is not even working. Might as well remove it all together. – marcogmonteiro Jul 20 '20 at 10:18

1 Answers1

0

If you closely inspect your error, you can see that is happening on line 1562.

You're trying to use the jquery object there to send data to your google analytics. However that is not even being used. You might as well just remove this from your product detail template.

<script type="text/javascript">
    jQuery(document).ready(function(){
    var MBG = GoogleAnalyticEnhancedECommerce;
    MBG.setCurrency('EUR');
    MBG.addProductDetailView({
        "id":0,
        "name":"null",
        "category":"null",
        "brand":"",
        "variant":"null",
        "type":"typical",
        "position":"0",
        "quantity":1,
        "list":"product",
        "url":"",
        "price":"0.00"
   });
});
</script>

If you really want this to work, you might want to transfer your jquery to your header so that way its going to be loaded before this script runs.

Another thing you might do is disable the analytics module. Since it's not being used and this is what is causing the problem.

Or look into the function in that model that is rendering that code to try and solve that. You can just change that from using Jquery document ready to native document ready with js.

So in your case change that to:

document.addEventListener("DOMContentLoaded", function(event) { 
  var MBG = GoogleAnalyticEnhancedECommerce;
    MBG.setCurrency('EUR');
    MBG.addProductDetailView({
        "id":0,
        "name":"null",
        "category":"null",
        "brand":"",
        "variant":"null",
        "type":"typical",
        "position":"0",
        "quantity":1,
        "list":"product",
        "url":"",
        "price":"0.00"
   });
});

You can read more about it here: $(document).ready equivalent without jQuery

marcogmonteiro
  • 1,617
  • 1
  • 13
  • 20