Advertisement
NikolayBezay

Femina event for Adoric recommendation campaigns GTM teg for all pages.

Jan 4th, 2023 (edited)
1,103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.15 KB | None | 0 0
  1. <script>
  2.     (function() {
  3.         var MAXIMUM_WAITING_TIME = 15 * 1000;
  4.         var ITERATION_TIME_STEP = 500;
  5.  
  6.         function sendAdoricProductEvent(productSKU) {
  7.             adoric.trigger('pageview', {
  8.                 type: 'product',
  9.                 ids: productSKU
  10.             });
  11.         }
  12.  
  13.         var waitPageTriggerElement = setInterval(function() {
  14.             var skuElement = document.querySelector('.value[itemprop="sku"]');
  15.             if (skuElement && window.adoric) {
  16.                clearInterval(waitPageTriggerElement);
  17.                 sendAdoricProductEvent(skuElement.textContent);
  18.             }
  19.         }, ITERATION_TIME_STEP);
  20.         setTimeout(function() {
  21.             clearInterval(waitPageTriggerElement);
  22.         }, MAXIMUM_WAITING_TIME);
  23.  
  24.         if (window.location.href.indexOf('/cart') !== -1 && window.checkoutConfig && window.checkoutConfig.quoteItemData) {
  25.            window.checkoutConfig.quoteItemData.forEach(function(item) {
  26.                if (item.product && item.product.sku) {
  27.                    sendAdoricProductEvent(item.product.sku);
  28.                 }
  29.             });
  30.         }
  31.     })();
  32. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement