Skip to content

Commit d333e4a

Browse files
committed
chore: metrics ga migration to electron
1 parent b4ec59d commit d333e4a

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

src/desktop-metrics.html

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
<meta name="robots" content="noindex, nofollow">
66
<title>Desktop Metrics logger with Google Analytics</title>
77
<script>
8+
// Set __ELECTRON__ flag like index.html does
9+
if(window.electronAppAPI) {
10+
window.__ELECTRON__ = true;
11+
}
12+
813
const SAVED_GOOGLE_ANALYTICS_DESKTOP_KEY = "SAVED_GOOGLE_ANALYTICS_DESKTOP_KEY";
914
let gaReady = false, loadedGoogleAnalyticsID;
1015

@@ -20,8 +25,10 @@
2025
let gaFocusCallback, focusCallbackDone;
2126
window.savedEventListener = window.addEventListener;
2227
savedEventListener('focus', (focusEvent)=>{
23-
gaFocusCallback.call(this, focusEvent);
24-
focusCallbackDone = true;
28+
if (gaFocusCallback) {
29+
gaFocusCallback.call(this, focusEvent);
30+
focusCallbackDone = true;
31+
}
2532
});
2633

2734
window.addEventListener = function (eventName, fn, globalEvFlag) {
@@ -118,17 +125,25 @@
118125
setTimeout(reloadOnce, 1000);
119126
}
120127
}
121-
window.__TAURI__.event.listen("health", processRequest);
122-
setInterval(async ()=>{
123-
// close window if the metrics hidden window and file drop window is the only one around.
124-
const allTauriWindowsLabels = await window.__TAURI__.invoke('_get_window_labels');
125-
if(allTauriWindowsLabels.length === 2 || allTauriWindowsLabels.length === 1){
126-
window.__TAURI__.window.getCurrent().close();
127-
}
128-
}, 1000);
128+
129+
if(window.__TAURI__) {
130+
window.__TAURI__.event.listen("health", processRequest);
131+
setInterval(async ()=>{
132+
// close window if the metrics hidden window and file drop window is the only one around.
133+
const allTauriWindowsLabels = await window.__TAURI__.invoke('_get_window_labels');
134+
if(allTauriWindowsLabels.length === 2 || allTauriWindowsLabels.length === 1){
135+
window.__TAURI__.window.getCurrent().close();
136+
}
137+
}, 1000);
138+
} else if(window.__ELECTRON__) {
139+
window.electronAPI.onHealthMetric((payload) => {
140+
processRequest({ payload });
141+
});
142+
// No cleanup needed - Electron app exits when main windows close
143+
}
129144
</script>
130145
</head>
131146
<body>
132147
Phoenix Desktop Metrics emitter to GA.
133148
</body>
134-
</html>
149+
</html>

src/utils/Metrics.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,14 @@ define(function (require, exports, module) {
196196

197197
function _sendNativeGAEvent(analyticsID, customUserID, events=[]) {
198198
if(window.__TAURI__){
199-
return _sendTauriGAEvent(analyticsID, customUserID, events=[]);
199+
return _sendTauriGAEvent(analyticsID, customUserID, events);
200200
}
201201
if(window.__ELECTRON__){
202-
// todo electron send event to metrics window with electron
202+
window.electronAPI.sendHealthMetric({
203+
analyticsID: analyticsID,
204+
customUserID: customUserID,
205+
events: events
206+
});
203207
return;
204208
}
205209
console.error("Metrics send event failed. Unknown native platform");

0 commit comments

Comments
 (0)