Advertisement
NikolayBezay

Quick QA env. custom GTM tag to show campaign by cart limit and click over payment button.

Feb 7th, 2023 (edited)
1,016
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.25 KB | None | 0 0
  1. <script>
  2. (function() {
  3.     var MIN_TOTAL_CART_SUM_LIMIT = 400;
  4.     var MAX_TOTAL_CART_SUM_LIMIT = 498;
  5.     var SHOW_CAMPAIGN_EVENT_NAME = 'showCartLimitCampaign';
  6.  
  7.     function checkCheckoutState() {
  8.         return window.location.href.indexOf('section=checkout') !== -1;
  9.     }
  10.    
  11.     function checkPaymentCampaign() {
  12.         var cartWrapper = document.querySelector('[class*="cartWrapper"]');
  13.         if (!cartWrapper || !adoric || !adoric.trigger) {
  14.             return null;
  15.         }
  16.         cartWrapper.addEventListener('click', function(event) {
  17.             var paymentButton = event.target.closest('[class*="paymentButton"]');
  18.             setTimeout(function() {
  19.                 if (checkCheckoutState() && paymentButton && window.adoricVars.cartInfo.sum > MIN_TOTAL_CART_SUM_LIMIT && window.adoricVars.cartInfo.sum <= MAX_TOTAL_CART_SUM_LIMIT && paymentButton && adoricVars.userInfo.deliveryPlanName == 'חבילת בסיס') {
  20.                    adoric.trigger(SHOW_CAMPAIGN_EVENT_NAME);
  21.                 }
  22.             }, 1000);
  23.         });
  24.     }
  25.  
  26.     if (document.readyState === 'loading') {
  27.         document.addEventListener('DOMContentLoaded', checkPaymentCampaign);
  28.     } else {
  29.         checkPaymentCampaign();
  30.     }
  31. })();
  32. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement