Skip to content

Commit 8ffee8a

Browse files
authored
add metrics collector html for desktop testing
1 parent caf9643 commit 8ffee8a

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

desktop-metrics.html

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Desktop Metrics logger with Google Analytics</title>
6+
<script>
7+
let gaReady = false;
8+
function installGoogleAnalytics(analyticsID, customUserID) {
9+
if(!analyticsID || !customUserID || gaReady){
10+
return ;
11+
}
12+
// ga primer scripts
13+
window.dataLayer = window.dataLayer || [];
14+
window.gtag = function() {
15+
window.dataLayer.push(arguments);
16+
if(window.dataLayer.length > 500){
17+
window.dataLayer.splice(0, 250); // remove half the elements offline queue guard
18+
}
19+
}
20+
21+
const gaScript = document.createElement('script');
22+
gaScript.async = true;
23+
gaScript.src = `https://www.googletagmanager.com/gtag/js?id=${analyticsID}`;
24+
document.head.appendChild(gaScript);
25+
26+
gtag('js', new Date());
27+
gtag('config', analyticsID, { 'user_id': customUserID });
28+
gaReady = true;
29+
}
30+
31+
async function processRequest(event) {
32+
const payload = event.payload;
33+
if(!gaReady) {
34+
installGoogleAnalytics(payload.analyticsID, payload.customUserID);
35+
}
36+
37+
for(let eventPayload of payload.events) {
38+
gtag('event', eventPayload.eventAct, {
39+
'event_category': eventPayload.category,
40+
'event_label': eventPayload.label,
41+
'value': eventPayload.count
42+
});
43+
}
44+
}
45+
window.__TAURI__.event.listen("health", processRequest);
46+
setInterval(async ()=>{
47+
// close window if the metrics hidden window is the only one around.
48+
const allTauriWindowsLabels = await window.__TAURI__.invoke('_get_window_labels');
49+
if(allTauriWindowsLabels.length === 1){
50+
window.__TAURI__.window.getCurrent().close();
51+
}
52+
}, 1000);
53+
</script>
54+
</head>
55+
<body>
56+
Phoenix Desktop Metrics emitter to GA.
57+
</body>
58+
</html>

0 commit comments

Comments
 (0)