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 1 commit
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

Default search engine metric for Ghostery browser
  • Loading branch information
sammacbeth committed Nov 19, 2020
commit a35d180583e739d3da3e9408f2119b18eb170428
@@ -21,6 +21,7 @@ module.exports = {
extends: 'airbnb',
globals: {
chrome: true,
browser: true,
t: true,
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
@@ -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,12 @@ class Metrics {
this._buildQueryPair('uc', this.utm_campaign);
}

if (BROWSER_INFO.token === 'gd') {
metrics_url +=
// default search
this._buildQueryPair('ds', await Metrics._getDefaultSearchEngine());
}

return metrics_url;
}

@@ -335,10 +341,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 +674,24 @@ class Metrics {
flag = !flag;
}, FREQUENCIES.biweekly);
}

static async _getDefaultSearchEngine() {
// search API is only available in Ghostery browser where this permission is added to the manifest.
if (typeof browser !== 'undefined' && browser.search) {
// limit engines we can send to the specific set we're interested in from search choice screen
const searchEngines = {
'Ghostery Search': 'ghost',
Google: 'google',
Bing: 'bing',
StartPage: 'sp',
Yahoo: 'yahoo',
};
const engines = await browser.search.get();
const defaultSearchEngine = engines.find(s => s.isDefault).name;
return searchEngines[defaultSearchEngine] || 'other';
}
return '';
}
}

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