UNPKG

shadowaide-js

Version:

Automatically include the Net Promoter Score survey in your web or hybrid app with ShadowAide

629 lines 31.8 kB
!function() { function a(a, b, d, e) { if (c) return c[a]; for (b = document.cookie.split("; "), c = {}, e = b.length - 1; e >= 0; e--) d = b[e].split("="), c[d[0]] = d[1]; return c[a]; } function b(a, b, d) { document.cookie = a + "=" + b + ";" + d, c || (c = {}), c[a] = b; } var c; window.readCookie = a, window.writeCookie = b; }(), function() { String.prototype.includes || (String.prototype.includes = function(a, b) { "use strict"; return "number" != typeof b && (b = 0), b + a.length > this.length ? !1 : -1 !== this.indexOf(a, b); }); }(), function() { "use strict"; function a() { var a = document.currentScript; if (!a) for (var b = document.getElementsByTagName("script"), c = 0, d = b.length; d > c; c++) if ("//shadowaide" == b[c].innerHTML.slice(0, 10)) { a = b[c]; break; } return a; } function b(a, b, c, d) { return function() { var e = this, f = arguments, g = function() { b = null, d || a.apply(e, f); }, h = d && !b; return clearTimeout(b), b = setTimeout(g, c), h && a.apply(e, f), b; }; } function c(a) { var b = 0; return function(c, d) { return 0 !== b && "object" == typeof a && "object" == typeof d && a == d ? "[Circular]" : b >= 29 ? "[Unknown]" : (++b, d); }; } function d(a) { return a.replace(/^\s+|\s+$/gm, ""); } function e(a, b, c) { return a ? a.attachEvent ? a.attachEvent("on" + b, c) : a.addEventListener(b, c, !1) : void 0; } function f(a, b) { var c, e, f, g = a.className, h = b.match(t) || []; if (c = 1 === a.nodeType && (" " + d(g) + " ").replace(b, " ")) { for (var i = 0; e = h[i++]; ) for (;c.indexOf(" " + e + " ") > -1; ) c = c.replace(" " + e + " ", " "); f = c, g !== f && a.setAttribute("class", f); } } function g(a, b) { a.className = a.className + " " + b; } function h(a, b) { for (var c in b) try { b[c].constructor == Object ? a[c] = h(a[c], b[c]) : a[c] = b[c]; } catch (d) { a[c] = b[c]; } return a; } function i(a, b, c, d, e) { B.addToQueue({ msg: a, url: b, line: c, col: d, error: e }); } function j() { var a = C.getData("session"); if (!a) { if (a = readCookie("sa_session"), !a) { var b = location.hostname.match(/^([^\/?#]+)(?:[\/?#]|$)/i)[1].split(".").slice(-2).join("."); a = D.guid(), writeCookie("sa_session", a, "domain=" + b + ";path=/"); } C.storeData("session", a); } return a; } function k(a) { var b = j(), c = { apikey: u, session: b }, d = JSON.stringify(c), e = new XMLHttpRequest(); e.onreadystatechange = function() { if (e.readyState == XMLHttpRequest.DONE) { if (200 == e.status || 304 == e.status) { var b = JSON.parse(e.responseText); if (b) { var c = null, d = null, f = 864e5, g = new Date(), h = g - b.declineResurveyInterval * f, i = g - b.resurveyInterval * f; b.surveyAllowed = !0, localStorage && (c = readCookie("sasdec"), d = readCookie("sasres")), (c && c > h || d && d > i) && (b.surveyAllowed = !1), b.remaining <= 0 && (b.surveyAllowed = !1), E = b; } } a && a(E); } }, e.open("GET", x + ":" + y + "/api/v1/config"), e.setRequestHeader("Content-Type", "application/json"), e.setRequestHeader("x-api-key", u), e.send(d); } function l(a, b, c) { var d = Math.random(); if (a) { if (+b / 100 > d) return !0; } else if (+c / 100 > d) return !0; return !1; } function m(a, b) { for (var c = 0; c < b.length; c++) if (a.search(b[c])) return !0; return !1; } function n() { E ? o(E) && setTimeout(function() { p(); }, 1e3 * E.timeDelay) : k(function(a) { o(a) && setTimeout(function() { p(); }, 1e3 * a.timeDelay); }); } function o(a) { if (window.sa.config.dev) return !0; if (!a || !a.surveyAllowed) return !1; var b = !window.shadowaide.identify || !window.shadowaide.identify.email; return l(b, a.anonymousPct, a.registeredPct) && m(window.location.pathname, a.showOn) ? !0 : !1; } function p() { localStorage && writeCookie("sasres", new Date()); var a = document.getElementById("sa-survey-modal"); if (!a) { var b = { lang: { en: { nps_question: "How likely are you to recommend {{product}} to a friend or co-worker?", product: "this product or service", website: "this website", score_unlikely: "Not al all likely", score_likely: "Extremely likely", dismiss: "Dismiss", explain_score: "Help us by explaining your score", submit: "Send", thanks: "Thank you for your response, and your feedback!" }, es: { nps_question: "¿Qué probabilidad hay de que usted recomiende este {{product}} a un amigo o compañero de trabajo?", product: "producto o servicio", website: "sitio web", score_unlikely: "Absolutamente improbable", score_likely: "Extremadamente probable", dismiss: "Descartar", explain_score: "Ayúdenos explicando su puntuación", submit: "ENVIAR", thanks: "¡Gracias por su respuesta y por sus comentarios!" }, ru: { nps_question: "Насколько вероятно, что вы порекомендуете этот {{product}} другу или коллеге?", product: "продукт или сервис", website: "веб-сайт", score_unlikely: "Маловероятно", score_likely: "Очень вероятно", dismiss: "Отклонить", explain_score: "Помогите нам, объяснив ваш рейтинг", submit: "ОТПРАВИТЬ", thanks: "Спасибо за Ваш ответ и отзыв!!" }, pt: { nps_question: "Qual a probabilidade de você recomendar este {{product}} a um amigo ou colega de trabalho?", product: "produto ou serviço", website: "website", score_unlikely: "Nem um pouco provável", score_likely: "Extremamente provável", dismiss: "Dispensar", explain_score: "Ajude-nos explicando sua classificação", submit: "ENVIAR", thanks: "Obrigado por sua resposta e por seus comentários!" }, ja: { nps_question: "この{{product}}を友人または同僚に薦める可能性はどれくらいありますか?", product: "商品またはサービス", website: "ウェブサイト", score_unlikely: "可能性が全くない", score_likely: "可能性が非常に高い", dismiss: "無視", explain_score: "そのスコアをつけた理由を説明してください", submit: "送信", thanks: "ご意見とご感想をありがとうございました!" }, it: { nps_question: "Quanto è probabile che raccomanderà questo {{product}} ad un amico o a un collega?", product: "prodotto o servizio", website: "sito internet", score_unlikely: "Per niente probabile", score_likely: "Estremamente probabile", dismiss: "Declinare", explain_score: "Ci aiuti spiegando la Sua valutazione", submit: "INVIA", thanks: "Grazie per la tua risposta e per la tua valutazione!" }, hi: { nps_question: "आपके द्वारा इस {{product}} की सिफारिश किसी मित्र या सहकर्मी को करने की कितनी संभावना है?", product: "उत्पाद या सेवा", website: "वेबसाइट", score_unlikely: "कोई संभावना नहीं", score_likely: "अत्यंत संभावना", dismiss: "हटाएं", explain_score: "अपना स्कोर समझाकर हमारी सहायता करें", submit: "भेजें", thanks: "आपकी प्रतिक्रिया, और आपके फीडबैक के लिए धन्यवाद!" }, de: { nps_question: "Wie wahrscheinlich ist es, dass Sie {{product}} einem Freund oder Arbeitskollegen weiterempfehlen?", product: "dieses Produkt/diesen Service", website: "diese Website", score_unlikely: "Sehr unwahrscheinlich", score_likely: "Sehr wahrscheinlich", dismiss: "Ignorieren", explain_score: "Helfen Sie uns, indem Sie Ihre Bewertung erläutern", submit: "ABSCHICKEN", thanks: "Danke für Ihre Antworten und Ihr Feedback!" }, fr: { nps_question: "Comment situez-vous la probabilité que vous recommandiez ce {{product}} à un ami ou un collègue ?", product: "produit ou service", website: "site Web", score_unlikely: "Pas du tout probable", score_likely: "Extrêmement probable", dismiss: "Rejeter", explain_score: "Aidez-nous en expliquant votre score", submit: "ENVOYER", thanks: "Merci pour votre réponse et vos commentaires !" }, zh: { nps_question: "您向朋友或同事推荐此{{product}}的可能性有多大?", product: "产品或服务", website: "网站", score_unlikely: "完全不可能", score_likely: "极有可能", dismiss: "忽略", explain_score: "解释您的分数来帮助我们", submit: "发送", thanks: "感谢您的回应,以及您的反馈" } } }; b = h(b, window.sa.config); var c = navigator.languages && navigator.languages[0] || navigator.language || navigator.userLanguage; c || (c = "en"), void 0 === b.lang[c] && c.includes("-") && (c = c.substring(0, c.indexOf("-"))), void 0 == b.lang[c] && (c = "en"); var d = b.lang[c], i = d.nps_question; i = i.replace("{{product}}", d.product); var j = '<div id="sa-survey-modal" class="light sa-survey-modal sa-bottom"> <form id="sa-survey-form" method="post"> <div id="sa-survey-close"><span id="sa-survey-x">X</span><span id="sa-survey-dismiss">' + d.dismiss + '</span></div> <div class="thanks sa-survey-collapsed" id="sa-survey-thanks"> <p>' + d.thanks + '</p> </div> <div class="sa-survey-question" id="sa-survey-question"> <p id="sa-language-direction" dir="ltr">' + i + '</p> </div> <div class="sa-nps-score" id="sa-survey-fullscore"> <ul id="sa-nps-score"> <li>0</li> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> <li>7</li> <li>8</li> <li>9</li> <li>10</li> </ul> <label id="sa-survey-not-likely-label">' + d.score_unlikely + '</label> <label id="sa-survey-likely-label">' + d.score_likely + '</label> </div> <div class="sa-nps-score sa-survey-collapsed" id="sa-survey-feedback"> <textarea name="feedback" rows="2" placeholder="' + d.explain_score + '" id="sa-survey-text"></textarea> <input type="submit" value="' + d.submit + '" id="sa-survey-submit"> </div> </form> <p id="sa-powered-by">Powered By <a href="https://www.shadowaide.com" target="_blank">ShadowAide</a></p> </div>', k = document.createElement("div"); k.innerHTML = j, document.body.appendChild(k); var l = null; e(document.getElementById("sa-nps-score"), "click", function(a) { l = +a.target.outerText; for (var b = a.target.parentElement.children, c = b.length, d = 0; c > d; d++) f(b[d], "sa-score-selected"); g(a.target, "sa-score-selected"), f(document.getElementById("sa-survey-feedback"), "sa-survey-collapsed"); }), document.getElementById("sa-survey-form").onsubmit = function(a) { a.stopPropagation(), event.cancelBubble = !0, a.preventDefault(); var b = B.addDefaultData({ type: "survey", data: { score: l, feedback: document.getElementById("sa-survey-text").value } }); B.addToQueue(b), f(document.getElementById("sa-survey-thanks"), "sa-survey-collapsed"), g(document.getElementById("sa-survey-fullscore"), "sa-survey-collapsed"), g(document.getElementById("sa-survey-question"), "sa-survey-collapsed"), g(document.getElementById("sa-survey-feedback"), "sa-survey-collapsed"), g(document.getElementById("sa-survey-submit"), "sa-survey-collapsed"); }, e(document.getElementById("sa-survey-close"), "click", function(a) { localStorage && writeCookie("sasdec", new Date()), k.remove(); }); } } window.sa = window.sa || function() { var a = {}; return a.config = { debug: !1, dev: !1, ping_interval: 60, batch: !0, report_logs: !0, reporting_host: "https://events.shadowaide.com", reporting_port: "443", scroll_tracking: !1, mouse_tracking: !1 }, (a.q = a.q || []).push(arguments), a; }(); var q, r, s, t = /\S+/g, u = null, v = "https://events.shadowaide.com", w = 443, x = "https://dashboard.shadowaide.com", y = 443, z = a(); z && (u = z.getAttribute("data-apikey"), u || (u = z.getAttribute("apikey")), z.hasAttribute("data-reportingsvr") ? v = z.getAttribute("data-reportingsvr") : z.hasAttribute("reportingsvr") && (v = z.getAttribute("reportingsvr")), z.hasAttribute("data-reportingport") ? w = z.getAttribute("data-reportingport") : z.hasAttribute("reportingport") && (w = z.getAttribute("reportingport")), z.hasAttribute("data-dashboardsvr") ? x = z.getAttribute("data-dashboardsvr") : z.hasAttribute("dashboardsvr") && (x = z.getAttribute("dashboardsvr")), z.hasAttribute("data-dashboardport") ? y = z.getAttribute("data-dashboardport") : z.hasAttribute("dashboardport") && (y = z.getAttribute("dashboardport"))); var A = { bootstrap: function() { A.takeOverConsole(), A.registerListeners(), A.loadStyling(), B.loadQueue(), setInterval(function() { B.processQueue(); }, 3e3); }, takeOverConsole: function() { function a(a) { var c = b[a], d = a; b[a] = function() { if (window.sa.config.report_logs) { var a = B.eventType.CONSOLEERR; "warn" == d ? a = B.eventType.CONSOLEWARN : "log" == d && (a = B.eventType.CONSOLELOG); var e = B.addDefaultData({ type: a, data: arguments }); B.addToQueue(e); } if (c.apply) c.apply(b, arguments); else { var f = Array.prototype.slice.apply(arguments).join(" "); c(f); } }; } var b = window.console; if (window.sa.config.report_logs && b) for (var c = [ "log", "warn", "error" ], d = 0; d < c.length; d++) a(c[d]); }, loadStyling: function() { var a = "sa-css"; if (!document.getElementById(a)) { var b = document.getElementsByTagName("head")[0], c = document.createElement("link"); c.id = a, c.rel = "stylesheet", c.type = "text/css", c.href = "//events.shadowaide.com/js-client/css/sa_client.css", c.media = "all", b.appendChild(c); } }, registerListeners: function() { var a = window.onerror; window.onerror = function(b, c, d, e, f) { i(b, c, d, e, f), a && a(); }, document.addEventListener("click", function(a) { var b = a.currentTarget.activeElement.textContent; B.addEventToQueue(B.eventType.CLICK, { timestamp: new Date().valueOf(), location: document.URL, pageX: a.pageX, pageY: a.pageY, targetPath: C.getPathTo(a.target), sourcePath: C.getPathTo(a.srcElement), targetText: b }); }), window.addEventListener("abort", function(a) { B.addEventToQueue("abort", { timestamp: new Date().valueOf() }); }), window.addEventListener("error", function(a) { B.addToQueue({ type: B.eventType.CONSOLEERR, timestamp: new Date().valueOf(), data: a }); }), window.addEventListener("hashchange", window.shadowaide.pageload), "onpageshow" in window ? (window.addEventListener("pageshow", window.shadowaide.pageload), window.addEventListener("pagehide", function(a) {})) : (window.addEventListener("load", window.shadowaide.pageload), window.addEventListener("beforeunload", function(a) { B.addEventToQueue("unload", { timestamp: new Date().valueOf() }), B.processQueue(); })), window.addEventListener("resize", function(a) { r = b(function() { B.addEventToQueue("resize", { timestamp: new Date().valueOf(), height: window.innerHeight, width: window.innerWidth }); }, r, 300, !1)(); }), window.addEventListener("scroll", function(a) { window.sa.config.scroll_tracking && (q = b(function() { B.addEventToQueue(B.eventType.SCROLL, { timestamp: new Date().valueOf(), scrollX: window.scrollX, scrollY: window.scrollY }); }, q, 300, !1)()); }), window.addEventListener("mousemove", function(a) { if (window.sa.config.mouse_tracking) { var c = a.toElement || a.relatedTarget || a.target; s = b(function() { B.addEventToQueue(B.eventType.MOUSEMOVE, { timestamp: new Date().valueOf(), toElement: C.getPathTo(c), offsetX: a.offsetX, offsetY: a.offsetY, offsetXPct: a.offsetX / c.offsetWidth, offsetYPct: a.offsetY / c.offsetHeight }); }, s, 300, !1)(); } }), window.addEventListener("unload", function(a) { B.processQueue(); }), window.addEventListener("submit", function(a) { B.addEventToQueue("submit", B.addDefaultData({})); }), /loaded|complete/.test(document.readyState) && window.shadowaide.pageload(); } }, B = { eventType: Object.freeze({ PAGELOAD: "page_load", RESOURCELOAD: "resource_load", IDENTIFY: "identify", CLICK: "click", SCROLL: "scroll", LOG: "log", CONSOLELOG: "console_log", CONSOLEWARN: "console_warn", CONSOLEERR: "console_error", INTERACTION: "interaction", MOUSEMOVE: "mousemove" }), eventqueue: [], isProcessing: !1, lastLoadedResource: -1, addDefaultData: function(a) { a.timestamp = new Date().valueOf(), a.data || (a.data = {}), a.data.title = document.title, a.data.location = document.URL, a.data.browser = C.getBrowserDetails(); var b = C.getObjectProfile(window.performance && window.performance.timing ? window.performance.timing : {}); return a.data.timing = { dns: b.dns, dom: b.dom, duration: b.duration, entryType: b.entryType, load: b.load, loadtime: b.loadtime, name: b.name, ssl: b.ssl, tcp: b.tcp, ttfb: b.ttfb }, a.data.referrer = document.referrer, a; }, sendEvent: function(a, b) { var c = j(), b = { apikey: u, type: a, session: c, data: b }, d = JSON.stringify(b), e = new XMLHttpRequest(); e.open("POST", v + ":" + w + "/api/v1/interaction/"), e.setRequestHeader("Content-Type", "application/json"), e.send(d); }, sendBatch: function(a) { if (!(a.length < 1)) { var b = j(), c = { apikey: u, session: b, events: a }, d = JSON.stringify(c), e = new XMLHttpRequest(); e.open("POST", v + ":" + w + "/api/v1/event/batch"), e.setRequestHeader("Content-Type", "application/json"), e.send(d); } }, addToQueue: function(a) { return B.eventqueue.push(a), B.persistQueue(); }, persistQueue: function(a) { var b = a ? a : B.eventqueue; return C.storeData("shadow.queue", JSON.stringify(b, c(b))), a ? a : B.eventqueue; }, loadQueue: function() { var a = C.getData("shadow.queue"); return a ? B.eventqueue = JSON.parse(a) : B.eventqueue || (B.eventqueue = []), B.eventqueue; }, batchSize: 10, processQueue: function() { if (u && !B.isProcessing) { for (B.isProcessing = !0; B.eventqueue.length; ) try { B.sendBatch(B.eventqueue.slice(0, B.batchSize)), B.eventqueue.splice(0, B.batchSize), B.persistQueue(); } catch (a) { B.isProcessing = !1; break; } B.isProcessing = !1; } }, addNewResourcesToQueue: function() { for (var a = C.getResourceProfiles(), b = v.replace(/^https?\:/i, ""), c = 0, d = a.length; d > c; c++) { var e = a[c].name.replace(/^https?\:/i, ""); e != b + ("80" == w || "443" == w ? "" : ":" + w) + "/api/v1/event/batch" && B.addToQueue({ type: B.eventType.RESOURCELOAD, timestamp: new Date().getTime(), data: C.getObjectProfile(a[c]) }); } }, addEventToQueue: function(a, b) { var c = B.addDefaultData({ type: a, event: a, data: b }); B.addToQueue(c); } }, C = { getObjectProfile: function(a) { return { loadtime: a.requestStart && a.navigationStart ? a.loadEventStart - a.navigationStart : void 0, dns: a.domainLookupEnd && a.domainLookupStart ? a.domainLookupEnd - a.domainLookupStart : void 0, tcp: a.connectEnd && a.connectStart ? a.connectEnd - a.connectStart : void 0, ssl: a.connectEnd && a.secureConnectionStart ? a.connectEnd - a.secureConnectionStart : void 0, ttfb: a.responseStart && a.navigationStart ? a.responseStart - a.navigationStart : void 0, dom: a.domComplete && a.domLoading ? a.domComplete - a.domLoading : void 0, load: a.loadEventEnd && a.loadEventStart ? a.loadEventEnd - a.loadEventStart : void 0, name: a.name ? a.name : window.location.href, duration: a.duration ? a.duration : void 0, initiatorType: a.initiatorType ? a.initiatorType : void 0, entryType: a.entryType ? a.entryType : "page" }; }, getBrowserDetails: function() { for (var a = { agent: navigator.userAgent.toLowerCase(), codename: navigator.appCodeName, name: navigator.appName, version: navigator.appVersion, majorver: parseInt(navigator.appVersion), minorver: parseFloat(navigator.appVersion), platform: navigator.platform, viewport: Math.max(document.documentElement.clientWidth, window.innerWidth || 0) + "x" + Math.max(document.documentElement.clientHeight, window.innerHeight || 0), resolution: window.screen.availHeight + "x" + window.screen.availWidth, pixelratio: window.devicePixelRatio, language: navigator.languages || navigator.language || navigator.userLanguage, plugins: [] }, b = C.getPlugins(), c = 0; c < b.length; c++) a.plugins.push({ name: b[c].name, mime: b[c].mime }); return a; }, getPlugins: function() { for (var a = [], b = 0, c = navigator.plugins.length; c > b; b++) a.push(C.getPluginDetails(navigator.plugins[b])); return a; }, getPluginDetails: function(a) { for (var b = null, c = { name: a.name }, d = 0, e = a.length; e > d; d++) b && (b += ","), b += a[d].type; return c.mime = b, c; }, lastLoadedResource: -1, getResourceProfiles: function(a) { a || (a = C.lastLoadedResource); for (var b = window.performance && window.performance.getEntriesByType ? window.performance.getEntriesByType("resource") : window.performance && window.performance.getEntries ? window.performance.getEntries({ entryType: "resource" }) : [], c = [], d = a + 1, e = b.length; e > d; d++) c.push(b[d]), C.lastLoadedResource = d; return c; }, storeData: function(a, b) { localStorage && localStorage.setItem(a, b); }, getData: function(a) { var b = null; return localStorage && (b = localStorage.getItem(a)), b; }, getPathTo: function(a) { if (a) { if ("" !== a.id) return 'id("' + a.id + '")'; if (a === document.body) return a.tagName; for (var b = 0, c = a.parentNode ? a.parentNode.childNodes : [], d = 0; d < c.length; d++) { var e = c[d]; if (e === a) return C.getPathTo(a.parentNode) + "/" + a.tagName + "[" + (b + 1) + "]"; 1 === e.nodeType && e.tagName === a.tagName && b++; } } } }, D = { guid: function() { function a() { return Math.floor(65536 * (1 + Math.random())).toString(16).substring(1); } return a() + a() + "-" + a() + "-" + a() + "-" + a() + "-" + a() + a() + a(); } }, E = null; k(), window.shadowaide = { init: function(a) { u = a; }, config: function(a) {}, identify: function(a) { return a ? (a.email || (a = { id: null, name: null, email: null, age: null, plan: null, customer_since: null, active_experiments: null }), window.shadowaide.identity = a, void B.addEventToQueue(B.eventType.IDENTIFY, a)) : window.shadowaide.identity; }, debug: function(a) { return a ? void (window.sa.config.debug = a) : window.sa.config.debug; }, log: function(a, b, c) { var d = B.addDefaultData({ type: B.eventType.LOG, msg: b, data: c }); B.addToQueue(d); }, track: function(a, b, c) {}, event: function(a, b) { b.timestamp = new Date().valueOf(), B.addEventToQueue(a, b); }, pageload: function(a) { var b = B.addDefaultData({ type: B.eventType.PAGELOAD }); B.addToQueue(b), B.processQueue(); }, error: function(a) {}, "try": function(a) { try { a(); } catch (b) { this.error(b); } }, showSurvey: n }, A.bootstrap(); }(); //# sourceMappingURL=shadowaide.min.js.map