Advertisement
NikolayBezay

Soda GTM for custom carousels optimisation(IL domain added)

Jul 20th, 2022
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.80 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.         var domain = location.hostname;
  19.         var dataSourceUrl = '';
  20.         var lsKey = '';
  21.         switch (domain) {
  22.             case 'sodastream.com':
  23.                 dataSourceUrl = 'https://feeds.datafeedwatch.com/61736/81fd097f63e9bf0edef631a72f6ca2f3a2872709.json';
  24.                 lsKey = 'upsell_Vertical_Carousel';
  25.                 getData(dataSourceUrl, lsKey);
  26.                 break;
  27.             case 'sodastream.ca':
  28.                 lsKey = 'upsell_Vertical_Carousel';
  29.                 var loc = window.location.href;
  30.                 if (loc.includes('sodastream.ca/fr')) {
  31.                     dataSourceUrl = 'https://feeds.datafeedwatch.com/64282/53ca1d9812b7ed5bff779eb0ab1d8f281f4ebabc.json';
  32.                 } else {
  33.                     dataSourceUrl = 'https://feeds.datafeedwatch.com/64282/0d1f540754be235a47254aa8a146099f77e67a21.json';
  34.                 }
  35.                 getData(dataSourceUrl, lsKey);
  36.                 break;
  37.             case 'sodastream.fr':
  38.                 dataSourceUrl = 'https://feeds.datafeedwatch.com/66229/9e5f8b240f61a3155d6bbc3494ee9e7139135578.json';
  39.                 lsKey = 'upsell_Vertical_Carousel';
  40.                 getData(dataSourceUrl, lsKey);
  41.                 break;
  42.             case 'sodastream.se':
  43.                 dataSourceUrl = 'https://feeds.datafeedwatch.com/64397/ef779f79ebf13838f3e7f3f2ac33c9e4cf4589c8.json';
  44.                 lsKey = 'upsell_Vertical_Carousel';
  45.                 getData(dataSourceUrl, lsKey);
  46.                 break;
  47.             case 'sodastream.de':
  48.                 dataSourceUrl = 'https://feeds.datafeedwatch.com/64183/52bb0f7cc9cb9bbc6e9589624d3e5fb5c5465ed7.json';
  49.                 lsKey = 'upsell_Vertical_Carousel';
  50.                 getData(dataSourceUrl, lsKey);
  51.                 break;
  52.             case 'sodastream.co.il':
  53.                 dataSourceUrl = 'https://feeds.datafeedwatch.com/61539/3629a57f8b9506c6479db51037f3073b4db15bd9.json';
  54.                 lsKey = 'upsell_Vertical_Carousel';
  55.                 getData(dataSourceUrl, lsKey);
  56.                 break;
  57.             default:
  58.                 return;
  59.         }
  60.     } catch (requestError) { console.log(requestError) }
  61. })();
  62. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement