Skip to content

Commit

Permalink
Identify kiosk uwp app in telemetry (#9714)
Browse files Browse the repository at this point in the history
  • Loading branch information
eanders-ms authored Oct 10, 2023
1 parent 276f736 commit c240cd1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
14 changes: 11 additions & 3 deletions docfiles/pxtweb/cookieCompliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ namespace pxt {
telemetryItem.properties["stage"] = (pxtConfig.relprefix || "/--").replace(/[^a-z]/ig, '')

const userAgent = navigator.userAgent.toLowerCase();
const 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) {
const electronRegexResult = /\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 (electronRegexResult) {
telemetryItem.properties["Electron"] = 1;
telemetryItem.properties["ElectronVersion"] = userAgentRegexResult[1];
telemetryItem.properties["ElectronVersion"] = electronRegexResult[1];
}

const pxtElectron = (window as any).pxtElectron;
Expand All @@ -231,6 +231,14 @@ namespace pxt {
telemetryItem.properties["PxtElectronIsProd"] = pxtElectron.versions.isProd;
}

// Kiosk UWP info is appended to the user agent by the makecode-dotnet-apps/arcade-kiosk UWP app
const kioskUwpRegexResult = /\((MakeCode Arcade Kiosk UWP)\/([\S]+)\/([\S]+)\)/i.exec(userAgent); // Example navigator.userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.60 (MakeCode Arcade Kiosk UWP/0.1.41.0/Windows.Xbox)"
if (kioskUwpRegexResult) {
telemetryItem.properties["KioskUwp"] = 1;
telemetryItem.properties["KioskUwpVersion"] = kioskUwpRegexResult[2];
telemetryItem.properties["KioskUwpPlatform"] = kioskUwpRegexResult[3];
}

// "cookie" does not actually correspond to whether or not we drop the cookie because we recently
// switched to immediately dropping it rather than waiting. Instead, we maintain the legacy behavior
// of only setting it to true for production sites where interactive consent has been obtained
Expand Down
13 changes: 10 additions & 3 deletions docfiles/tracking.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
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) {
var electronRegexResult = /\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 (electronRegexResult) {
telemetryItem.properties["Electron"] = 1;
telemetryItem.properties["ElectronVersion"] = userAgentRegexResult[1];
telemetryItem.properties["ElectronVersion"] = electronRegexResult[1];
}
if (typeof pxtElectron !== "undefined") {
telemetryItem.properties["PxtElectron"] = 1;
Expand All @@ -56,6 +56,13 @@
telemetryItem.properties["PxtTargetVersion"] = pxtElectron.versions.pxtTargetVersion;
telemetryItem.properties["PxtElectronIsProd"] = pxtElectron.versions.isProd;
}
// Kiosk UWP info is appended to the user agent by the makecode-dotnet-apps/arcade-kiosk UWP app
var kioskUwpRegexResult = /\((MakeCode Arcade Kiosk UWP)\/([\S]+)\/([\S]+)\)/i.exec(userAgent); // Example navigator.userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.60 (MakeCode Arcade Kiosk UWP/0.1.41.0/Windows.Xbox)"
if (kioskUwpRegexResult) {
telemetryItem.properties["KioskUwp"] = 1;
telemetryItem.properties["KioskUwpVersion"] = kioskUwpRegexResult[2];
telemetryItem.properties["KioskUwpPlatform"] = kioskUwpRegexResult[3];
}
return true;
});
},
Expand Down

0 comments on commit c240cd1

Please sign in to comment.