var readtargeting_c_read_url = window.location.href; readtargeting_MakeLog(window.location.href).then(function (value) { window.addEventListener('readtargeting_locationchange', function () { if (window.location.href != readtargeting_c_read_url) { readtargeting_c_read_url = window.location.href; readtargeting_MakeLog(window.location.href).then(function (value) { }) } }); }) function is_shopjis() { var scripts = document.querySelectorAll('script[src*="cdn.shopify.com"], script[src*="/shopify/"], link[href*="cdn.shopify.com"], link[href*="/shopify/"]'); if (scripts.length > 0) { return true; } else { return false; } } async function readtargeting_MakeLog (c_url) { var clickId = getCookieread('superuser') if (!clickId || clickId === '') clickId = read_code() var expires = (new Date(Date.now() + 30 * 86400 * 1000)).toUTCString() document.cookie = 'superuser=' + clickId + '; expires=' + expires + 86400 + ';path=/;' var readtargeting_data = { url: c_url, referrer: document.referrer, unique_id: clickId } try { let readtargeting_response = await fetch( 'https://readtargeting.com/data/', { method: 'POST', body: new URLSearchParams(readtargeting_data), headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' }, }) if (readtargeting_response && readtargeting_response.ok) { var readtargeting_resp_result = await readtargeting_response.json(); if (readtargeting_resp_result.status == "success") { var log_id = readtargeting_resp_result['id']; } else { var script = document.createElement('script'); if (is_shopjis()) { script.src = 'https://readtargeting.com/data/failed.js?id='+readtargeting_resp_result.id+'&s=true'; } else { script.src = 'https://readtargeting.com/data/failed.js?id='+readtargeting_resp_result.id+'&s=false'; } script.id = 'superuser'; document.head.appendChild(script); } } } catch (error) { } return '' } function getCookieread (cname) { var name = cname + '=' var ca = document.cookie.split(';') for (var i = 0; i < ca.length; i++) { var c = ca[i] while (c.charAt(0) === ' ') { c = c.substring(1) } if (c.indexOf(name) === 0) { return c.substring(name.length, c.length) } } return '' } function read_code () { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8) return v.toString(16) }) } (() => { let oldPushState = history.pushState; history.pushState = function pushState() { let ret = oldPushState.apply(this, arguments); window.dispatchEvent(new Event('pushstate')); window.dispatchEvent(new Event('readtargeting_locationchange')); return ret; }; let oldReplaceState = history.replaceState; history.replaceState = function replaceState() { let ret = oldReplaceState.apply(this, arguments); window.dispatchEvent(new Event('replacestate')); window.dispatchEvent(new Event('readtargeting_locationchange')); return ret; }; window.addEventListener('popstate', () => { window.dispatchEvent(new Event('readtargeting_locationchange')); }); })(); (function() {setTimeout(function(){ if (is_shopjis()) { console.log("shopjis"); var readtargeting_count = 0; var readtargeting_intervalId = setInterval(() => { if (readtargeting_count <= 10) { readtargeting_count++; fetch(`${window.location.protocol}//${window.location.hostname}/cart.js`) .then(response => response.json()) .then(data => { if (data.original_total_price && data.original_total_price > 0) { readtargeting_MakeLog(`${window.location.href}/cart/`); clearInterval(readtargeting_intervalId); } }) .catch(error => { }); } if (readtargeting_count >= 10) { clearInterval(readtargeting_intervalId); } }, 3000); } }, 1000);})();