Skip to content

Commit

Permalink
Work around uBlock Origin privacy filters (#1694)
Browse files Browse the repository at this point in the history
* Work around uBlock Origin privacy filters

* Rewrite getMetricData

* Address review
  • Loading branch information
Iinh authored May 2, 2023
1 parent 101caaa commit 7e7a814
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
9 changes: 9 additions & 0 deletions etl/glean_etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,21 @@
# Priority for sorting app ids in the UI (of anticipated relevance to the suer)
USER_CHANNEL_PRIORITY = {"release": 1, "beta": 2, "nightly": 3, "esr": 4}

# Certain words are blocked by uBlock Origin, so we need to map them to something else
# to avoid the page being blocked
# See: https://github.com/mozilla/glean-dictionary/issues/1682
UBLOCK_ORIGIN_PRIVACY_FILTER = {"ad_impression": "advert_impression"}


def _normalize_metrics(name):
# replace . with _ so sirv doesn't think that
# a metric is a file
metric_name = name.replace(".", "_")

for key, value in UBLOCK_ORIGIN_PRIVACY_FILTER.items():
if key in metric_name:
metric_name = metric_name.replace(key, value)

# if a metric name starts with "metrics", uBlock Origin
# will block the network call to get the JSON resource
# See: https://github.com/mozilla/glean-dictionary/issues/550
Expand Down
7 changes: 7 additions & 0 deletions src/formatters/adblocker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Certain words are blocked by uBlock Origin, so we need to
// map them to something else
// See: https://github.com/mozilla/glean-dictionary/issues/1682

export const UBLOCK_ORIGIN_PRIVACY_FILTER = {
ad_impression: "advert_impression",
};
12 changes: 11 additions & 1 deletion src/state/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fetch from "node-fetch";
import { UBLOCK_ORIGIN_PRIVACY_FILTER } from "../formatters/adblocker";

export async function fetchJSON(uri) {
const res = await fetch(uri);
Expand All @@ -18,9 +19,18 @@ export async function getPingData(appName, pingName) {
}

export async function getMetricData(appName, metricName) {
let updatedMetricName = metricName;

Object.keys(UBLOCK_ORIGIN_PRIVACY_FILTER).forEach((filter) => {
updatedMetricName = updatedMetricName.replace(
filter,
UBLOCK_ORIGIN_PRIVACY_FILTER[filter]
);
});

// we added data to metric names to avoid the JSON resource
// calls being blocked by uBlock Origin
return fetchJSON(`/data/${appName}/metrics/data_${metricName}.json`);
return fetchJSON(`/data/${appName}/metrics/data_${updatedMetricName}.json`);
}

export async function getTableData(appName, appId, pingName) {
Expand Down

0 comments on commit 7e7a814

Please sign in to comment.