Skip to content

Commit ea52492

Browse files
Remove superfluous Glean metrics (#14690)
* Remove superfluous Glean metrics * Update tests/unit/spec/glean/utils.js Co-authored-by: Jan Brasna <[email protected]> * Update tests/unit/spec/glean/utils.js Co-authored-by: Jan Brasna <[email protected]> --------- Co-authored-by: Jan Brasna <[email protected]>
1 parent 586a89a commit ea52492

File tree

6 files changed

+23
-454
lines changed

6 files changed

+23
-454
lines changed

bedrock/base/templates/404.html

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
{% block gtm_page_id %}data-gtm-page-id="404"{% endblock %}
1010

11-
{% block html_attrs %}data-http-status="404"{% endblock %}
12-
1311
{% block page_title %}{{ ftl('not-found-page-not-found-page-page-not-found') }}{% endblock %}
1412

1513
{% block page_css %}

glean/metrics.yaml

-106
Original file line numberDiff line numberDiff line change
@@ -2,112 +2,6 @@
22
$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0
33

44
page:
5-
viewed:
6-
type: datetime
7-
lifetime: application
8-
send_in_pings:
9-
- events
10-
description: |
11-
The time a page was viewed.
12-
data_sensitivity:
13-
- web_activity
14-
bugs:
15-
- https://github.com/mozilla/bedrock/issues/10746
16-
data_reviews:
17-
- https://bugzilla.mozilla.org/show_bug.cgi?id=1767442
18-
notification_emails:
19-
20-
expires: never
21-
path:
22-
type: string
23-
lifetime: application
24-
send_in_pings:
25-
- events
26-
description: |
27-
The URL path of the page that was viewed, excluding locale.
28-
data_sensitivity:
29-
- web_activity
30-
bugs:
31-
- https://github.com/mozilla/bedrock/issues/10746
32-
data_reviews:
33-
- https://bugzilla.mozilla.org/show_bug.cgi?id=1767442
34-
notification_emails:
35-
36-
expires: never
37-
locale:
38-
type: string
39-
lifetime: application
40-
send_in_pings:
41-
- events
42-
description: |
43-
The locale of the page that was viewed.
44-
data_sensitivity:
45-
- web_activity
46-
bugs:
47-
- https://github.com/mozilla/bedrock/issues/10746
48-
data_reviews:
49-
- https://bugzilla.mozilla.org/show_bug.cgi?id=1767442
50-
notification_emails:
51-
52-
expires: never
53-
query_params:
54-
type: labeled_string
55-
lifetime: application
56-
send_in_pings:
57-
- events
58-
description: |
59-
Query parameters associated with the URL of
60-
the page that was viewed.
61-
bugs:
62-
- https://github.com/mozilla/bedrock/issues/10746
63-
data_reviews:
64-
- https://bugzilla.mozilla.org/show_bug.cgi?id=1767442
65-
notification_emails:
66-
67-
expires: never
68-
labels:
69-
- utm_source
70-
- utm_campaign
71-
- utm_medium
72-
- utm_content
73-
- entrypoint_experiment
74-
- entrypoint_variation
75-
- experiment
76-
- variation
77-
- v
78-
- xv
79-
referrer:
80-
type: string
81-
lifetime: application
82-
send_in_pings:
83-
- events
84-
description: |
85-
The referring URL that linked to the page that was viewed.
86-
data_sensitivity:
87-
- web_activity
88-
bugs:
89-
- https://github.com/mozilla/bedrock/issues/10746
90-
data_reviews:
91-
- https://bugzilla.mozilla.org/show_bug.cgi?id=1767442
92-
notification_emails:
93-
94-
expires: never
95-
http_status:
96-
type: string
97-
description: |
98-
The HTTP status code of the page.
99-
lifetime: application
100-
send_in_pings:
101-
- events
102-
data_sensitivity:
103-
- technical
104-
bugs:
105-
- https://github.com/mozilla/bedrock/issues/13581
106-
data_reviews:
107-
- https://bugzilla.mozilla.org/show_bug.cgi?id=1848981
108-
notification_emails:
109-
110-
expires: never
1115
interaction:
1126
type: event
1137
description: |

media/js/glean/page.es6.js

+1-44
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,6 @@
55
*/
66

77
import * as page from '../libs/glean/page.js';
8-
import Utils from './utils.es6';
9-
10-
const defaultParams = {
11-
utm_source: '',
12-
utm_campaign: '',
13-
utm_medium: '',
14-
utm_content: '',
15-
entrypoint_experiment: '',
16-
entrypoint_variation: '',
17-
experiment: '',
18-
variation: '',
19-
v: '', // short param for 'variation'
20-
xv: '' // short param for 'experience version'.
21-
};
22-
23-
function recordCustomPageMetrics() {
24-
page.viewed.set();
25-
page.path.set(Utils.getPathFromUrl());
26-
page.locale.set(Utils.getLocaleFromUrl());
27-
page.referrer.set(Utils.getReferrer());
28-
page.httpStatus.set(Utils.getHttpStatus());
29-
30-
const params = Utils.getQueryParamsFromUrl();
31-
const finalParams = {};
32-
33-
// validate only known & trusted query params
34-
// for inclusion in Glean metrics.
35-
for (const param in defaultParams) {
36-
if (Object.prototype.hasOwnProperty.call(defaultParams, param)) {
37-
const allowedChars = /^[\w/.%-]+$/;
38-
let v = params.get(param);
39-
40-
if (v) {
41-
v = decodeURIComponent(v);
42-
finalParams[param] = allowedChars.test(v) ? v : '';
43-
} else {
44-
finalParams[param] = '';
45-
}
46-
47-
page.queryParams[param].set(finalParams[param]);
48-
}
49-
}
50-
}
518

529
function pageEvent(obj) {
5310
if (typeof obj !== 'object' && typeof obj.label !== 'string') {
@@ -77,4 +34,4 @@ function pageEvent(obj) {
7734
}
7835
}
7936

80-
export { recordCustomPageMetrics, pageEvent };
37+
export { pageEvent };

media/js/glean/utils.es6.js

+11-66
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@
66

77
import Glean from '@mozilla/glean/web';
88
import GleanMetrics from '@mozilla/glean/metrics';
9-
import { pageEvent, recordCustomPageMetrics } from './page.es6';
9+
import { pageEvent } from './page.es6';
1010
import {
1111
consentRequired,
1212
getConsentCookie,
1313
isFirefoxDownloadThanks
1414
} from '../base/consent/utils.es6';
1515

1616
const Utils = {
17-
filterNewsletterURL: (str) => {
17+
/**
18+
* Takes a URL string and filters out any sensitive information,
19+
* such as newsletter tokens, before returning the URL.
20+
* See issue https://github.com/mozilla/bedrock/issues/13583
21+
* @param {String} URL
22+
* @returns {String} filtered URL
23+
*/
24+
filterURL: (str) => {
1825
try {
1926
const url = new URL(str);
20-
21-
// Ensure we don't include tokens in newsletter page load event pings
22-
// Issue https://github.com/mozilla/bedrock/issues/13583
2327
const newsletterPaths = [
2428
'/newsletter/existing/',
2529
'/newsletter/country/'
@@ -45,63 +49,6 @@ const Utils = {
4549
}
4650
},
4751

48-
getUrl: (str) => {
49-
const url = typeof str === 'string' ? str : window.location.href;
50-
return Utils.filterNewsletterURL(url);
51-
},
52-
53-
getPathFromUrl: (str) => {
54-
let pathName =
55-
typeof str === 'string' ? str : document.location.pathname;
56-
pathName = pathName.replace(/^(\/\w{2}-\w{2}\/|\/\w{2,3}\/)/, '/');
57-
const newsletterPaths = [
58-
'/newsletter/existing/',
59-
'/newsletter/country/'
60-
];
61-
62-
// Ensure we don't include tokens in newsletter page pings
63-
// Issue https://github.com/mozilla/bedrock/issues/13583
64-
newsletterPaths.forEach((path) => {
65-
if (pathName.includes(path)) {
66-
pathName = path;
67-
}
68-
});
69-
70-
return pathName;
71-
},
72-
73-
getLocaleFromUrl: (str) => {
74-
const pathName =
75-
typeof str === 'string' ? str : document.location.pathname;
76-
const locale = pathName.match(/^\/(\w{2}-\w{2}|\w{2,3})\//);
77-
// If there's no locale in the path then assume language is `en-US`;
78-
return locale && locale.length > 0 ? locale[1] : 'en-US';
79-
},
80-
81-
getQueryParamsFromUrl: (str) => {
82-
const query = typeof str === 'string' ? str : window.location.search;
83-
84-
if (typeof window._SearchParams !== 'undefined') {
85-
return new window._SearchParams(query);
86-
}
87-
88-
return false;
89-
},
90-
91-
getReferrer: (str) => {
92-
const referrer = typeof str === 'string' ? str : document.referrer;
93-
const url = Utils.filterNewsletterURL(referrer);
94-
95-
return url;
96-
},
97-
98-
getHttpStatus: () => {
99-
const pageId = document
100-
.getElementsByTagName('html')[0]
101-
.getAttribute('data-http-status');
102-
return pageId && pageId === '404' ? '404' : '200';
103-
},
104-
10552
/**
10653
* Determine if page URL is /firefox/download/thanks/.
10754
*/
@@ -137,17 +84,15 @@ const Utils = {
13784
* Record page load event and add custom metrics.
13885
*/
13986
initPageLoadEvent: () => {
140-
recordCustomPageMetrics();
141-
14287
/**
14388
* Manually call Glean's default page_load event. Here
14489
* we override `url` and `referrer` since we need to
14590
* apply some custom logic to these values before they
14691
* are sent.
14792
*/
14893
GleanMetrics.pageLoad({
149-
url: Utils.getUrl(),
150-
referrer: Utils.getReferrer()
94+
url: Utils.filterURL(window.location.href),
95+
referrer: Utils.filterURL(document.referrer)
15196
});
15297
},
15398

0 commit comments

Comments
 (0)