prefix /api/metrics on android. fixes #1159
This commit is contained in:
parent
a42cec97f3
commit
41bfe31d61
2 changed files with 25 additions and 19 deletions
11
app/api.js
11
app/api.js
|
@ -390,3 +390,14 @@ export async function setFileList(bearerToken, data) {
|
||||||
});
|
});
|
||||||
return response.ok;
|
return response.ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function sendMetrics(blob) {
|
||||||
|
if (!navigator.sendBeacon) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
navigator.sendBeacon(getApiUrl('/api/metrics'), blob);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import storage from './storage';
|
import storage from './storage';
|
||||||
import { platform } from './utils';
|
import { platform } from './utils';
|
||||||
|
import { sendMetrics } from './api';
|
||||||
|
|
||||||
let appState = null;
|
let appState = null;
|
||||||
// let experiment = null;
|
// let experiment = null;
|
||||||
|
@ -31,27 +32,21 @@ function submitEvents() {
|
||||||
if (navigator.doNotTrack === '1') {
|
if (navigator.doNotTrack === '1') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const data = new Blob(
|
sendMetrics(
|
||||||
[
|
new Blob(
|
||||||
JSON.stringify({
|
[
|
||||||
now: Date.now(),
|
JSON.stringify({
|
||||||
session_id,
|
now: Date.now(),
|
||||||
lang,
|
session_id,
|
||||||
platform: platform(),
|
lang,
|
||||||
events
|
platform: platform(),
|
||||||
})
|
events
|
||||||
],
|
})
|
||||||
{ type: 'text/plain' } // see http://crbug.com/490015
|
],
|
||||||
|
{ type: 'text/plain' } // see http://crbug.com/490015
|
||||||
|
)
|
||||||
);
|
);
|
||||||
events.splice(0);
|
events.splice(0);
|
||||||
if (!navigator.sendBeacon) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
navigator.sendBeacon('/api/metrics', data);
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addEvent(event_type, event_properties) {
|
async function addEvent(event_type, event_properties) {
|
||||||
|
|
Loading…
Reference in a new issue