зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1577030 - Telemetry to track total numbers of trackers blocked. r=johannh
Differential Revision: https://phabricator.services.mozilla.com/D44521 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
2742e32812
Коммит
270e03dff6
|
@ -3,6 +3,40 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this,
|
||||
"TrackingDBService",
|
||||
"@mozilla.org/tracking-db-service;1",
|
||||
"nsITrackingDBService"
|
||||
);
|
||||
|
||||
const LOG = {
|
||||
"https://1.example.com": [
|
||||
[Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT, true, 1],
|
||||
],
|
||||
"https://2.example.com": [
|
||||
[Ci.nsIWebProgressListener.STATE_BLOCKED_FINGERPRINTING_CONTENT, true, 1],
|
||||
],
|
||||
"https://3.example.com": [
|
||||
[Ci.nsIWebProgressListener.STATE_BLOCKED_CRYPTOMINING_CONTENT, true, 2],
|
||||
],
|
||||
"https://4.example.com": [
|
||||
[Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER, true, 3],
|
||||
],
|
||||
"https://5.example.com": [
|
||||
[Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER, true, 1],
|
||||
],
|
||||
// Cookie blocked for other reason, then identified as a tracker
|
||||
"https://6.example.com": [
|
||||
[
|
||||
Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_ALL |
|
||||
Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT,
|
||||
true,
|
||||
4,
|
||||
],
|
||||
],
|
||||
};
|
||||
|
||||
requestLongerTimeout(2);
|
||||
|
||||
add_task(async function setup() {
|
||||
|
@ -409,3 +443,18 @@ add_task(async function checkTelemetryClickEvents() {
|
|||
await BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
await BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
});
|
||||
|
||||
// This tests that telemetry is sent when saveEvents is called.
|
||||
add_task(async function test_save_telemetry() {
|
||||
// Clear all scalar telemetry.
|
||||
Services.telemetry.clearScalars();
|
||||
|
||||
await TrackingDBService.saveEvents(JSON.stringify(LOG));
|
||||
|
||||
const scalars = Services.telemetry.getSnapshotForScalars("main", false)
|
||||
.parent;
|
||||
is(scalars["contentblocking.trackers_blocked_count"], 6);
|
||||
|
||||
// Use the TrackingDBService API to delete the data.
|
||||
await TrackingDBService.clearAll();
|
||||
});
|
||||
|
|
|
@ -12,8 +12,10 @@ const { Sqlite } = ChromeUtils.import("resource://gre/modules/Sqlite.jsm");
|
|||
const { requestIdleCallback } = ChromeUtils.import(
|
||||
"resource://gre/modules/Timer.jsm"
|
||||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const SCHEMA_VERSION = 1;
|
||||
const TRACKERS_BLOCKED_COUNT = "contentblocking.trackers_blocked_count";
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "DB_PATH", function() {
|
||||
return OS.Path.join(OS.Constants.Path.profileDir, "protections.sqlite");
|
||||
|
@ -227,6 +229,9 @@ TrackingDBService.prototype = {
|
|||
// cookie which is not a tracking cookie. These should not be added to the database.
|
||||
let type = this.identifyType(log[thirdParty]);
|
||||
if (type) {
|
||||
// Send the blocked event to Telemetry
|
||||
Services.telemetry.scalarAdd(TRACKERS_BLOCKED_COUNT, 1);
|
||||
|
||||
// today is a date "YYY-MM-DD" which can compare with what is
|
||||
// already saved in the database.
|
||||
let today = new Date().toISOString().split("T")[0];
|
||||
|
|
|
@ -677,6 +677,21 @@ contentblocking:
|
|||
- 'geckoview'
|
||||
record_in_processes:
|
||||
- main
|
||||
trackers_blocked_count:
|
||||
bug_numbers:
|
||||
- 1577030
|
||||
description: >
|
||||
A count of the number of tracking events blocked.
|
||||
expires: "75"
|
||||
kind: uint
|
||||
notification_emails:
|
||||
- chsiang@mozilla.com
|
||||
- seceng-telemetry@mozilla.com
|
||||
release_channel_collection: opt-out
|
||||
products:
|
||||
- 'firefox'
|
||||
record_in_processes:
|
||||
- main
|
||||
|
||||
sandbox:
|
||||
no_job:
|
||||
|
|
Загрузка…
Ссылка в новой задаче