Advertisement
orenchuck

send event to adoric from recommendations

May 27th, 2022
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. <script>
  2. (function () {
  3. var pageProductFormTimer = 10;
  4.  
  5. function sendProductId() {
  6. var itemId = productForm = document.querySelector("#product_addtocart_form");
  7. var select = document.querySelector('.control>select');
  8. var options = {once: true};
  9.  
  10. if (!itemId) return;
  11. itemId = itemId.getAttribute('data-product-sku');
  12.  
  13. if (parseInt(itemId) && adoric)
  14. adoric.trigger("pageview", {
  15. type: "product",
  16. ids: itemId,
  17. })/*else current product has dropdown select we check listener answer */
  18. else if (itemId && select && adoric) {
  19. select.addEventListener('change', function() {
  20. setTimeout(function() {
  21. var skuSpan = document.querySelector('.simple-sku>span');
  22. if (!skuSpan)return;/*maybe same problem page*/
  23. itemId = skuSpan.textContent.split(' ')[1];
  24. adoric.trigger("pageview", {
  25. type: "product",
  26. ids: itemId,
  27. })
  28. }, 300)
  29. }, options
  30. );
  31. }
  32. }
  33.  
  34. function waitPageProduct() {
  35. pageProductFormTimer--;
  36. var productForm = document.querySelector("#product_addtocart_form");
  37. if (!productForm && pageProductFormTimer > 0) {
  38. setTimeout(waitPageProduct, 1000);
  39. } else if (pageProductFormTimer > 0) {
  40. sendProductId();
  41. }
  42. }
  43. waitPageProduct();
  44. }
  45. )();
  46. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement