Skip to content

Commit

Permalink
Remove superfluous Glean metrics (mozilla#14690)
Browse files Browse the repository at this point in the history
* Remove superfluous Glean metrics

* Update tests/unit/spec/glean/utils.js

Co-authored-by: Jan Brasna <1784648+janbrasna@users.noreply.github.com>

* Update tests/unit/spec/glean/utils.js

Co-authored-by: Jan Brasna <1784648+janbrasna@users.noreply.github.com>

---------

Co-authored-by: Jan Brasna <1784648+janbrasna@users.noreply.github.com>
  • Loading branch information
alexgibson and janbrasna authored Jun 19, 2024
1 parent 586a89a commit ea52492
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 454 deletions.
2 changes: 0 additions & 2 deletions bedrock/base/templates/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

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

{% block html_attrs %}data-http-status="404"{% endblock %}

{% block page_title %}{{ ftl('not-found-page-not-found-page-page-not-found') }}{% endblock %}

{% block page_css %}
Expand Down
106 changes: 0 additions & 106 deletions glean/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,112 +2,6 @@
$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0

page:
viewed:
type: datetime
lifetime: application
send_in_pings:
- events
description: |
The time a page was viewed.
data_sensitivity:
- web_activity
bugs:
- https://github.com/mozilla/bedrock/issues/10746
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1767442
notification_emails:
- marketing-websites-team@mozilla.com
expires: never
path:
type: string
lifetime: application
send_in_pings:
- events
description: |
The URL path of the page that was viewed, excluding locale.
data_sensitivity:
- web_activity
bugs:
- https://github.com/mozilla/bedrock/issues/10746
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1767442
notification_emails:
- marketing-websites-team@mozilla.com
expires: never
locale:
type: string
lifetime: application
send_in_pings:
- events
description: |
The locale of the page that was viewed.
data_sensitivity:
- web_activity
bugs:
- https://github.com/mozilla/bedrock/issues/10746
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1767442
notification_emails:
- marketing-websites-team@mozilla.com
expires: never
query_params:
type: labeled_string
lifetime: application
send_in_pings:
- events
description: |
Query parameters associated with the URL of
the page that was viewed.
bugs:
- https://github.com/mozilla/bedrock/issues/10746
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1767442
notification_emails:
- marketing-websites-team@mozilla.com
expires: never
labels:
- utm_source
- utm_campaign
- utm_medium
- utm_content
- entrypoint_experiment
- entrypoint_variation
- experiment
- variation
- v
- xv
referrer:
type: string
lifetime: application
send_in_pings:
- events
description: |
The referring URL that linked to the page that was viewed.
data_sensitivity:
- web_activity
bugs:
- https://github.com/mozilla/bedrock/issues/10746
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1767442
notification_emails:
- marketing-websites-team@mozilla.com
expires: never
http_status:
type: string
description: |
The HTTP status code of the page.
lifetime: application
send_in_pings:
- events
data_sensitivity:
- technical
bugs:
- https://github.com/mozilla/bedrock/issues/13581
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1848981
notification_emails:
- marketing-websites-team@mozilla.com
expires: never
interaction:
type: event
description: |
Expand Down
45 changes: 1 addition & 44 deletions media/js/glean/page.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,6 @@
*/

import * as page from '../libs/glean/page.js';
import Utils from './utils.es6';

const defaultParams = {
utm_source: '',
utm_campaign: '',
utm_medium: '',
utm_content: '',
entrypoint_experiment: '',
entrypoint_variation: '',
experiment: '',
variation: '',
v: '', // short param for 'variation'
xv: '' // short param for 'experience version'.
};

function recordCustomPageMetrics() {
page.viewed.set();
page.path.set(Utils.getPathFromUrl());
page.locale.set(Utils.getLocaleFromUrl());
page.referrer.set(Utils.getReferrer());
page.httpStatus.set(Utils.getHttpStatus());

const params = Utils.getQueryParamsFromUrl();
const finalParams = {};

// validate only known & trusted query params
// for inclusion in Glean metrics.
for (const param in defaultParams) {
if (Object.prototype.hasOwnProperty.call(defaultParams, param)) {
const allowedChars = /^[\w/.%-]+$/;
let v = params.get(param);

if (v) {
v = decodeURIComponent(v);
finalParams[param] = allowedChars.test(v) ? v : '';
} else {
finalParams[param] = '';
}

page.queryParams[param].set(finalParams[param]);
}
}
}

function pageEvent(obj) {
if (typeof obj !== 'object' && typeof obj.label !== 'string') {
Expand Down Expand Up @@ -77,4 +34,4 @@ function pageEvent(obj) {
}
}

export { recordCustomPageMetrics, pageEvent };
export { pageEvent };
77 changes: 11 additions & 66 deletions media/js/glean/utils.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@

import Glean from '@mozilla/glean/web';
import GleanMetrics from '@mozilla/glean/metrics';
import { pageEvent, recordCustomPageMetrics } from './page.es6';
import { pageEvent } from './page.es6';
import {
consentRequired,
getConsentCookie,
isFirefoxDownloadThanks
} from '../base/consent/utils.es6';

const Utils = {
filterNewsletterURL: (str) => {
/**
* Takes a URL string and filters out any sensitive information,
* such as newsletter tokens, before returning the URL.
* See issue https://github.com/mozilla/bedrock/issues/13583
* @param {String} URL
* @returns {String} filtered URL
*/
filterURL: (str) => {
try {
const url = new URL(str);

// Ensure we don't include tokens in newsletter page load event pings
// Issue https://github.com/mozilla/bedrock/issues/13583
const newsletterPaths = [
'/newsletter/existing/',
'/newsletter/country/'
Expand All @@ -45,63 +49,6 @@ const Utils = {
}
},

getUrl: (str) => {
const url = typeof str === 'string' ? str : window.location.href;
return Utils.filterNewsletterURL(url);
},

getPathFromUrl: (str) => {
let pathName =
typeof str === 'string' ? str : document.location.pathname;
pathName = pathName.replace(/^(\/\w{2}-\w{2}\/|\/\w{2,3}\/)/, '/');
const newsletterPaths = [
'/newsletter/existing/',
'/newsletter/country/'
];

// Ensure we don't include tokens in newsletter page pings
// Issue https://github.com/mozilla/bedrock/issues/13583
newsletterPaths.forEach((path) => {
if (pathName.includes(path)) {
pathName = path;
}
});

return pathName;
},

getLocaleFromUrl: (str) => {
const pathName =
typeof str === 'string' ? str : document.location.pathname;
const locale = pathName.match(/^\/(\w{2}-\w{2}|\w{2,3})\//);
// If there's no locale in the path then assume language is `en-US`;
return locale && locale.length > 0 ? locale[1] : 'en-US';
},

getQueryParamsFromUrl: (str) => {
const query = typeof str === 'string' ? str : window.location.search;

if (typeof window._SearchParams !== 'undefined') {
return new window._SearchParams(query);
}

return false;
},

getReferrer: (str) => {
const referrer = typeof str === 'string' ? str : document.referrer;
const url = Utils.filterNewsletterURL(referrer);

return url;
},

getHttpStatus: () => {
const pageId = document
.getElementsByTagName('html')[0]
.getAttribute('data-http-status');
return pageId && pageId === '404' ? '404' : '200';
},

/**
* Determine if page URL is /firefox/download/thanks/.
*/
Expand Down Expand Up @@ -137,17 +84,15 @@ const Utils = {
* Record page load event and add custom metrics.
*/
initPageLoadEvent: () => {
recordCustomPageMetrics();

/**
* Manually call Glean's default page_load event. Here
* we override `url` and `referrer` since we need to
* apply some custom logic to these values before they
* are sent.
*/
GleanMetrics.pageLoad({
url: Utils.getUrl(),
referrer: Utils.getReferrer()
url: Utils.filterURL(window.location.href),
referrer: Utils.filterURL(document.referrer)
});
},

Expand Down
Loading

0 comments on commit ea52492

Please sign in to comment.