var _at = {}; window._at.track = window._at.track || function(){(window._at.track.q = window._at.track.q || []).push(arguments);}; _at.domain = 'whitefoxboutique.com'; _at.owner = '83d308dfe60e'; _at.idSite = '21834'; _at.attributes = {}; _at.webpushid = 'web.42.aimtell.com'; _at.worker = '/apps/aimtell/assets/js/aimtell-worker.js.php'; (function() { var u='//cdn.aimtell.com/trackpush/';var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'trackpush.min.js'; s.parentNode.insertBefore(g,s); })(); if (window.location.protocol != 'https:' && window.location.href.indexOf('account') < 0) { httpsver = 'https:' + window.location.href.substring(window.location.protocol.length); fetch(httpsver, {mode: 'no-cors'}).then(function(response) { window.location.href = httpsver; //redirect }).catch(function(err) { console.log('Could not access https version of site'); }); } function _aimtellShopifyCartChecker(){ //generate call var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { //on response if (xhr.readyState == 4) { shopifyCartContents = JSON.parse(xhr.responseText); //if there are items in cart, loop through each item if(shopifyCartContents.item_count > 0){ //record cart information for add to cart features if(!_aimtellGetCookie('_aimtellCartToken-'+shopifyCartContents.token)){ var xmlhttp = new XMLHttpRequest(); var _aimtellShopifyData = {}; _aimtellShopifyData.subscriber = _aimtellSubscriberID; _aimtellShopifyData.cart = shopifyCartContents.token _aimtellShopifyData.idSite = _at.idSite; _aimtellShopifyData.owner_uid = _at.owner; _aimtellShopifyData.item_count = shopifyCartContents.item_count; //grab the first item and use the variables try { _aimtellShopifyData.variables = {}; _aimtellShopifyData.variables.price = (shopifyCartContents.items[0].price / 100); _aimtellShopifyData.variables.url = window.location.href + shopifyCartContents.items[0].url; _aimtellShopifyData.variables.icon = shopifyCartContents.items[0].image; _aimtellShopifyData.variables.title = shopifyCartContents.items[0].title; } catch (err) { console.warn('[Aimtell]' + err); } var postData = JSON.stringify(_aimtellShopifyData); //format data var postURL = _aimtellAPI+'/shopify/cookie'; //prod //fire off call to record data xmlhttp.open('POST', postURL,true); xmlhttp.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8'); xmlhttp.send(postData); //mark token as recorded _aimtellSetCookie('_aimtellCartToken-'+shopifyCartContents.token, true, 1) } //track each item as an event for (var i = 0; i < shopifyCartContents.items.length; i++) { //only track each item once if(!_aimtellGetCookie('_aimtellAddToCart-'+shopifyCartContents.items[i].id)){ _aimtellTrackEvent('Item', 'Add To Cart', shopifyCartContents.items[i].product_title) _aimtellSetCookie('_aimtellAddToCart-'+shopifyCartContents.items[i].id, true, 1) } } } } } xhr.open('GET','/cart.js', true); xhr.send(null); } function _aimtellShopifyReady(){ _aimtellShopifyCartChecker(); //on page load, check for all forms and add add to cart listener for (var i=0; i < document.forms.length; i++) { var action = document.forms[i].getAttribute('action'); if(action && action.indexOf('/cart') >= 0) { _aimtellListener(document.forms[i], 'submit', _aimtellShopifyCartChecker); } } }