Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(glean): add is_baseline metric to pings #9476

Merged
merged 3 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Comment on lines +200 to +205
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some potential JS magic:

isBaseline: { undefined: undefined, true: "baseline", false: "no_baseline"}[doc?.baseline?.is_baseline]

or

isBaseline: { true: "baseline", false: "no_baseline"}[doc?.baseline?.is_baseline]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately typescript makes this less fun, as I have to manually cast doc?.baseline?.is_baseline to a string:

      isBaseline: { true: "baseline", false: "no_baseline" }[
        String(doc?.baseline?.is_baseline)
      ],

So I'm going to leave as it is, especially since I imagine we'll need a second layer of logic for future the almost-baseline case, but I'll remember this for the future!

});
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:
- [email protected]
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:
- [email protected]
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