mirror of
https://github.com/hardillb/node-red-alexa-home-skill-web.git
synced 2025-12-11 09:29:44 +01:00
This adds: - google analytics to the command handling - the start of support for the new temperature queries - fixes the oauth token refresh code - reuses still active oauth tokens
48 lines
992 B
JavaScript
48 lines
992 B
JavaScript
var request = require('request');
|
|
var querystring = require('querystring');
|
|
|
|
var baseURL = "https://www.google-analytics.com/";
|
|
|
|
var Measurements = function(tid) {
|
|
this.tid = tid;
|
|
};
|
|
|
|
Measurements.prototype.send = function(options) {
|
|
|
|
if (!this.tid){
|
|
return;
|
|
}
|
|
var required = {
|
|
v: 1,
|
|
tid: this.tid,
|
|
t: 'event'
|
|
};
|
|
var url = baseURL;
|
|
var body;
|
|
if (Array.isArray(options)) {
|
|
for (var i=0; i<options.length && i < 20; i++) {
|
|
var temp = Object.assign(required, options[i]);
|
|
body += querystring.stringify(temp);
|
|
body += "\n";
|
|
}
|
|
|
|
url += "batch";
|
|
} else {
|
|
options = Object.assign(required, options);
|
|
body = querystring.stringify(options);
|
|
url += "collect";
|
|
}
|
|
// console.log(body);
|
|
request.post({url: url, body: body},
|
|
function(err, response, body){
|
|
if (err) {
|
|
console.log(err);
|
|
}
|
|
|
|
// console.log("Analytics response: %d",response.statusCode);
|
|
// console.log(response.headers);
|
|
// console.log(body);
|
|
});
|
|
}
|
|
|
|
module.exports = Measurements; |