✨ tracking: Track browser/OS of webui on load
Can of course be disabled. Better implementation of #4148 Thanks you @apbarratt!
This commit is contained in:
1 parent
e6860aaec6
commit
c37c64a742
4 files changed
+70
-1
No files matched your search
@@ -38,6 +38,7 @@ class TrackingPlugin(
|
||||
octoprint.plugin.AssetPlugin,
|
||||
octoprint.plugin.WizardPlugin,
|
||||
octoprint.plugin.EventHandlerPlugin,
|
||||
octoprint.plugin.SimpleApiPlugin,
|
||||
):
|
||||
def __init__(self):
|
||||
self._environment = None
|
||||
@@ -76,6 +77,7 @@ class TrackingPlugin(
|
||||
"printer_safety_check": True,
|
||||
"throttled": True,
|
||||
"slicing": True,
|
||||
"webui_load": True,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -94,6 +96,26 @@ class TrackingPlugin(
|
||||
# tracking was just enabled, let's start up tracking
|
||||
self._start_tracking()
|
||||
|
||||
##~~ SimpleApiPlugin
|
||||
|
||||
def get_api_commands(self):
|
||||
return {"track": ["event", "payload"]}
|
||||
|
||||
def on_api_command(self, command, data):
|
||||
if command != "track":
|
||||
return
|
||||
|
||||
event = data.pop("event")
|
||||
if event == "webui_load":
|
||||
payload = data.get("payload", {})
|
||||
browser_name = payload.get("browser_name")
|
||||
browser_version = payload.get("browser_version")
|
||||
os_name = payload.get("os_name")
|
||||
os_version = payload.get("os_version")
|
||||
|
||||
if all((browser_name, browser_version, os_name, os_version)):
|
||||
self._track_webui_load(browser_name, browser_version, os_name, os_version)
|
||||
|
||||
##~~ EnvironmentDetectionPlugin
|
||||
|
||||
def on_environment_detected(self, environment, *args, **kwargs):
|
||||
@@ -191,7 +213,7 @@ class TrackingPlugin(
|
||||
##~~ AssetPlugin
|
||||
|
||||
def get_assets(self):
|
||||
return {"js": ["js/usage.js"]}
|
||||
return {"js": ["js/usage.js"], "clientjs": ["clientjs/usage.js"]}
|
||||
|
||||
##~~ WizardPlugin
|
||||
|
||||
@@ -280,6 +302,18 @@ class TrackingPlugin(
|
||||
|
||||
self._track("shutdown")
|
||||
|
||||
def _track_webui_load(self, browser_name, browser_version, os_name, os_version):
|
||||
if not self._settings.get_boolean(["events", "webui_load"]):
|
||||
return
|
||||
|
||||
self._track(
|
||||
"webui_load",
|
||||
browser_name=browser_name,
|
||||
browser_version=browser_version,
|
||||
os_name=os_name,
|
||||
os_version=os_version,
|
||||
)
|
||||
|
||||
def _track_plugin_event(self, event, payload):
|
||||
if not self._settings.get_boolean(["events", "plugin"]):
|
||||
return
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["OctoPrintClient"], factory);
|
||||
} else {
|
||||
factory(global.OctoPrintClient);
|
||||
}
|
||||
})(this, function (OctoPrintClient) {
|
||||
var OctoPrintTrackingClient = function (base) {
|
||||
this.base = base;
|
||||
};
|
||||
|
||||
OctoPrintTrackingClient.prototype.track = function (event, payload, opts) {
|
||||
return this.base.simpleApiCommand(
|
||||
"tracking",
|
||||
"track",
|
||||
{event: event, payload: payload},
|
||||
opts
|
||||
);
|
||||
};
|
||||
|
||||
OctoPrintClient.registerPluginComponent("tracking", OctoPrintTrackingClient);
|
||||
return OctoPrintTrackingClient;
|
||||
});
|
||||
@@ -10,6 +10,15 @@ $(function () {
|
||||
self.active = ko.observable();
|
||||
self.required = false;
|
||||
|
||||
self.onStartupComplete = function () {
|
||||
OctoPrint.plugins.tracking.track("webui_load", {
|
||||
browser_name: OctoPrint.coreui.browser.name,
|
||||
browser_version: OctoPrint.coreui.browser.browser_version,
|
||||
os_name: OctoPrint.coreui.browser.os_name,
|
||||
os_version: OctoPrint.coreui.browser.os_version
|
||||
});
|
||||
};
|
||||
|
||||
self.enableUsage = function () {
|
||||
self.settingsViewModel.settings.plugins.tracking.enabled(true);
|
||||
self.decision(true);
|
||||
|
||||
@@ -52,6 +52,9 @@
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: settings.plugins.tracking.events.slicing"> {{ _('Onboard slicing actions') }}
|
||||
</label>
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: settings.plugins.tracking.events.webui_load"> {{ _('Web interface load') }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
Reference in new issue
Block a user