var RPTracker = /** @class */ (function () { function RPTracker() { this.systemCookieName = 'rpTrackingExternalUserId'; this.globalUserId = null; this.trackingDomain = 'https://telescope.realpage.com'; this.callbackName = 'null'; this.systemId = 'PLSW6'; this.customData = {}; } RPTracker.prototype.sendHit = function () { try { if (this.systemId != null) { var externalCookieValue = this.getSystemCookieValue(); if (typeof (externalCookieValue) === 'undefined') { externalCookieValue = this.generateExternalSystemId(); this.setSystemCookieValue(externalCookieValue); } } if (this.callbackName != null) { var fn = window[this.callbackName]; if (typeof fn === 'function') { this.customData = fn(); } } this.httpPostAsync(this.trackingDomain + '/collect?systemid=' + this.systemId + '&externaluserid=' + externalCookieValue + '&referrer=' + document.referrer + '&pageurl=' + window.location.href, this.customData); } catch (e) { console.error(e); } }; RPTracker.prototype.setSystemId = function (systemId) { this.systemId = systemId; }; RPTracker.prototype.setCustomData = function (customData) { this.customData = customData; }; RPTracker.prototype.getTrackingId = function () { return this.globalUserId; }; RPTracker.prototype.generateExternalSystemId = function () { 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); }); }; RPTracker.prototype.getSystemCookieValue = function () { return this.getCookieValueByName(this.systemCookieName); }; RPTracker.prototype.getCookieValueByName = function (cookieName) { var value = "; " + document.cookie; var parts = value.split("; " + cookieName + "="); if (parts.length == 2) return parts.pop().split(";").shift(); }; RPTracker.prototype.setSystemCookieValue = function (value) { var days = 30; var expires = ""; var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); document.cookie = this.systemCookieName + "=" + value + expires + "; path=/"; }; RPTracker.prototype.httpPostAsync = function (url, data) { var _this = this; var xmlHttp = new XMLHttpRequest(); xmlHttp.open("POST", url, true); xmlHttp.setRequestHeader("Content-Type", "application/json"); xmlHttp.withCredentials = true; xmlHttp.onreadystatechange = function () { if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { _this.globalUserId = xmlHttp.responseText; } }; xmlHttp.send(JSON.stringify(data)); }; return RPTracker; }()); var rptracker = rptracker || new RPTracker(); rptracker.sendHit(); //# sourceMappingURL=tracker.js.map