From 1a4bdd1461c9900e9e49fbb1dd62a2a23a3546fa Mon Sep 17 00:00:00 2001 From: Justin Grevich Date: Sun, 25 Oct 2015 16:17:22 -0700 Subject: [PATCH] Add User-Agent header to post request This adds the User-Agent header ('slackalytics.js') to the post request as per: https://developers.google.com/analytics/devguides/collection/protocol/v1/reference#using-post --- app.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index e081e7a..a6e0cea 100644 --- a/app.js +++ b/app.js @@ -88,11 +88,18 @@ app.post('/collect', function(req, res){ }; console.log(JSON.stringify(data)); console.log(req.body); - //Make Post Request - request.post("https://www.google-analytics.com/collect?" + qs.stringify(data), - function(error, resp, body){ - console.log(error); - }) + //Make Post Request + + var request_options = { + url: 'https://www.google-analytics.com/collect?' + qs.stringify(data), + headers: { 'User-Agent': 'slackalytics.js' } + } + + function request_callback(error, resp, body) { + if (error) { console.log(error); } + } + + request.post(request_options, request_callback) res.send("OK") });