-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4794 from mozilla/mntor-3358-view-telemetry
Add view telemetry for CTA buttons (MNTOR-3358)
- Loading branch information
Showing
10 changed files
with
143 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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/. */ | ||
|
||
import { IntersectionOptions, useInView } from "react-intersection-observer"; | ||
import { TelemetryArgs, useTelemetry } from "./useTelemetry"; | ||
import { GleanMetricMap } from "../../telemetry/generated/_map"; | ||
import { RefObject } from "react"; | ||
|
||
export function useViewTelemetry< | ||
EventModule extends keyof Pick<GleanMetricMap, "ctaButton">, | ||
EventName extends keyof GleanMetricMap[EventModule], | ||
>( | ||
eventModule: EventModule, | ||
args: TelemetryArgs & GleanMetricMap[EventModule][EventName], | ||
options?: IntersectionOptions, | ||
) { | ||
const { experimentationId, ...telemetryArgs } = args; | ||
const recordTelemetry = useTelemetry({ experimentationId }); | ||
const { ref } = useInView({ | ||
skip: Object.keys(telemetryArgs).length === 0, | ||
threshold: 1, | ||
triggerOnce: true, | ||
...options, | ||
onChange: (inView) => { | ||
// Since this function is only triggered once when an element is entering | ||
// the viewport and not again after leaving it. With the current setting | ||
// the following condition is not expected to get called. Keeping the | ||
// condition in place in case this changes. | ||
/* c8 ignore next 3 */ | ||
if (!inView) { | ||
return; | ||
} | ||
recordTelemetry(eventModule, "view", telemetryArgs); | ||
}, | ||
}); | ||
|
||
return ref as unknown as RefObject<unknown>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -429,6 +429,38 @@ cta_button: | |
description: Which tier of plan the user is on [Free, Plus] | ||
type: string | ||
|
||
view: | ||
type: event | ||
description: | | ||
A button that has a specific call-to-action entered the viewport. | ||
bugs: | ||
- https://bugzilla.mozilla.org/show_bug.cgi?id=1823766 | ||
data_reviews: | ||
- https://bugzilla.mozilla.org/show_bug.cgi?id=1823766 | ||
data_sensitivity: | ||
- interaction | ||
notification_emails: | ||
- [email protected] | ||
expires: never | ||
extra_keys: | ||
path: | ||
description: The path of the page. | ||
type: string | ||
user_id: | ||
description: Mozilla accounts user ID. | ||
type: string | ||
session_id: | ||
description: An ID that allows us to track “sessions” of the user experience within the product. | ||
type: string | ||
flow_id: | ||
description: A randomly generated unique identifier for following user flows within the FxA system. | ||
type: string | ||
button_id: | ||
description: The ID of the button that entered the viewport, or some way to identify where on the page the interaction is located. | ||
plan_tier: | ||
description: Which tier of plan the user is on [Free, Plus] | ||
type: string | ||
|
||
csat_survey: | ||
click: | ||
type: event | ||
|