var productID = 0; var vendor = ''; var featured_image = ''; var check_ref = window.location.hostname; if ("_GerdaAnalyticsConfig" in window){ //console.log('Landish 2'); //console.log('1d66d7b9da80'); //console.log(_GerdaAnalyticsConfig); //console.log(window.location.hostname); if(_GerdaAnalyticsConfig.product){ productID = _GerdaAnalyticsConfig.product.id; vendor = _GerdaAnalyticsConfig.product.vendor; featured_image = _GerdaAnalyticsConfig.product.featured_image; } var project_gerda = '1d66d7b9da80'; var type = ''; if(_GerdaAnalyticsConfig.type=='product'){ if(_GerdaAnalyticsConfig.product.available==false){ type = 'unavaiable'; } else { type = 'avaiable'; } } else { type = _GerdaAnalyticsConfig.type; } //console.log("SENDDATA"); sendData_gerda(window.location.pathname, productID, type, vendor, 0, featured_image); } function getURLParameter(name) { return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null; } function makeid(length) { var result = ''; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var charactersLength = characters.length; for ( var i = 0; i < length; i++ ) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) { return parts.pop().split(';').shift(); } } function sendData_gerda(path, productID=0, visit_type='visit', vendor = '', variantID=0, featured_image = '', AppID = false, order_number = ''){ if(AppID!==false){ project_gerda = AppID; } var utm_source = getURLParameter('utm_source'); var utm_medium = getURLParameter('utm_medium'); var utm_campaign = getURLParameter('utm_campaign'); var utm_term = getURLParameter('utm_term'); var utm_content = getURLParameter('utm_content'); var doc_ref = document.referrer; var myuid = '123'; //console.log("CHECK:" + doc_ref); //console.log("CHECK REF:" + check_ref); if (doc_ref.toLowerCase().indexOf(check_ref) >= 0){ doc_ref = ""; } //console.log("CHECKED:" + doc_ref); if(utm_source){ document.cookie = "utm_source=" + utm_source + ";path=/ ; max-age=31536000; SameSite=None; Secure"; } else if(getCookie('utm_source')!=undefined){ utm_source = getCookie('utm_source'); } if(utm_medium){ document.cookie = "utm_medium=" + utm_medium + ";path=/ ; max-age=31536000; SameSite=None; Secure"; } else if(getCookie('utm_medium')!=undefined){ utm_medium = getCookie('utm_medium'); } if(utm_campaign){ document.cookie = "utm_campaign=" + utm_campaign + ";path=/ ; max-age=31536000; SameSite=None; Secure"; } else if(getCookie('utm_campaign')!=undefined){ utm_campaign = getCookie('utm_campaign'); } if(utm_term){ document.cookie = "utm_term=" + utm_term + ";path=/ ; max-age=31536000; SameSite=None; Secure"; } else if(getCookie('utm_term')!=undefined){ utm_term = getCookie('utm_term'); } if(utm_content){ document.cookie = "utm_content=" + utm_content + ";path=/ ; max-age=31536000; SameSite=None; Secure"; } else if(getCookie('utm_content')!=undefined){ utm_content = getCookie('utm_content'); } if(doc_ref && doc_ref != ""){ document.cookie = "doc_ref=" + doc_ref + ";path=/ ; max-age=31536000; SameSite=None; Secure"; } else if(getCookie('doc_ref')!=undefined){ doc_ref = getCookie('doc_ref'); } //console.log("CHECK COOKIE:" + doc_ref); if(getCookie('myuid')==undefined){ myuid = makeid(8); document.cookie = "myuid=" + myuid + ";path=/ ;max-age=31536000; SameSite=None; Secure"; } else { myuid = getCookie('myuid'); } var uri = 'https://gerda.life/analyticsapp/apiPostAnalytics/' + project_gerda + '/?myuid=' + myuid + '&path=' + path + '&utm_source=' + utm_source + '&utm_medium=' + utm_medium + '&utm_campaign=' + utm_campaign + '&utm_term=' + utm_term + '&utm_content=' + utm_content + '&doc_ref=' + doc_ref + '&product_id=' + productID + '&vendor=' + vendor + '&visit_type=' + visit_type + '&featured_image=' + featured_image +'&order_number=' + order_number; //console.log("U:" + uri); fetch(uri) .then(response => response.json()); } // Listen Add to Cart 2 function parseQuery(queryString) { var query = {}; var pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&'); for (var i = 0; i < pairs.length; i++) { var pair = pairs[i].split('='); query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || ''); } return query; } //Reference the original methods XMLHttpRequest.prototype._send = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype._open = XMLHttpRequest.prototype.open; //override open XMLHttpRequest.prototype.open = function () { this._url = arguments[1]; //set the url we are opening this._open.apply(this,arguments); //call original open event with arguments }; //override send XMLHttpRequest.prototype.send = function () { //This is where your logic would need to live. //console.log("ADD_TO_CART:"); if(this._url=='/cart/add.js' || this._url=='/cart/add'){ var parsed_string = parseQuery(arguments[0]); //console.log("PARSED:"); //console.log(parsed_string); //console.log(parsed_string.id); sendData_gerda(window.location.pathname, _GerdaAnalyticsConfig.product.id, 'addtocart', _GerdaAnalyticsConfig.product.vendor, 0, featured_image); } this._send.apply(this, arguments); //call original send event with arguments }; // Listen Add to Cart (function(ns, fetch) { function send(data){ sendData_gerda(window.location.pathname, _GerdaAnalyticsConfig.product.id, 'addtocart', _GerdaAnalyticsConfig.product.vendor, 0, featured_image); } if (typeof fetch !== 'function') return; ns.fetch = function() { const response = fetch.apply(this, arguments); //console.log("RESPONSE:"); //console.log(response); response.then(res => { //console.log("RESIT:"); //console.log(res); if ([ `${window.location.origin}/cart/add.js`, `${window.location.origin}/cart/add`, ].includes(res.url)) { res.clone().json().then( data => send(data) ); } }); return response; } }(window, window.fetch))