Skip to content

Commit

Permalink
feat(glean): add is_baseline metric to pings (#9476)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMcA authored Sep 1, 2023
1 parent c40fb92 commit 231d6aa
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 46 deletions.
2 changes: 1 addition & 1 deletion client/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function App(appProps: HydrationData) {
);

usePing();
useGleanPage(pageNotFound);
useGleanPage(pageNotFound, appProps.doc);

const localeMatch = useMatch("/:locale/*");

Expand Down
2 changes: 1 addition & 1 deletion client/src/telemetry/generated/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// AUTOGENERATED BY glean_parser v6.2.1. DO NOT EDIT. DO NOT COMMIT.
// AUTOGENERATED BY glean_parser v8.1.1. DO NOT EDIT. DO NOT COMMIT.

import EventMetricType from "@mozilla/glean/private/metrics/event";

Expand Down
40 changes: 20 additions & 20 deletions client/src/telemetry/generated/navigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// AUTOGENERATED BY glean_parser v6.2.1. DO NOT EDIT. DO NOT COMMIT.
// AUTOGENERATED BY glean_parser v8.1.1. DO NOT EDIT. DO NOT COMMIT.

import StringMetricType from "@mozilla/glean/private/metrics/string";
import QuantityMetricType from "@mozilla/glean/private/metrics/quantity";
import StringMetricType from "@mozilla/glean/private/metrics/string";

/**
* The navigators ISO 3166 country name (not code) based on geo ip.
Expand All @@ -21,27 +21,27 @@ export const geo = new StringMetricType({
});

/**
* The navigators user agent.
* The subscription type of the user. can be one of
* 'core','mdn_plus_5m','mdn_plus_5y','mdn_plus_10m','mdn_plus_10y'
*
* Generated from `navigator.user_agent`.
* Generated from `navigator.subscription_type`.
*/
export const userAgent = new StringMetricType({
export const subscriptionType = new StringMetricType({
category: "navigator",
name: "user_agent",
name: "subscription_type",
sendInPings: ["action", "page"],
lifetime: "application",
disabled: false,
});

/**
* The subscription type of the user. can be one of
* 'core','mdn_plus_5m','mdn_plus_5y','mdn_plus_10m','mdn_plus_10y'
* The navigators user agent.
*
* Generated from `navigator.subscription_type`.
* Generated from `navigator.user_agent`.
*/
export const subscriptionType = new StringMetricType({
export const userAgent = new StringMetricType({
category: "navigator",
name: "subscription_type",
name: "user_agent",
sendInPings: ["action", "page"],
lifetime: "application",
disabled: false,
Expand All @@ -62,27 +62,27 @@ export const viewportBreakpoint = new StringMetricType({
});

/**
* The ratio of viewport width to viewport height,
* expressed as a percentage.
* The ratio of viewport width to screen width, expressed as a percentage.
*
* Generated from `navigator.viewport_ratio`.
* Generated from `navigator.viewport_horizontal_coverage`.
*/
export const viewportRatio = new QuantityMetricType({
export const viewportHorizontalCoverage = new QuantityMetricType({
category: "navigator",
name: "viewport_ratio",
name: "viewport_horizontal_coverage",
sendInPings: ["action", "page"],
lifetime: "application",
disabled: false,
});

/**
* The ratio of viewport width to screen width, expressed as a percentage.
* The ratio of viewport width to viewport height,
* expressed as a percentage.
*
* Generated from `navigator.viewport_horizontal_coverage`.
* Generated from `navigator.viewport_ratio`.
*/
export const viewportHorizontalCoverage = new QuantityMetricType({
export const viewportRatio = new QuantityMetricType({
category: "navigator",
name: "viewport_horizontal_coverage",
name: "viewport_ratio",
sendInPings: ["action", "page"],
lifetime: "application",
disabled: false,
Expand Down
42 changes: 29 additions & 13 deletions client/src/telemetry/generated/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,61 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// AUTOGENERATED BY glean_parser v6.2.1. DO NOT EDIT. DO NOT COMMIT.
// AUTOGENERATED BY glean_parser v8.1.1. DO NOT EDIT. DO NOT COMMIT.

import UrlMetricType from "@mozilla/glean/private/metrics/url";
import StringMetricType from "@mozilla/glean/private/metrics/string";

/**
* The URL path of the page that was viewed.
* The HTTP status code of the page.
*
* Generated from `page.path`.
* Generated from `page.http_status`.
*/
export const path = new UrlMetricType({
export const httpStatus = new StringMetricType({
category: "page",
name: "path",
name: "http_status",
sendInPings: ["action", "page"],
lifetime: "application",
disabled: false,
});

/**
* The referring URL that linked to the page that was viewed.
* The Baseline status of the page:
* null: the page has no baseline status
* "baseline": the page is baseline
* "not_baseline" the page is not baseline
*
* Generated from `page.referrer`.
* Generated from `page.is_baseline`.
*/
export const referrer = new UrlMetricType({
export const isBaseline = new StringMetricType({
category: "page",
name: "referrer",
name: "is_baseline",
sendInPings: ["action", "page"],
lifetime: "application",
disabled: false,
});

/**
* The http status of the page.
* The URL path of the page that was viewed.
*
* Generated from `page.http_status`.
* Generated from `page.path`.
*/
export const httpStatus = new StringMetricType({
export const path = new UrlMetricType({
category: "page",
name: "http_status",
name: "path",
sendInPings: ["action", "page"],
lifetime: "application",
disabled: false,
});

/**
* The referring URL that linked to the page that was viewed.
*
* Generated from `page.referrer`.
*/
export const referrer = new UrlMetricType({
category: "page",
name: "referrer",
sendInPings: ["action", "page"],
lifetime: "application",
disabled: false,
Expand Down
18 changes: 9 additions & 9 deletions client/src/telemetry/generated/pings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// AUTOGENERATED BY glean_parser v6.2.1. DO NOT EDIT. DO NOT COMMIT.
// AUTOGENERATED BY glean_parser v8.1.1. DO NOT EDIT. DO NOT COMMIT.

import PingType from "@mozilla/glean/private/ping";

/**
* A ping that will be sent everytime a new page is visited.
* A ping that will be sent everytime a page event happens (user interaction).
*
* Generated from `page`.
* Generated from `action`.
*/
export const page = new PingType({
name: "page",
export const action = new PingType({
name: "action",
includeClientId: true,
sendIfEmpty: false,
reasonCodes: [],
});

/**
* A ping that will be sent everytime a page event happens (user interaction).
* A ping that will be sent everytime a new page is visited.
*
* Generated from `action`.
* Generated from `page`.
*/
export const action = new PingType({
name: "action",
export const page = new PingType({
name: "page",
includeClientId: true,
sendIfEmpty: false,
reasonCodes: [],
Expand Down
15 changes: 13 additions & 2 deletions client/src/telemetry/glean-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useLocation } from "react-router";
import { useUserData } from "../user-context";
import { handleSidebarClick } from "./sidebar-click";
import { VIEWPORT_BREAKPOINTS } from "./constants";
import { Doc } from "../../../libs/types/document";

export type ViewportBreakpoint = "xs" | "sm" | "md" | "lg" | "xl" | "xxl";
export type HTTPStatus = "200" | "404";
Expand All @@ -24,6 +25,7 @@ export type PageProps = {
viewportBreakpoint: ViewportBreakpoint | undefined;
viewportRatio: number;
viewportHorizontalCoverage: number;
isBaseline?: string;
};

export type PageEventProps = {
Expand Down Expand Up @@ -93,6 +95,9 @@ function glean(): GleanAnalytics {
if (referrer) {
pageMetric.referrer.setUrl(referrer);
}
if (page.isBaseline) {
pageMetric.isBaseline.set(page.isBaseline);
}
pageMetric.httpStatus.set(page.httpStatus);
if (page.geo) {
navigatorMetric.geo.set(page.geo);
Expand Down Expand Up @@ -171,7 +176,7 @@ export function useGlean() {
return React.useContext(GleanContext);
}

export function useGleanPage(pageNotFound: boolean) {
export function useGleanPage(pageNotFound: boolean, doc?: Doc) {
const loc = useLocation();
const userData = useUserData();
const path = useRef<String | null>(null);
Expand All @@ -192,12 +197,18 @@ export function useGleanPage(pageNotFound: boolean) {
viewportHorizontalCoverage: Math.round(
(100 * window.innerWidth) / window.screen.width
),
isBaseline:
doc?.baseline?.is_baseline === undefined
? undefined
: doc.baseline.is_baseline
? "baseline"
: "not_baseline",
});
if (typeof userData !== "undefined" && path.current !== loc.pathname) {
path.current = loc.pathname;
submit();
}
}, [loc.pathname, userData, pageNotFound]);
}, [loc.pathname, userData, pageNotFound, doc?.baseline?.is_baseline]);
}

export function useGleanClick() {
Expand Down
20 changes: 20 additions & 0 deletions client/src/telemetry/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ page:
notification_emails:
- mdn-team@mozilla.com
expires: 2023-09-05
is_baseline:
type: string
description: |
The Baseline status of the page:
null: the page has no baseline status
"baseline": the page is baseline
"not_baseline" the page is not baseline
lifetime: application
send_in_pings:
- page
- action
data_sensitivity:
- technical
bugs:
- "https://mozilla-hub.atlassian.net/browse/MP-542"
data_reviews:
- "https://bugzilla.mozilla.org/show_bug.cgi?id=1848187"
notification_emails:
- mdn-team@mozilla.com
expires: 2024-09-05

navigator:
geo:
Expand Down
2 changes: 2 additions & 0 deletions libs/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export const CSP_DIRECTIVES = {
"connect-src": [
"'self'",

"developer.allizom.org", // required for glean to work on localhost:5042

"bcd.developer.allizom.org",
"bcd.developer.mozilla.org",

Expand Down

0 comments on commit 231d6aa

Please sign in to comment.