NikolayBezay

Soda static add to cart template

Nov 23rd, 2021 (edited)
979
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.   var GA_EVENT_CATEGORY = 'Adoric';
  3.   var GA_EVENT_ACTION = 'click - ADDTOCART';
  4.   var GA_EVENT_LABEL = 'DUO Upgrade Angebot';
  5.   var PDRODUCT_ID = '39575250960463';
  6.  
  7.   function adoricAddToCart(productId) {
  8.     var data = {
  9.       "id": productId,
  10.       "quantity": 1
  11.     };
  12.     var xhr = new XMLHttpRequest();
  13.     xhr.withCredentials = true;
  14.     xhr.addEventListener('readystatechange', function() {
  15.       if (this.readyState === 4) {
  16.         console.log(this.responseText);
  17.         window.ga && window.ga("t0.send", "event", {
  18.           eventCategory: GA_EVENT_CATEGORY,
  19.           eventAction: GA_EVENT_ACTION,
  20.           eventLabel: GA_EVENT_LABEL
  21.         });
  22.         window.location.href = window.location.origin + '/cart';
  23.       }
  24.     });
  25.     xhr.open('POST', window.location.origin + '/cart/add.js');
  26.     xhr.setRequestHeader('content-type', 'application/json');
  27.     xhr.setRequestHeader('cache-control', 'no-cache');
  28.     xhr.send(JSON.stringify(data));
  29.   }
  30.   adoricAddToCart(PDRODUCT_ID);
  31. })();
  32.  
Add Comment
Please, Sign In to add comment