addsearch-js-client
Version:
AddSearch API JavaScript client
29 lines • 944 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const es6_promise_1 = require("es6-promise");
const api_1 = require("./api");
(0, es6_promise_1.polyfill)();
const sendStats = (apiHostname, sitekey, payload, statsRequestIntercepted) => {
// Beacon in browsers
if (typeof window !== 'undefined' &&
window.navigator &&
window.navigator.sendBeacon &&
!statsRequestIntercepted) {
window.navigator.sendBeacon(`https://${apiHostname}/v1/stats/${sitekey}/`, JSON.stringify(payload));
}
// POST in node
else {
api_1.statsInstance
.post(`https://${apiHostname}/v1/stats/${sitekey}/`, payload, {
headers: {
'Content-Type': 'text/plain'
}
})
.then()
.catch((err) => {
console.error(err);
});
}
};
exports.default = sendStats;
//# sourceMappingURL=stats.js.map
;