Skip to content

Commit d32f490

Browse files
committed
Initial commit
1 parent 1483340 commit d32f490

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/stats.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
require('es6-promise').polyfill();
4+
require('isomorphic-fetch');
5+
6+
var sendStats = function(sitekey, data) {
7+
8+
// Beacon in browsers
9+
if (typeof window !== 'undefined' && window.navigator && window.navigator.sendBeacon) {
10+
navigator.sendBeacon('https://api.addsearch.com/v1/stats/' + sitekey + '/', JSON.stringify(data));
11+
}
12+
13+
// POST in node
14+
else {
15+
fetch('https://api.addsearch.com/v1/stats/' + sitekey + '/', {
16+
method: 'POST',
17+
headers: {
18+
'Content-Type': 'text/plain',
19+
},
20+
body: JSON.stringify(data)
21+
});
22+
}
23+
};
24+
25+
module.exports = sendStats;

0 commit comments

Comments
 (0)