Advertisement
orenchuck

gtm aldo add 20% tag

Apr 25th, 2023
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. <script>
  2. (function () {
  3. var WAITING_TIMER_COUNTER = 10;
  4. var PART_OF_SECOND = 200;
  5. var feedURL = 'https://feeds.datafeedwatch.com/60212/31faa3c0131b91b3ab1a11e1083763b0174863aa.json';
  6.  
  7. function showTagsCampaign(productSku) {
  8. if (productSku) {
  9. productSku = productSku.textContent;
  10. }
  11. fetch(feedURL)
  12. .then(function (res) {
  13. return res.json();
  14. }).then(function (res) {
  15. if (res && res.products) {
  16. res.products.forEach(function (item) {
  17. if (item.id === productSku) {
  18. adoric && adoric.trigger('show20%tag');
  19. }
  20. });
  21. }
  22. }).catch(function (error) {
  23. console.info(error);
  24. });
  25. }
  26.  
  27. function waitPageSelector() {
  28. WAITING_TIMER_COUNTER--;
  29. var nativePageSelector = document.querySelector('[class*="productFullDetail-productSku"]');
  30.  
  31. if (!nativePageSelector && WAITING_TIMER_COUNTER > 0 || !window.adoric) {
  32. setTimeout(waitPageSelector, PART_OF_SECOND);
  33. } else if (window.adoric) {
  34. showTagsCampaign(nativePageSelector);
  35. }
  36. }
  37.  
  38. waitPageSelector();
  39. })();
  40. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement