Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
fix(core): fix event reporting bug
Browse files Browse the repository at this point in the history
fix #15
  • Loading branch information
foxted committed Dec 23, 2019
1 parent 5ef607b commit fae2b6a
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,26 @@ class Variate {
}

report(event: Event) {
const xhr = new XMLHttpRequest();
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();

xhr.open('POST', 'https://reporting.variate.ca/track', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(event.toJson());
xhr.open('POST', 'https://reporting.variate.ca/track', true);

return xhr.readyState === 4;
xhr.setRequestHeader('Content-Type', 'application/json');

xhr.onload = function() {
if (this.status >= 200 && this.status < 300) {
resolve(true);
} else {
reject(false);
}
};
xhr.onerror = function () {
reject(false);
};

xhr.send(event.toJson());
});
}
}

Expand Down

0 comments on commit fae2b6a

Please sign in to comment.