window._lmtag = window._lmtag ? window._lmtag : _lmtag = { _lm_pixel_url: "https://lovys-1.leadsmonitor.io/pixel.gif", _lm_tracked_params: [ 'id', 'ref', 'type', 'location', 'revenue' ], _lm_id: undefined, _lmBuildParams: function(obj) { return this._lm_tracked_params.reduce(function(r, item) { if (obj[item] != undefined) { return r + ((r == "") ? "?" : "&") + item + "=" + obj[item]; } return r; }, ""); }, _lmWriteTag: function(src) { const _lm_pixel_tag = ""; if (document.getElementById('_lm_pix') != null) { var _lm_old_pix = document.getElementById('_lm_pix').innerHTML; document.getElementById('_lm_pix').innerHTML = _lm_old_pix + _lm_pixel_tag; } else { const i = document.createElement('div'); i.id = '_lm_pix' i.innerHTML = _lm_pixel_tag; document.body.appendChild(i); } }, _lmCreateLmId: function() { const id = Math.floor(Date.now() * Math.random()).toString(36).toUpperCase() + Math.floor(Date.now() * Math.random()).toString(36).toUpperCase(); this._lm_id = id; const cookieExpirationDate = new Date(); cookieExpirationDate.setTime(Date.now() + 365*24*60*60*1000); const newCookie = '_lm_id=' + id + '; expires=' + cookieExpirationDate.toGMTString() + "; path=/;SameSite=None;Secure"; document.cookie = newCookie; console.log(document.cookie); }, _lmRefreshId: function() { if (this._lm_id != undefined) { return ; } else if (window._lm_id != undefined) { this._lm_id = window._lm_id; } else if (localStorage != undefined && localStorage.getItem('_lm_id') != null) { this._lm_id = localStorage.getItem('_lm_id'); } else if (document.cookie != undefined && document.cookie.match(/_lm_id=([^;]+)/) != null) { this._lm_id = String(document.cookie.match(/_lm_id=([^;]+)/)[1]); localStorage.setItem('_lm_id', this._lm_id); } else { this._lmCreateLmId(); } }, registerHit: function(hitType = undefined, parameters = {}) { parameters.type = hitType; if (hitType == 'visit') { hitType = undefined; } this._lmRefreshId(); parameters['id'] = this._lm_id; if (document.referrer != "") { parameters['ref'] = encodeURIComponent(document.referrer); } if (document.location != "") { parameters['location'] = encodeURIComponent(document.location); } const paramString = this._lmBuildParams(parameters); this._lmWriteTag(this._lm_pixel_url + paramString); } }; // polyfill if (!Date.now) { Date.now = function now() { return new Date().getTime(); }; } // !polyfill