Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop browser telemetry #633

Merged
merged 5 commits into from Nov 30, 2020
Merged
Changes from all commits
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -194,12 +194,13 @@ class Globals {
this.BROWSER_INFO.name = 'ghostery_android';
this.BROWSER_INFO.token = 'ga';
this.BROWSER_INFO.os = 'android';
this.BROWSER_INFO.version = info.version;
} else {
this.BROWSER_INFO.displayName = 'Ghostery Desktop Browser';
this.BROWSER_INFO.name = 'ghostery_desktop';
this.BROWSER_INFO.token = 'gd';
this.BROWSER_INFO.version = info.version.split('.').join('');
}
this.BROWSER_INFO.version = info.version;
}
});
}
@@ -190,9 +190,9 @@ class Metrics {
* Set uninstall url
* @param {string} conf key being changed
*/
setUninstallUrl(key) {
async setUninstallUrl(key) {
if (typeof chrome.runtime.setUninstallURL === 'function' && (!key || METRICS_URL_SET.has(key))) {
const metrics_url = this._buildMetricsUrl('uninstall');
const metrics_url = await this._buildMetricsUrl('uninstall');
if (metrics_url.length) {
chrome.runtime.setUninstallURL(metrics_url);
}
@@ -220,7 +220,7 @@ class Metrics {
* @param {string} frequency ping frequency
* @return {string} complete telemetry url
*/
_buildMetricsUrl(type, frequency) {
async _buildMetricsUrl(type, frequency) {
const frequencyString = (type !== 'uninstall') ? `/${frequency}` : '';

let metrics_url = `${METRICS_BASE_URL}/${type}${frequencyString}?gr=-1`;
@@ -309,6 +309,14 @@ class Metrics {
this._buildQueryPair('uc', this.utm_campaign);
}

if (BROWSER_INFO.token === 'gd') {
// fetch metrics from the search extension and append them
const searchMetrics = await Metrics._getSearchExtensionMetrics();
Object.keys(searchMetrics).forEach((k) => {
metrics_url += this._buildQueryPair(k, searchMetrics[k]);
});
}

return metrics_url;
}

@@ -335,10 +343,10 @@ class Metrics {
};
}

frequencies.forEach((frequency) => {
frequencies.forEach(async(frequency) => {
if (this._checkPing(type, frequency)) {
const timeNow = Number((new Date()).getTime());
const metrics_url = this._buildMetricsUrl(type, frequency);
const metrics_url = await this._buildMetricsUrl(type, frequency);
// update Conf timestamps for each ping type and frequency
const metrics = conf.metrics || {};
metrics[`${type}_${frequency}`] = timeNow;
@@ -668,6 +676,14 @@ class Metrics {
flag = !flag;
}, FREQUENCIES.biweekly);
}

static async _getSearchExtensionMetrics() {
return new Promise((resolve) => {
chrome.runtime.sendMessage('search@ghostery.com', 'getMetrics', (response) => {
resolve(response || {});
});
});
}
}

// return the class as a singleton
ProTip! Use n and p to navigate between commits in a pull request.