var fcAttribution = (function(fcAttribution) { var attrCookie = '_fc_attr', loggedInCookie = '_fc_logged_in', cookieDays = 182, // ~ 6 months attrParams = ['utm_medium', 'utm_source', 'utm_term', 'utm_content', 'utm_campaign', 'gclid']; function getCookie(name) { name = name + '='; var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = cookies[i]; while (cookie.charAt(0) == ' ') { cookie = cookie.substring(1); } if (cookie.indexOf(name) == 0) { return cookie.substring(name.length, cookie.length); } } return ''; } function setCookie(name, value, expiryDays) { var d = new Date(); d.setTime(d.getTime() + (expiryDays * 24 * 60 * 60 * 1000)); var expires = 'expires=' + d.toUTCString(); document.cookie = name + '=' + value + '; ' + expires + '; domain=.fullcontact.com; path=/'; } function deleteCookie(name) { setCookie(name, '', -1); } function getUrlParameter(name) { name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'), results = regex.exec(location.search); return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); }; function getFCAttrs() { var cookieVal = getCookie(attrCookie); if (cookieVal) { return JSON.parse(atob(cookieVal)); } return []; } function storeAttributions() { var referrer = document.referrer, isLoggedIn = getCookie(loggedInCookie); // Make sure that there is a referrer, we aren't logged in, and the referrer does not match https://*.fullcontact.com* if (referrer && !referrer.match(/https:\/\/[\w]+\.fullcontact\.com.*/i) && !isLoggedIn && typeof atob === 'function' && typeof btoa === 'function') { var fcAttrs = getFCAttrs(), attrKey, paramVal, attr = { referrer: referrer }; for (var i in attrParams) { attrKey = attrParams[i]; paramVal = getUrlParameter(attrKey); if (paramVal) { attr[attrKey] = paramVal; } } attr.click_time = (new Date()).toISOString().slice(0, -5); fcAttrs.push(attr); setCookie(attrCookie, btoa(JSON.stringify(fcAttrs)), cookieDays); } return false; } function clearCookies() { deleteCookie(attrCookie); } fcAttribution.storeAttributions = storeAttributions; fcAttribution.clearCookies = clearCookies; return fcAttribution; })(fcAttribution || {}); fcAttribution.storeAttributions();