We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1483340 commit d32f490Copy full SHA for d32f490
src/stats.js
@@ -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