Skip to content

Commit

Permalink
Fix missing telemetry fields (#1863)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmod authored Sep 6, 2024
1 parent 61ef429 commit e156c7e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 15 deletions.
19 changes: 16 additions & 3 deletions extension-manifest-v3/src/background/telemetry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,28 @@ const loadStorage = async () => {
return storage;
};

const getConf = async () => {
const getConf = async (storage) => {
const options = await store.resolve(Options);

// Historically install_data was stored in Options.
// As it is used by telemetry only, it is here migrated
// to telemetry storage.
// TODO: cleanup Options after September 2024
if (!storage.installDate) {
saveStorage(storage, {
installDate:
options.installDate || new Date().toISOString().split('T')[0],
installRandom: Math.floor(Math.random() * 100) + 1,
});
}

return {
enable_ad_block: options.blockAds,
enable_anti_tracking: options.blockTrackers,
enable_smart_block: options.blockAnnoyances,
enable_human_web: options.terms,
install_date: options.installDate,
installDate: storage.installDate,
installRandom: storage.installRandom,
setup_complete: options.onboarding.done && options.terms,
setup_skip: options.onboarding.done && !options.terms,
setup_timestamp: options.onboarding.shownAt,
Expand All @@ -84,7 +97,7 @@ chrome.runtime.onMessage.addListener((msg) => {
? 'https://staging-d.ghostery.com'
: 'https://d.ghostery.com',
EXTENSION_VERSION: version,
getConf,
getConf: () => getConf(storage),
log,
storage,
saveStorage: (metrics) => {
Expand Down
43 changes: 43 additions & 0 deletions extension-manifest-v3/src/background/telemetry/language.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Ghostery Browser Extension
* https://www.ghostery.com/
*
* Copyright 2017-present Ghostery GmbH. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0
*/

const SUPPORTED_LANGUAGES = new Set([
'de',
'en',
'es',
'fr',
'hu',
'it',
'ja',
'ko',
'nl',
'pl',
'pt_BR',
'ru',
'zh_CN',
'zh_TW',
]);

export default function getDefaultLanguage() {
let lang = navigator.language.replace('-', '_');

if (SUPPORTED_LANGUAGES.has(lang)) {
return lang;
}

lang = lang.slice(0, 2);

if (SUPPORTED_LANGUAGES.has(lang)) {
return lang;
}

return 'en';
}
7 changes: 4 additions & 3 deletions extension-manifest-v3/src/background/telemetry/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0
*/

import getDefaultLanguage from './language.js';
import getBrowserInfo from '/utils/browser-info.js';

/**
Expand Down Expand Up @@ -260,11 +261,11 @@ class Metrics {
// Operating system
buildQueryPair('os', browserInfo.os) +
// Browser language
buildQueryPair('l', conf.language) +
buildQueryPair('l', getDefaultLanguage()) +
// Browser version
buildQueryPair('bv', browserInfo.version) +
// Date of install (former install_date)
buildQueryPair('id', conf.install_date) +
buildQueryPair('id', conf.installDate) +
// Showing campaign messages (former show_cmp)
buildQueryPair('sc', conf.show_cmp ? '1' : '0') +
// Subscription Type
Expand All @@ -282,7 +283,7 @@ class Metrics {
buildQueryPair('hw', conf.enable_human_web ? '1' : '0') +
// Old parameters, new names
// Random number, assigned at install (former install_rand)
buildQueryPair('ir', conf.install_random_number) +
buildQueryPair('ir', conf.installRandom) +
// Login state (former signed_in)
buildQueryPair('sn', conf.account ? '1' : '0') +
// Noncritical ping (former noncritical)
Expand Down
9 changes: 0 additions & 9 deletions extension-manifest-v3/src/pages/onboarding/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ mount(document.body, {
});

store.resolve(Options).then(({ installDate, onboarding }) => {
// Get install date from `onboarding.shownAt` or generate current date
if (!installDate) {
installDate = (
onboarding.shownAt ? new Date(onboarding.shownAt) : new Date()
)
.toISOString()
.split('T')[0];
}

store.set(Options, {
onboarding: {
shownAt: Date.now(),
Expand Down

0 comments on commit e156c7e

Please sign in to comment.