Advertisement
orenchuck

GTM vertical carousel all domains

May 25th, 2022 (edited)
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.46 KB | None | 0 0
  1. <script>
  2.     (function() {
  3.         try {
  4.             function getData(sourceUrl, lsKey) {
  5.                 var xhr = new XMLHttpRequest();
  6.                 xhr.withCredentials = true;
  7.                 xhr.addEventListener("readystatechange", function() {
  8.                     if (this.readyState === 4) {
  9.                         var json = JSON.parse(this.responseText);
  10.                         if (json && json.products && json.products.length > 0) {
  11.                            window.localStorage.setItem(lsKey, JSON.stringify(json));
  12.                         }
  13.                     }
  14.                 });
  15.                 xhr.open("GET", sourceUrl);
  16.                 xhr.send();
  17.             }
  18.  
  19.             var domain = location.hostname;
  20.             var dataSourceUrl = '';
  21.             var lsKey = '';
  22.             switch (domain) {
  23.                 case 'sodastream.com':
  24.                     dataSourceUrl = 'https://feeds.datafeedwatch.com/61736/81fd097f63e9bf0edef631a72f6ca2f3a2872709.json';
  25.                     lsKey = 'upsell_Vertical_Carousel';
  26.                     getData(dataSourceUrl, lsKey);
  27.                     break;
  28.                 case 'sodastream.ca':
  29.                     dataSourceUrl = 'https://feeds.datafeedwatch.com/64282/0d1f540754be235a47254aa8a146099f77e67a21.json';
  30.                     lsKey = 'upsell_Vertical_Carousel';
  31.                     getData(dataSourceUrl, lsKey);
  32.                     break;
  33.                 case 'sodastream.fr':
  34.                     dataSourceUrl = 'https://feeds.datafeedwatch.com/66229/9e5f8b240f61a3155d6bbc3494ee9e7139135578.json';
  35.                     lsKey = 'upsell_Vertical_Carousel';
  36.                     getData(dataSourceUrl, lsKey);
  37.                     break;
  38.                 case 'sodastream.se':
  39.                     dataSourceUrl = 'https://feeds.datafeedwatch.com/64397/ef779f79ebf13838f3e7f3f2ac33c9e4cf4589c8.json';
  40.                     lsKey = 'upsell_Vertical_Carousel';
  41.                     getData(dataSourceUrl, lsKey);
  42.                     break;
  43.                 case 'sodastream.de':
  44.                     dataSourceUrl = 'https://feeds.datafeedwatch.com/64183/52bb0f7cc9cb9bbc6e9589624d3e5fb5c5465ed7.json';
  45.                     lsKey = 'upsell_Vertical_Carousel';
  46.                     getData(dataSourceUrl, lsKey);
  47.                     break;
  48.                     default:
  49.                     return;
  50.                 }
  51.  
  52.            
  53.         } catch(requestError) {console.log(requestError)}
  54.     })();
  55. </script>
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement