NikolayBezay

Gadecosmetics.com "Free delivery" event to Adoric for GTM.

Feb 19th, 2021
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.33 KB | None | 0 0
  1. <script>
  2. (function() {
  3.     var minPrice = 60;
  4.     var maxPrice = 99;
  5.     function checkTotalCart() {
  6.         var parser = new DOMParser();
  7.         var doc =  '';
  8.         var data = null;
  9.         var xhr = new XMLHttpRequest();
  10.         xhr.withCredentials = true;
  11.         xhr.addEventListener('readystatechange', function () {
  12.             if (this.readyState === 4) {
  13.  
  14.                 doc = parser.parseFromString(this.responseText, 'text/html');      
  15.                 var cartData = JSON.parse(doc.querySelector('body').innerText, 2);
  16.                 var totalPrice = cartData.total_price;
  17.                 totalPrice = parseInt(totalPrice / 100);
  18.                 if ((totalPrice >= minPrice) && (totalPrice <= maxPrice)) {
  19.                    window.adoric && adoric.trigger('FreeDelivery');
  20.                 }
  21.             }
  22.         });
  23.         xhr.open('GET', 'https://www.gadecosmetics.com/cart.js');
  24.         xhr.setRequestHeader('cache-control', 'no-cache');
  25.         xhr.send(data);
  26.     }
  27.  
  28.     var listProductForms = document.querySelectorAll('.shopify-product-form');
  29.     if (listProductForms.length > 0) {
  30.         for(var i = 0; i < listProductForms.length; i++) {
  31.             listProductForms[i].addEventListener('submit', function(){
  32.                 setTimeout(checkTotalCart, 2000);
  33.            });
  34.        }
  35.    }
  36. })();
  37. </script>
Advertisement
Add Comment
Please, Sign In to add comment