Skip to content

Commit ddee60b

Browse files
committed
Add brokenSiteReport metric
1 parent 11e079a commit ddee60b

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

shared/js/background/background.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import RemoteConfig from './components/remote-config';
3232
import initDebugBuild from './devbuild';
3333
import initReloader from './devbuild-reloader';
3434
import tabManager from './tab-manager';
35-
import AbnExperimentMetrics, { AppUseMetric, SearchMetric } from './components/abn-experiments';
35+
import AbnExperimentMetrics, { AppUseMetric, PixelMetric, SearchMetric } from './components/abn-experiments';
3636
// NOTE: this needs to be the first thing that's require()d when the extension loads.
3737
// otherwise FF might miss the onInstalled event
3838
require('./events');
@@ -78,7 +78,7 @@ const components = {
7878
if (BUILD_TARGET === 'chrome' || BUILD_TARGET === 'chrome-mv2') {
7979
const abnMetrics = new AbnExperimentMetrics({ remoteConfig });
8080
components.abnMetrics = abnMetrics;
81-
components.metrics = [new AppUseMetric({ abnMetrics }), new SearchMetric({ abnMetrics })];
81+
components.metrics = [new AppUseMetric({ abnMetrics }), new SearchMetric({ abnMetrics }), new PixelMetric({ abnMetrics })];
8282
components.fireButton = new FireButton({ settings, tabManager });
8383
}
8484
// MV3-only components

shared/js/background/components/abn-experiments.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,32 @@ export class SearchMetric {
8484
}
8585
}
8686

87+
export class PixelMetric {
88+
/**
89+
* Metric that observes outgoing pixel calls and routes a subset of them as experiment metrics.
90+
* Currently intercepts `epbf` pixels and triggers a `brokenSiteReport` metric.
91+
* @param {{
92+
* abnMetrics: AbnExperimentMetrics
93+
* }} opts
94+
*/
95+
constructor({ abnMetrics }) {
96+
browser.webRequest.onCompleted.addListener(
97+
async (details) => {
98+
await abnMetrics.remoteConfig.ready;
99+
const url = new URL(details.url);
100+
if (url.pathname.startsWith('/t/epbf_')) {
101+
// broken site report
102+
abnMetrics.onMetricTriggered('brokenSiteReport');
103+
}
104+
},
105+
{
106+
urls: ['https://improving.duckduckgo.com/t/*'],
107+
tabId: -1,
108+
},
109+
);
110+
}
111+
}
112+
87113
export default class AbnExperimentMetrics {
88114
/**
89115
*
@@ -123,7 +149,6 @@ export default class AbnExperimentMetrics {
123149
* @param {number} [timestamp]
124150
*/
125151
async onMetricTriggered(metric, value = 1, timestamp) {
126-
console.log('xxx metric triggered:', metric);
127152
this.remoteConfig
128153
.getSubFeatureStatuses()
129154
.filter((status) => status.hasCohorts && status.cohort && status.cohort.enrolledAt)

0 commit comments

Comments
 (0)