Advertisement
NikolayBezay

Keds.co.il Related product GTM teg(UPDATED).

Dec 6th, 2022
74
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. function getCurrentPageProducts() {
  4. let resultID = null;
  5. if (dataLayer) {
  6. dataLayer.forEach(item => {
  7. for (let j in item) {
  8. if (item[j].items && item[j].items[0] && item[j].items[0].id) {
  9. resultID = item[j].items[0].id;
  10. }
  11. }
  12. })
  13. }
  14. return resultID;
  15. }
  16. async function getRelatedProductData() {
  17. const RELATED_PRODUCT_ENDPOINT = 'https://us-east4-adoric-production.cloudfunctions.net/Support_relatedProducts';
  18. const CLIENT_KEY = 'keds';
  19. try {
  20. const productsInPage = getCurrentPageProducts();
  21. if (productsInPage) {
  22. const response = await fetch(RELATED_PRODUCT_ENDPOINT + '?clientKey=' + CLIENT_KEY + '&productList=' + productsInPage);
  23. const result = await response.json();
  24. window.adoricRelatedProductData = await result;
  25. if (window.adoricRelatedProductData && window.adoricRelatedProductData.length > 0) {
  26. window.adoric && window.adoric.trigger('relatedProductFromThePAGE');
  27. }
  28. }
  29. } catch (error) {
  30. console.log(error.message);
  31. }
  32. }
  33. getRelatedProductData();
  34. })();
  35. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement