Skip to content

Commit 13360e4

Browse files
Merge pull request #4798 from Countly/tracker
[SER-1044] Tracker fixes
2 parents 5e7a576 + eafd267 commit 13360e4

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

api/parts/mgmt/tracker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ var tracker = {},
1919
fs = require('fs'),
2020
asyncjs = require('async'),
2121
trial = "79199134e635edb05fc137e8cd202bb8640fb0eb",
22-
server = "e0693b48a5513cb60c112c21aede3cab809d52d0",
2322
app = "e70ec21cbe19e799472dfaee0adb9223516d238f",
23+
server = app,
2424
url = "https://stats.count.ly",
2525
plugins = require('../../../plugins/pluginManager.js'),
2626
offlineMode = plugins.getConfig("api").offline_mode,

plugins/server-stats/api/jobs/stats.js

+37-15
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@ const job = require('../../../../api/parts/jobs/job.js'),
44
tracker = require('../../../../api/parts/mgmt/tracker.js'),
55
log = require('../../../../api/utils/log.js')('job:stats'),
66
config = require("../../../../frontend/express/config.js"),
7+
pluginManager = require('../../../pluginManager.js'),
78
moment = require('moment-timezone'),
89
request = require('countly-request');
910

11+
const promisedLoadConfigs = function(db) {
12+
return new Promise((resolve) => {
13+
pluginManager.loadConfigs(db, () => {
14+
resolve();
15+
});
16+
});
17+
};
18+
1019
/** Representing a StatsJob. Inherits api/parts/jobs/job.js (job.Job) */
1120
class StatsJob extends job.Job {
1221
/**
@@ -36,7 +45,7 @@ class StatsJob extends job.Job {
3645
s: { $sum: "$s"}
3746
}
3847
}
39-
], { allowDiskUse: true }, function(error, allData) {
48+
], { allowDiskUse: true }, async function(error, allData) {
4049
if (!error) {
4150
var data = {};
4251
data.all = 0;
@@ -56,21 +65,34 @@ class StatsJob extends job.Job {
5665
data.avg = Math.round((data.all / allData.length) * 100) / 100;
5766
var date = new Date();
5867
var usersData = [];
59-
members.forEach((member) => {
60-
usersData.push({
61-
device_id: member.email,
62-
timestamp: Math.floor(date.getTime() / 1000),
63-
hour: date.getHours(),
64-
dow: date.getDay(),
65-
user_details: JSON.stringify({
66-
custom: {
67-
dataPointsAll: data.all,
68-
dataPointsMonthlyAvg: data.avg,
69-
dataPointsLast3Months: data.month3
70-
}
71-
})
72-
});
68+
69+
await promisedLoadConfigs(db);
70+
71+
let domain = '';
72+
73+
try {
74+
// try to extract hostname from full domain url
75+
const urlObj = new URL(pluginManager.getConfig('api').domain);
76+
domain = urlObj.hostname;
77+
}
78+
catch (_) {
79+
// do nothing, domain from config will be used as is
80+
}
81+
82+
usersData.push({
83+
device_id: domain,
84+
timestamp: Math.floor(date.getTime() / 1000),
85+
hour: date.getHours(),
86+
dow: date.getDay(),
87+
user_details: JSON.stringify({
88+
custom: {
89+
dataPointsAll: data.all,
90+
dataPointsMonthlyAvg: data.avg,
91+
dataPointsLast3Months: data.month3
92+
}
93+
})
7394
});
95+
7496
var formData = {
7597
app_key: "e70ec21cbe19e799472dfaee0adb9223516d238f",
7698
requests: JSON.stringify(usersData)

0 commit comments

Comments
 (0)