diff --git a/src/classes/Globals.js b/src/classes/Globals.js index 04dde28f3..8c7a11582 100644 --- a/src/classes/Globals.js +++ b/src/classes/Globals.js @@ -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; } }); } diff --git a/src/classes/Metrics.js b/src/classes/Metrics.js index d28c8a5c3..e1138af4f 100644 --- a/src/classes/Metrics.js +++ b/src/classes/Metrics.js @@ -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