(function () { !function (e, t) { if ("undefined" != typeof module && module.exports) module.exports = t(); else if ("function" == typeof define && define.amd) define([], function () { return e.ectrack = t() }); else { if ("undefined" != typeof ectrack) return null; e.ectrack = t() } }(this, function () { function e(e, t, n) { e.addEventListener ? e.addEventListener(t, n, !1) : e.attachEvent && e.attachEvent("on" + t, n) } Object.keys || (Object.keys = function (e) { var t = []; for (var n in e) e.hasOwnProperty(n) && t.push(n); return t }); var t, n, i, r, a = { startStopTimes: {}, idleTimeoutMs: 3e4, currentIdleTimeMs: 0, checkStateRateMs: 250, active: !1, idle: !1, currentPageName: "landing-page", timeElapsedCallbacks: [], userLeftCallbacks: [], userReturnCallbacks: [], trackTimeOnElement: function (t) { var n = document.getElementById(t); n && (e(n, "mouseover", function () { a.startTimer(t) }), e(n, "mousemove", function () { a.startTimer(t) }), e(n, "mouseleave", function () { a.startTimer(t) }), e(n, "keypress", function () { a.startTimer(t) }), e(n, "focus", function () { a.startTimer(t) })) }, getTimeOnElementInSeconds: function (e) { var t = a.getTimeOnPageInSeconds(e); return t || 0 }, startTimer: function (e) { if (e || (e = a.currentPageName), void 0 === a.startStopTimes[e]) a.startStopTimes[e] = []; else { var t = a.startStopTimes[e], n = t[t.length - 1]; if (void 0 !== n && void 0 === n.stopTime) return } a.startStopTimes[e].push({ startTime: new Date, stopTime: void 0 }), a.active = !0 }, stopAllTimers: function () { for (var e = Object.keys(a.startStopTimes), t = 0; t < e.length; t++) a.stopTimer(e[t]) }, stopTimer: function (e) { e || (e = a.currentPageName); var t = a.startStopTimes[e]; void 0 !== t && 0 !== t.length && (void 0 === t[t.length - 1].stopTime && (t[t.length - 1].stopTime = new Date), a.active = !1) }, getTimeOnCurrentPageInSeconds: function () { return a.getTimeOnPageInSeconds(a.currentPageName) }, getTimeOnPageInSeconds: function (e) { if (void 0 !== a.getTimeOnPageInMilliseconds(e)) return a.getTimeOnPageInMilliseconds(e) / 1e3 }, getTimeOnCurrentPageInMilliseconds: function () { return a.getTimeOnPageInMilliseconds(a.currentPageName) }, getTimeOnPageInMilliseconds: function (e) { var t = 0, n = a.startStopTimes[e]; if (void 0 !== n) { for (var i = 0, r = 0; r < n.length; r++) { var o = n[r].startTime, s = n[r].stopTime; void 0 === s && (s = new Date), i += s - o } return Number(i) } }, getTimeOnAllPagesInSeconds: function () { for (var e = [], t = Object.keys(a.startStopTimes), n = 0; n < t.length; n++) { var i = t[n], r = a.getTimeOnPageInSeconds(i); e.push({ pageName: i, timeOnPage: r }) } return e }, setIdleDurationInSeconds: function (e) { var t = parseFloat(e); if (!1 === isNaN(t)) a.idleTimeoutMs = 1e3 * e; else throw { name: "InvalidDurationException", message: "An invalid duration time (" + e + ") was provided." }; return this }, setCurrentPageName: function (e) { return a.currentPageName = e, this }, resetRecordedPageTime: function (e) { delete a.startStopTimes[e] }, resetAllRecordedPageTimes: function () { for (var e = Object.keys(a.startStopTimes), t = 0; t < e.length; t++) a.resetRecordedPageTime(e[t]) }, resetIdleCountdown: function () { a.idle && a.triggerUserHasReturned(), a.idle = !1, a.currentIdleTimeMs = 0 }, callWhenUserLeaves: function (e, t) { this.userLeftCallbacks.push({ callback: e, numberOfTimesToInvoke: t }) }, callWhenUserReturns: function (e, t) { this.userReturnCallbacks.push({ callback: e, numberOfTimesToInvoke: t }) }, triggerUserHasReturned: function () { if (!a.active) for (var e = 0; e < this.userReturnCallbacks.length; e++) { var t = this.userReturnCallbacks[e], n = t.numberOfTimesToInvoke; (isNaN(n) || void 0 === n || n > 0) && (t.numberOfTimesToInvoke -= 1, t.callback()) } a.startTimer() }, triggerUserHasLeftPage: function () { if (a.active) for (var e = 0; e < this.userLeftCallbacks.length; e++) { var t = this.userLeftCallbacks[e], n = t.numberOfTimesToInvoke; (isNaN(n) || void 0 === n || n > 0) && (t.numberOfTimesToInvoke -= 1, t.callback()) } a.stopAllTimers() }, callAfterTimeElapsedInSeconds: function (e, t) { a.timeElapsedCallbacks.push({ timeInSeconds: e, callback: t, pending: !0 }) }, checkState: function () { for (var e = 0; e < a.timeElapsedCallbacks.length; e++) a.timeElapsedCallbacks[e].pending && a.getTimeOnCurrentPageInSeconds() > a.timeElapsedCallbacks[e].timeInSeconds && (a.timeElapsedCallbacks[e].callback(), a.timeElapsedCallbacks[e].pending = !1); !1 === a.idle && a.currentIdleTimeMs > a.idleTimeoutMs ? (a.idle = !0, clearInterval(a.durationInterval), a.triggerUserHasLeftPage()) : a.currentIdleTimeMs += a.checkStateRateMs }, visibilityChangeEventName: void 0, hiddenPropName: void 0, listenForVisibilityEvents: function () { void 0 !== document.hidden ? (a.hiddenPropName = "hidden", a.visibilityChangeEventName = "visibilitychange") : void 0 !== document.mozHidden ? (a.hiddenPropName = "mozHidden", a.visibilityChangeEventName = "mozvisibilitychange") : void 0 !== document.msHidden ? (a.hiddenPropName = "msHidden", a.visibilityChangeEventName = "msvisibilitychange") : void 0 !== document.webkitHidden && (a.hiddenPropName = "webkitHidden", a.visibilityChangeEventName = "webkitvisibilitychange"), e(document, a.visibilityChangeEventName, function () { document[a.hiddenPropName] ? a.triggerUserHasLeftPage() : a.triggerUserHasReturned() }, !1), e(window, "blur", function () { a.triggerUserHasLeftPage() }), e(window, "focus", function () { a.triggerUserHasReturned() }), e(document, "mousemove", function () { a.resetIdleCountdown() }), e(document, "keyup", function () { a.resetIdleCountdown() }), e(document, "touchstart", function () { a.resetIdleCountdown() }), e(window, "scroll", function () { a.resetIdleCountdown() }), setInterval(function () { a.checkState() }, a.checkStateRateMs) }, initialize: function (e) { var t = 1800, n = a.currentPageName || "default-page-name"; e && (t = e.idleTimeoutInSeconds || t, n = e.currentPageName || n), a.setIdleDurationInSeconds(t).setCurrentPageName(n).listenForVisibilityEvents(), a.cookies = { visitor: "_ectrack_" + a.originid + "_visitor", visit: "_ectrack_" + a.originid + "_visit", events: "_ectrack_" + a.originid + "_events", utm: "_ectrack_" + a.originid + "_utm", prospect: "_ectrack_" + a.originid + "_prospect" }, a.prospectid = p(a.cookies.prospect); var i = U("_ecpid"); i && (a.prospectid = i, k(a.cookies.prospect, a.prospectid)); var r = document.querySelector("meta[name=ec_pagetoken]"); r && (a.landingpageid = r.getAttribute("value")); try { m = JSON.parse(p(a.cookies.events) || "[]") } catch (o) { } for (var s = 0; s < m.length; s++) O(m[s]); a.startTimer(); var c = function () { if (3 > a.getTimeOnCurrentPageInSeconds()) return !1; a.trackDuration() }; a.callWhenUserLeaves(function () { c() }, 5), a.callWhenUserReturns(function () { for (var e = 0; e < a.userLeftCallbacks.length; e++) { var t = a.userLeftCallbacks[e], n = t.numberOfTimesToInvoke; isNaN(n) || 0 != n || (t.numberOfTimesToInvoke = 1) } a.durationInterval = setInterval(function () { c() }, 3e4) }, 100), a.durationInterval = setInterval(function () { c() }, 3e4) } }; function o(e) { return Array.isArray(e) } var s = function e(t, n, i) { var r, a, s, c, u; return n = n || new FormData, void 0 === (r = t) || (o(t) ? t.forEach(function (t) { e(t, n, i + "[]") }) : (a = t) !== Object(a) || null != (c = s = t) && "number" == typeof c.size && "string" == typeof c.type && "function" == typeof c.slice && "number" == typeof s.lastModified && "string" == typeof s.name || (u = t) instanceof Date ? n.append(i, t) : Object.keys(t).forEach(function (r) { var a = t[r]; if (o(a)) for (; r.length > 2 && r.lastIndexOf("[]") === r.length - 2;) r = r.substring(0, r.length - 2); e(a, n, i ? i + "[" + r + "]" : r) })), n }, c = { set: function (e, t, n, i) { var r = "", a = ""; if (n) { var o = new Date; o.setTime(o.getTime() + 6e4 * n), r = "; expires=" + o.toGMTString() } i && (a = "; domain=" + i), document.cookie = e + "=" + escape(t) + r + a + "; path=/" }, get: function (e) { var t, n, i = e + "=", r = document.cookie.split(";"); for (t = 0; t < r.length; t++) { for (n = r[t]; " " === n.charAt(0) ;) n = n.substring(1, n.length); if (0 === n.indexOf(i)) return unescape(n.substring(i.length, n.length)) } return null } }, u = { urlPrefix: "", visitsUrl: "https://excelcrm.vn/modules/track/track.asmx/trackvisit", eventsUrl: "https://excelcrm.vn/modules/track/track.asmx/trackevents", cookieDomain: null, page: null, platform: "Web", useBeacon: !1, startOnReady: !0, trackVisits: false, cookies: !0, trackNow: !1 }; a.configure = function (e) { for (var t in e) e.hasOwnProperty(t) && (u[t] = e[t]) }; var l = window.jQuery || window.Zepto || window.$, d = !1, f = [], g = "undefined" != typeof JSON && void 0 !== JSON.stringify, m = []; function v() { return u.urlPrefix + u.eventsUrl } function k(e, t, n) { c.set(e, t, n, u.cookieDomain || u.domain) } function p(e) { return c.get(e) } function $(e) { c.set(e, "", -1) } function h(e) { p("ectrack_debug") && window.console.log(e) } function T() { for (var e; e = f.shift() ;) e(); d = !0 } function b(e) { d ? e() : f.push(e) } function y(t, n, i) { e(document, t, function (e) { var t, r, a; t = e.target, r = n, ((a = t.matches || t.matchesSelector || t.mozMatchesSelector || t.msMatchesSelector || t.oMatchesSelector || t.webkitMatchesSelector) ? a.apply(t, [r]) : (h("Unable to match"), !1)) && i(e) }) } function I() { u.cookies && g && k(a.cookies.events, JSON.stringify(m), 10) } function C() { var e = document.querySelector("meta[name=csrf-token]"); return e && e.content } function S(e) { var t = C(); t && e.setRequestHeader("X-CSRF-Token", t) } function P(e, t, n) { if (a.originid && void 0 !== a.originid && g) { if (l) l.ajax({ type: "POST", url: e, data: JSON.stringify(t), contentType: "application/json; charset=utf-8", dataType: "json", beforeSend: S, success: function (e) { n(e.d) } }); else { var i = new XMLHttpRequest; i.open("POST", e, !0), i.setRequestHeader("Content-Type", "application/json"), i.onreadystatechange = function () { i.readyState > 3 && 200 === i.status && n(JSON.parse(i.responseText).d) }, S(i), i.send(JSON.stringify(t)) } } } function x(e) { for (var t = {}, n = Object.keys(e), i = 0; i < n.length; i++) { var r = n[i]; "visit_token" != r && "visitor_token" != r && "id" != r && (t[r] = e[n[i]]) } return u.cookies && (t.visit_token = e.visit_token, t.visitor_token = e.visitor_token), delete e.visit_token, delete e.visitor_token, t } function O(e) { b(function () { var t = { trackEvent: x(e) }; P(v(), t, function (t) { for (var n = 0; n < m.length; n++) if (m[n].id == e.id) { m.splice(n, 1); break } I(), e.trackEventCallback && e.trackEventCallback(t) }) }) } function _() { return u.page || window.location.pathname } function E(e) { return e && e.length > 0 ? e : null } function N(e) { for (var t in e) e.hasOwnProperty(t) && null === e[t] && delete e[t]; return e } function w(e) { var t = e.target; return N({ tag: t.tagName.toLowerCase(), id: E(t.id), class: E(t.className), page: _(), section: function e(t) { for (; t && t !== document; t = t.parentNode) if (t.hasAttribute("data-section")) return t.getAttribute("data-section"); return null }(t) }) } function U(e, t) { t || (t = window.location.href); var n = RegExp("[?&]" + (e = e.replace(/[\[\]]/g, "\\$&")) + "(=([^&#]*)|&|#|$)").exec(t); return n ? n[2] ? decodeURIComponent(n[2].replace(/\+/g, " ")) : "" : null } function M(e) { var t = []; for (var n in e) e.hasOwnProperty(n) && t.push(encodeURIComponent(n) + "=" + encodeURIComponent(e[n])); return t.join("&") } function R() { if (d = !1, n = a.getVisitId(), i = a.getVisitorId(), r = p("ectrack_track"), !1 === u.cookies || !1 === u.trackVisits) h("Visit tracking disabled"), T(); else if (n && i && !r) h("Active visit"), T(); else if (n || (n = null, k(a.cookies.visit, n, 240)), p(a.cookies.visit)) { h("Visit started"), i || (i = null, k(a.cookies.visitor, i, 267840)); var e = { visit_token: n, visitor_token: i, platform: u.platform, landing_page: window.location.href, referrer: document.referrer, originid: a.originid }, t = U("_ecpid"); null != t && (e.prospect_id = t), a.landingpageid && (e.landingpage_id = a.landingpageid), e = { visit: e }, document.referrer.length > 0 && (e.referrer = document.referrer), h(e), P(u.urlPrefix + u.visitsUrl, e, function (e) { $("ectrack_track"), T(), e && (-1 == parseInt(e.sessionid) ? (a.originid = void 0, a.reset()) : (k(a.cookies.visitor, e.visitorid, 267840), k(a.cookies.visit, e.sessionid, 240))) }) } else h("Cookies disabled"), T() } function L(e) { return { utm_source: U("utm_source", e), utm_medium: U("utm_medium", e), utm_campaign: U("utm_campaign", e), utm_term: U("utm_term", e), utm_content: U("utm_content", e) } } return a.getVisitId = a.getVisitToken = function () { var e = p(a.cookies.visit); return 0 == e || "null" == e ? null : e }, a.getVisitorId = a.getVisitorToken = function () { var e = p(a.cookies.visitor); return 0 == e || "null" == e ? null : e }, a.getUtm = function (e) { var t = p(a.cookies.utm), n = {}; return (n = null == t ? L() : L(0 == t.indexOf("?") ? t : "?" + t)).optin = document.URL, n.referer = document.referrer, n.fbclid = U("fbclid"), n.gclid = U("gclid"), n = N(n), e && (n = M(n)), n }, a.reset = function () { return $(a.cookies.visitor), $(a.cookies.visit), $(a.cookies.events), $(a.cookies.utm), $("ectrack_track"), !0 }, a.debug = function (e) { return !1 === e ? $("ectrack_debug") : k("ectrack_debug", "t", 525600), !0 }, a.track = function (e, t) { var n = { name: e, id: "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (e) { var t = 16 * Math.random() | 0; return ("x" == e ? t : 3 & t | 8).toString(16) }) }; if (t) for (var i = Object.keys(t), r = 0; r < i.length; r++) n[i[r]] = t[i[r]]; return b(function () { u.cookies && !a.getVisitId() && R(), b(function () { if (h(n), n.visit_token = a.getVisitId(), n.visitor_token = a.getVisitorId(), (u.useBeacon || u.trackNow) && g && void 0 !== window.navigator.sendBeacon) { var e; e = n, b(function () { var t, n = x(e), i = (t = document.querySelector("meta[name=csrf-param]")) && t.content, r = C(); i && r && (n[i] = r), n.events_json = JSON.stringify(n.events), delete n.events, window.navigator.sendBeacon(v(), s(n)) }) } else m.push(n), I(), setTimeout(function () { O(n) }, 1e3) }) }), !0 }, a.trackView = function (e) { var t = { url: window.location.href, title: document.title, page: _() }; if (e) for (var n in e) e.hasOwnProperty(n) && (t[n] = e[n]); a.track("view", t) }, a.trackClicks = function () { y("click", "a, button, input[type=submit]", function (e) { var t = e.target, n = w(e); n.text = "input" == n.tag ? t.value : (t.textContent || t.innerText || t.innerHTML).replace(/[\s\r\n]+/g, " ").trim(), n.href = t.href, a.track("click", n) }) }, a.trackSubmits = function () { y("submit", "form", function (e) { var t = w(e); a.track("submit", t) }) }, a.trackChanges = function () { y("change", "input, textarea, select", function (e) { var t = w(e); a.track("change", t) }) }, a.trackAll = function () { a.trackView(), a.trackClicks(), a.trackSubmits(), a.trackChanges() }, a.trackDuration = function () { var e = a.getTimeOnCurrentPageInSeconds(), t = new Date, n = function (e) { return ("0" + e).slice(-2) }, i = t.getUTCFullYear() + "/" + n(t.getUTCMonth() + 1) + "/" + n(t.getUTCDate()) + " " + n(t.getUTCHours()) + ":" + n(t.getUTCMinutes()) + ":" + n(t.getUTCSeconds()), r = { duration: e, url: window.location.href, createddate: i }; a.prospectid && (r.prospect_id = a.prospectid), a.landingpageid && (r.landingpage_id = a.landingpageid), r.trackEventCallback = function (e) { void 0 != e && (-1 == (e = parseInt(e)) ? a.originid = void 0 : 0 == e ? (a.reset(), R()) : (a.resetRecordedPageTime(a.currentPageName), a.stopTimer(a.currentPageName), a.startTimer(a.currentPageName))) }, a.track("leave", r) }, a.start = function () { var e; R(), null != (e = L()).utm_source && null != e.utm_medium && null != e.utm_campaign && (e = N(e), k(a.cookies.utm, M(e), 267840)), a.start = function () { } }, t = function () { if (u.startOnReady) { var e = document.getElementById("_ectrackjs"); e && null == a.originid && (a.originid = U("trackid", e.src), a.initialize(), a.start(), "ecjstracking-test" == U("utm_source") && a.cookies.visitor && a.trackDuration()) } }, "interactive" === document.readyState || "complete" === document.readyState ? t() : e(document, "DOMContentLoaded", t), a }) }).call(this);