Skip to content

Commit

Permalink
Merge pull request #34 from appcelerator/timob-12771
Browse files Browse the repository at this point in the history
[TIMOB-12771] Fixed analytics to only send payload when logged in.
  • Loading branch information
nebrius committed Mar 4, 2013
2 parents bf592ae + b5ade1a commit 10ac8f8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Updated auth library to use request module instead of node.js built-in request functions. [TIMOB-12423]
* Fixed analytics library to set the uid cookie and not pass in the app_id. [TIMOB-12653]
* Fixed bug with the Android detection library failing to call 'android list' on Windows [TIMOB-12764]
* Fixed analytics to only send payload when logged in. [TIMOB-12771]

0.1.27 (1/22/2013)
-------------------
Expand Down
49 changes: 26 additions & 23 deletions lib/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,29 +176,32 @@ process.on('message', function(m) {

// console.log(payload);

var status = auth.status(),
sessionCookie = status.cookie.match(/(PHPSESSID=[A-Za-z0-9]+)/),
cookie = (sessionCookie ? sessionCookie[1] + ';' : '') + 'uid=' + status.guid; // no, this is not a bug... it really is called uid and expects the guid

async.series(payload.map(function (data) {
return function (callback) {
request({
uri: url,
method: 'POST',
proxy: m.httpProxyServer || undefined,
headers: {
Cookie: cookie
},
body: urlEncode(data)
}, function (error, response, body) {
// Return the index if it failed and it needs to be written to the logfile again
if (error || response.statusCode != 204) {
payloadRetry.push(data);
}
callback();
});
};
}), save);
var status = auth.status();

if (status.loggedIn && status.guid) {
var sessionCookie = status.cookie && status.cookie.match(/(PHPSESSID=[A-Za-z0-9]+)/),
cookie = (sessionCookie ? sessionCookie[1] + ';' : '') + 'uid=' + status.guid; // no, this is not a bug... it really is called uid and expects the guid

async.series(payload.map(function (data) {
return function (callback) {
request({
uri: url,
method: 'POST',
proxy: m.httpProxyServer || undefined,
headers: {
Cookie: cookie
},
body: urlEncode(data)
}, function (error, response, body) {
// Return the index if it failed and it needs to be written to the logfile again
if (error || response.statusCode != 204) {
payloadRetry.push(data);
}
callback();
});
};
}), save);
}
} else {
save();
}
Expand Down

0 comments on commit 10ac8f8

Please sign in to comment.