var codeplan1 = '70000000-0000-0000-0000-008e000f4468'; var codeplan2 = '70000000-0000-0000-0000-008e000f4468'; var div = document.createElement('div'); div.id = 'comm100-button-70000000-0000-0000-0000-008e000f4468'; document.body.appendChild(div); var Comm100API=Comm100API||{};(function(t){function e(e){var a=document.createElement("script"),c=document.getElementsByTagName("script")[0];a.type="text/javascript",a.async=!0,a.src=e+t.site_id,c.parentNode.insertBefore(a,c)}t.chat_buttons=t.chat_buttons||[],t.chat_buttons.push({code_plan:'70000000-0000-0000-0000-008e000f4468',div_id:"comm100-button-70000000-0000-0000-0000-008e000f4468"}),t.site_id=1000552,t.main_code_plan='70000000-0000-0000-0000-008e000f4468',e("https://vue.comm100.com/livechat.ashx?siteId="),setTimeout(function(){t.loaded||e("https://standby.comm100vue.com/livechat.ashx?siteId=")},5e3)})(Comm100API||{}); var shopifyAppUrl = 'https://api12.comm100.io/ShopifyApi/api/ShopifyApi/saveVisitor'; function saveVisitor(sdata) { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("POST", shopifyAppUrl, true); xmlhttp.setRequestHeader("Content-type", "application/json; charset=utf-8"); xmlhttp.send(JSON.stringify(sdata)); } function getCookie(name) { if (document.cookie.length > 0) { var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)) return unescape(arr[2]); else return ''; } return ''; } function setCookie(name, value) { var exp = new Date(); exp.setTime(exp.getTime() + 1 * 60 * 60 * 1000); document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/"; } function testCookie() { var keyName = "testCookie"; var valueStr = "shopifySaveVisitor"; setCookie(keyName, valueStr); return getCookie(keyName) === valueStr; } function GetShopifyId() { if (!testCookie()) { return; } if (shopifyAppUrl === null) { return; } var tempVisitorGuid = null; if (document.getElementById('comm100-container') !== null) { // var visitorState = document.getElementById('comm100-container').firstChild._component.props.store.getState(); var visitorState = document.getElementById('comm100-iframe').contentWindow.store.getState(); if (visitorState && visitorState.page && visitorState.page.visitor && visitorState.page.visitor.guid) { tempVisitorGuid = visitorState.page.visitor.guid; } } if (!tempVisitorGuid) { return; } var tempCustomerId = 0; if (meta && meta.page && meta.page.customerId) { tempCustomerId = meta.page.customerId; } else if (__st && __st.cid) { tempCustomerId = __st.cid; } var tempCartId = getCookie('cart'); if (tempVisitorGuid !== getCookie('shopifyVisitorGuid')) { var saveData = { shopifyVisitor: { siteId: visitorState.page.siteId, visitorGuid: tempVisitorGuid, codeplanId: visitorState.page.campaignId, saveType: 'savevisitor', customerId: tempCustomerId, cartId: tempCartId, domain: document.domain }, }; saveVisitor(saveData); setCookie('shopifyVisitorGuid', tempVisitorGuid); } if (tempCustomerId !== 0 && tempCustomerId.toString() !== getCookie('shopifyCustomerId')) { var saveData = { shopifyVisitor: { siteId: visitorState.page.siteId, visitorGuid: tempVisitorGuid, codeplanId: visitorState.page.campaignId, saveType: 'savevisitorcustomer', customerId: tempCustomerId, cartId: tempCartId, domain: document.domain }, }; saveVisitor(saveData); setCookie('shopifyCustomerId', tempCustomerId); } if (tempCartId && tempCartId !== getCookie('shopifyCartId')) { var saveData = { shopifyVisitor: { siteId: visitorState.page.siteId, visitorGuid: tempVisitorGuid, codeplanId: visitorState.page.campaignId, saveType: 'savevisitorcart', customerId: tempCustomerId, cartId: tempCartId, domain: document.domain }, }; saveVisitor(saveData); setCookie('shopifyCartId', tempCartId); } } var shopifyAppHander = setInterval(GetShopifyId, 5000);