Fix issue with sendBeacon request.

This commit is contained in:
Mike Cao 2022-03-10 19:01:33 -08:00
parent 48db7708de
commit 17790aa5a8
6 changed files with 23 additions and 22 deletions

View file

@ -47,7 +47,7 @@ import { removeTrailingSlash } from '../lib/url';
const post = (url, data, callback) => {
const req = new XMLHttpRequest();
req.open('POST', url, true);
req.setRequestHeader('Content-Type', 'application/json');
req.setRequestHeader('Content-Type', 'text/plain');
req.onreadystatechange = () => {
if (req.readyState === 4) {
@ -114,20 +114,16 @@ import { removeTrailingSlash } from '../lib/url';
const sendEvent = (value, type) => {
const payload = getPayload();
payload.event_type = type;
payload.event_value = value;
const blob = new Blob(
[
JSON.stringify({
type: 'event',
payload,
}),
],
{ type: 'application/json' },
);
const data = JSON.stringify({
type: 'event',
payload,
});
navigator.sendBeacon(`${root}/api/collect`, blob);
navigator.sendBeacon(`${root}/api/collect`, data);
};
const addEvents = node => {