Skip to content

Commit 5e95cdf

Browse files
committed
Track only servers with domain, no local developments
1 parent ee53f77 commit 5e95cdf

File tree

6 files changed

+33
-36
lines changed

6 files changed

+33
-36
lines changed

api/api.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ else {
3939
process.title = t.join(' ');
4040

4141
plugins.connectToAllDatabases().then(function() {
42-
tracker.enable();
42+
plugins.loadConfigs(common.db, function() {
43+
tracker.enable();
44+
});
4345
common.writeBatcher = new WriteBatcher(common.db);
4446
common.readBatcher = new ReadBatcher(common.db);
4547
common.insertBatcher = new InsertBatcher(common.db);

api/jobs/ping.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class PingJob extends job.Job {
1717
if (!offlineMode) {
1818
var server = tracker.getBulkServer();
1919
var user = tracker.getBulkUser(server);
20+
if (!user) {
21+
return done();
22+
}
2023
var days = 90;
2124
var current_sync = Date.now();
2225

api/parts/mgmt/tracker.js

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ var tracker = {},
1616
server = "9c28c347849f2c03caf1b091ec7be8def435e85e",
1717
user = "fa6e9ae7b410cb6d756e8088c5f3936bf1fab5f3",
1818
url = "https://stats.count.ly",
19-
plugins = require('../../../plugins/pluginManager.js'),
20-
domain = plugins.getConfig("api").domain;
19+
plugins = require('../../../plugins/pluginManager.js');
2120

2221
var IS_FLEX = false;
2322

@@ -51,26 +50,28 @@ tracker.enable = function() {
5150
storage_path: "../../../.sdk/",
5251
interval: 10000,
5352
fail_timeout: 600,
54-
session_update: 120,
53+
session_update: 60 * 60 * 12,
5554
remote_config: true,
5655
debug: (logger.getLevel("tracker:server") === "debug")
5756
};
57+
58+
var domain = plugins.getConfig("api").domain;
59+
5860
//set static device id if domain is defined
5961
if (domain) {
6062
config.device_id = stripTrailingSlash((domain + "").split("://").pop());
6163
}
62-
Countly.init(config);
6364

64-
//change device id if is it not domain
65-
if (domain && Countly.get_device_id() !== domain) {
66-
Countly.change_id(stripTrailingSlash((domain + "").split("://").pop()), true);
67-
}
68-
else if (!domain) {
69-
checkDomain();
70-
}
71-
isEnabled = true;
72-
Countly.user_details({"name": config.device_id });
73-
plugins.loadConfigs(common.db, function() {
65+
if (config.device_id && config.device_id !== "localhost") {
66+
Countly.init(config);
67+
68+
//change device id if is it not domain
69+
if (Countly.get_device_id() !== domain) {
70+
Countly.change_id(stripTrailingSlash((domain + "").split("://").pop()), true);
71+
}
72+
73+
isEnabled = true;
74+
Countly.user_details({"name": config.device_id });
7475
if (plugins.getConfig("tracking").server_sessions) {
7576
Countly.begin_session(true);
7677
}
@@ -83,7 +84,7 @@ tracker.enable = function() {
8384
}
8485
collectServerData();
8586
}, 20000);
86-
});
87+
}
8788
};
8889

8990
/**
@@ -103,7 +104,10 @@ tracker.getBulkServer = function() {
103104
* @returns {Object} Countly Bulk User instance
104105
*/
105106
tracker.getBulkUser = function(serverInstance) {
106-
return serverInstance.add_user({device_id: stripTrailingSlash((plugins.getConfig("api").domain + "").split("://").pop())});
107+
var domain = stripTrailingSlash((plugins.getConfig("api").domain + "").split("://").pop());
108+
if (domain && domain !== "localhost") {
109+
return serverInstance.add_user({device_id: domain});
110+
}
107111
};
108112

109113
/**
@@ -224,20 +228,4 @@ function stripTrailingSlash(str) {
224228
return str;
225229
}
226230

227-
//check every hour if domain was provided
228-
var checkDomain = function() {
229-
if (!domain && domain !== plugins.getConfig("api").domain) {
230-
domain = plugins.getConfig("api").domain;
231-
if (Countly && isEnabled) {
232-
Countly.change_id(stripTrailingSlash((domain + "").split("://").pop()), true);
233-
Countly.userData.set("domain", domain);
234-
Countly.user_details({"name": stripTrailingSlash((domain + "").split("://").pop())});
235-
Countly.userData.save();
236-
}
237-
}
238-
else if (!domain) {
239-
setTimeout(checkDomain, 3600000);
240-
}
241-
};
242-
243231
module.exports = tracker;

frontend/express/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
414414
};
415415

416416
plugins.loadConfigs(countlyDb, function() {
417+
tracker.enable();
417418
curTheme = plugins.getConfig("frontend").theme;
418419
app.loadThemeFiles(curTheme);
419420
app.dashboard_headers = plugins.getConfig("security").dashboard_additional_headers;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ class StatsJob extends job.Job {
154154

155155
var server = tracker.getBulkServer();
156156
var user = tracker.getBulkUser(server);
157+
if (!user) {
158+
return done();
159+
}
157160
var days = 30;
158161
var current_sync = Date.now();
159162

plugins/system-utility/api/api.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var plugin = {},
22
common = require('../../../api/utils/common.js'),
3-
tracker = require('../../../api/parts/mgmt/tracker.js'),
3+
//tracker = require('../../../api/parts/mgmt/tracker.js'),
44
plugins = require('../../pluginManager.js'),
55
systemUtility = require('./system.utility'),
66
log = common.log('system-utility:api'),
@@ -261,7 +261,7 @@ function stopWithTimeout(type, fromTimeout = false) {
261261

262262
});
263263

264-
plugins.register("/master", function() {
264+
/*plugins.register("/master", function() {
265265
//ping server stats periodically
266266
if (tracker.isEnabled()) {
267267
var timeout = 1000 * 60 * 15;
@@ -326,7 +326,7 @@ function stopWithTimeout(type, fromTimeout = false) {
326326
};
327327
getServerStats();
328328
}
329-
});
329+
});*/
330330
}(plugin));
331331

332332
module.exports = plugin;

0 commit comments

Comments
 (0)