UNPKG

pxt-core

Version:

Microsoft MakeCode provides Blocks / JavaScript / Python tools and editors

68 lines (65 loc) 4.61 kB
<script type="text/javascript" src="/doccdn/pxtweb.js"></script> <script type="text/javascript"> window.loadAppInsights = function (includeCookie) { //Backend will patch / + doccdn + / with CDN url and the check that URL ends with the sha would pass var isProduction = includeCookie && (/[0-9a-f]{40}\/ai\.0\.js$/.test("/doccdn/ai.0.js")); var appInsights=window.appInsights||function(config){ function i(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},u=document,e=window,o="script",s="AuthenticatedUserContext",h="start",c="stop",l="Track",a=l+"Event",v=l+"Page",y=u.createElement(o),r,f;y.src=config.url||"https://az416426.vo.msecnd.net/scripts/a/ai.0.js";u.getElementsByTagName(o)[0].parentNode.appendChild(y);try{t.cookie=u.cookie}catch(p){}for(t.queue=[],t.version="1.0",r=["Event","Exception","Metric","PageView","Trace","Dependency"];r.length;)i("track"+r.pop());return i("set"+s),i("clear"+s),i(h+a),i(c+a),i(h+v),i(c+v),i("flush"),config.disableExceptionTracking||(r="onerror",i("_"+r),f=e[r],e[r]=function(config,i,u,e,o){var s=f&&f(config,i,u,e,o);return s!==!0&&t["_"+r](config,i,u,e,o),s}),t }({ instrumentationKey:"9801ed01-c40f-46ec-aa40-2a1742a9e71c", disableAjaxTracking: true, overridePageViewDuration: false, disableExceptionTracking: true, isCookieUseDisabled: !isProduction, isStorageUseDisabled: !isProduction, url: "/doccdn/ai.0.js" }); window.appInsights=appInsights; appInsights.queue.push(function () { appInsights.context.addTelemetryInitializer(function (envelope) { var telemetryItem = envelope.data.baseData; telemetryItem.properties = telemetryItem.properties || {}; telemetryItem.properties["cookie"] = isProduction; if (typeof pxtConfig === "undefined" || !pxtConfig || !pxtConfig.targetId) { telemetryItem.properties["target"] = "@targetid@"; return; } telemetryItem.properties["target"] = pxtConfig.targetId; telemetryItem.properties["stage"] = (pxtConfig.relprefix || "/--").replace(/[^a-z]/ig, '') if (typeof Windows !== "undefined") telemetryItem.properties["WindowsApp"] = 1; var userAgent = navigator.userAgent.toLowerCase(); var userAgentRegexResult = /\belectron\/(\d+\.\d+\.\d+.*?)(?: |$)/i.exec(userAgent); // Example navigator.userAgent: "Mozilla/5.0 Chrome/61.0.3163.100 Electron/2.0.0 Safari/537.36" if (userAgentRegexResult) { telemetryItem.properties["Electron"] = 1; telemetryItem.properties["ElectronVersion"] = userAgentRegexResult[1]; } if (typeof pxtElectron !== "undefined") { telemetryItem.properties["PxtElectron"] = 1; telemetryItem.properties["ElectronVersion"] = pxtElectron.versions.electronVersion; telemetryItem.properties["ChromiumVersion"] = pxtElectron.versions.chromiumVersion; telemetryItem.properties["NodeVersion"] = pxtElectron.versions.nodeVersion; telemetryItem.properties["PxtElectronVersion"] = pxtElectron.versions.pxtElectronVersion; telemetryItem.properties["PxtCoreVersion"] = pxtElectron.versions.pxtCoreVersion; telemetryItem.properties["PxtTargetVersion"] = pxtElectron.versions.pxtTargetVersion; telemetryItem.properties["PxtElectronIsProd"] = pxtElectron.versions.isProd; } }); }); var location = window.location.toString(); // Use generic title for script share page, otherwise use current page title var pageTitle = isScriptPage(location) ? "Share Page" : null; appInsights.trackPageView(pageTitle, scrubUrl(location), {urlReferrer: scrubUrl(document.referrer.toString())}); var scriptIdRegex = /(?:S?\d{5}-\d{5}-\d{5}-\d{5})|(?:_[0-9a-zA-Z]{12})/g; // Check if the current page contains a share URL function isScriptPage(url) { return !!url.match(scriptIdRegex); } // Scrub the key (if any) from the URL. function scrubUrl(url) { return url.replace(scriptIdRegex, "xxxxx-xxxxx-xxxxx-xxxxx"); } return isProduction; } pxt.initAnalyticsAsync(); </script>