Bug 1089670 - Record searches in Telemetry. r=bwinton

This commit is contained in:
Georg Fritzsche 2014-10-31 21:47:13 +01:00
Родитель b897505e65
Коммит 07f67c4930
3 изменённых файлов: 83 добавлений и 1 удалений

Просмотреть файл

@ -406,6 +406,33 @@ const gSessionHistoryObserver = {
}
};
const gGatherTelemetryObserver = {
observe: function(subject, topic, data) {
if (topic != "gather-telemetry") {
return;
}
let engine;
try {
engine = Services.search.defaultEngine;
} catch (e) {}
let name;
if (!engine) {
name = "NONE";
} else if (engine.identifier) {
name = engine.identifier;
} else if (engine.name) {
name = "other-" + engine.name;
} else {
name = "UNDEFINED";
}
let engines = Services.telemetry.getKeyedHistogramById("SEARCH_DEFAULT_ENGINE");
engines.add(name, true)
},
};
/**
* Given a starting docshell and a URI to look up, find the docshell the URI
* is loaded in.
@ -1160,6 +1187,7 @@ var gBrowserInit = {
Services.obs.addObserver(gXPInstallObserver, "addon-install-blocked", false);
Services.obs.addObserver(gXPInstallObserver, "addon-install-failed", false);
Services.obs.addObserver(gXPInstallObserver, "addon-install-complete", false);
Services.obs.addObserver(gGatherTelemetryObserver, "gather-telemetry", false);
window.messageManager.addMessageListener("Browser:URIFixup", gKeywordURIFixup);
window.messageManager.addMessageListener("Browser:LoadURI", RedirectLoad);
@ -1473,6 +1501,7 @@ var gBrowserInit = {
Services.obs.removeObserver(gXPInstallObserver, "addon-install-blocked");
Services.obs.removeObserver(gXPInstallObserver, "addon-install-failed");
Services.obs.removeObserver(gXPInstallObserver, "addon-install-complete");
Services.obs.removeObserver(gGatherTelemetryObserver, "gather-telemetry");
window.messageManager.removeMessageListener("Browser:URIFixup", gKeywordURIFixup);
window.messageManager.removeMessageListener("Browser:LoadURI", RedirectLoad);
@ -3356,6 +3385,7 @@ const BrowserSearch = {
*/
recordSearchInHealthReport: function (engine, source, selection) {
BrowserUITelemetry.countSearchEvent(source, null, selection);
this.recordSearchInTelemetry(engine, source);
#ifdef MOZ_SERVICES_HEALTHREPORT
let reporter = Cc["@mozilla.org/datareporting/service;1"]
.getService()
@ -3377,6 +3407,38 @@ const BrowserSearch = {
});
#endif
},
_getSearchEngineId: function (engine) {
if (!engine) {
return "other";
}
if (engine.identifier) {
return engine.identifier;
}
return "other-" + engine.name;
},
recordSearchInTelemetry: function (engine, source) {
const SOURCES = [
"abouthome",
"contextmenu",
"newtab",
"searchbar",
"urlbar",
];
if (SOURCES.indexOf(source) == -1) {
Cu.reportError("Unknown source for search: " + source);
return;
}
let countId = this._getSearchEngineId(engine) + "." + source;
let count = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS");
count.add(countId);
},
};
function FillHistoryMenu(aParent) {

Просмотреть файл

@ -356,6 +356,15 @@ BrowserGlue.prototype = {
// nsBrowserGlue to prevent double counting.
let win = this.getMostRecentBrowserWindow();
BrowserUITelemetry.countSearchEvent("urlbar", win.gURLBar.value);
let engine = null;
try {
engine = subject.QueryInterface(Ci.nsISearchEngine);
} catch (ex) {
Cu.reportError(ex);
}
win.BrowserSearch.recordSearchInTelemetry(engine, "urlbar");
#ifdef MOZ_SERVICES_HEALTHREPORT
let reporter = Cc["@mozilla.org/datareporting/service;1"]
.getService()
@ -368,7 +377,6 @@ BrowserGlue.prototype = {
reporter.onInit().then(function record() {
try {
let engine = subject.QueryInterface(Ci.nsISearchEngine);
reporter.getProvider("org.mozilla.searches").recordSearch(engine, "urlbar");
} catch (ex) {
Cu.reportError(ex);

Просмотреть файл

@ -4493,6 +4493,18 @@
"n_values": 100,
"description": "Security UI Telemetry"
},
"SEARCH_COUNTS": {
"expires_in_version": "never",
"kind": "count",
"keyed": true,
"description": "Record the search counts for search engines that have partner agreements with Mozilla"
},
"SEARCH_DEFAULT_ENGINE": {
"expires_in_version": "never",
"kind": "flag",
"keyed": true,
"description": "Record the default search engine."
},
"SEARCH_SERVICE_INIT_MS": {
"expires_in_version": "40",
"kind": "exponential",