-
Notifications
You must be signed in to change notification settings - Fork 45
Align event logging/compliance with ml-trainer #1303
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
Draft
microbit-matt-hillsdon
wants to merge
4
commits into
main
Choose a base branch
from
analytics-ga4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1687190
Move analytics into the OSS app and redesign events as a GA4 catalog
microbit-matt-hillsdon 90d73ab
Generalise analytics param names for cross-product reuse
microbit-matt-hillsdon e7f7d51
Use python-editor-v3-microbit 0.3.0-analytics.ga4.98 in CI
microbit-matt-hillsdon 2cd0e0a
Fix cm/openDocs navigation broken by analytics param rename
microbit-matt-hillsdon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,30 @@ | ||
| /** | ||
| * (c) 2026, Micro:bit Educational Foundation and contributors | ||
| * | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
| import { ReactNode, createContext } from "react"; | ||
| import { CookieConsent, DeploymentConfig } from "../deployment"; | ||
|
|
||
| const stubConsentValue: CookieConsent = { | ||
| analytics: false, | ||
| functional: true, | ||
| }; | ||
| const stubConsentContext = createContext<CookieConsent | undefined>( | ||
| stubConsentValue | ||
| ); | ||
|
|
||
| /** | ||
| * Compliance for builds without the shared-assets cookie modal (OSS forks, | ||
| * local dev). Consent is immediately "functional only" so features gated on | ||
| * having a consent decision, such as the welcome dialog, still work. | ||
| */ | ||
| export const createStubCompliance = (): DeploymentConfig["compliance"] => ({ | ||
| ConsentProvider: ({ children }: { children: ReactNode }) => ( | ||
| <stubConsentContext.Provider value={stubConsentValue}> | ||
| {children} | ||
| </stubConsentContext.Provider> | ||
| ), | ||
| consentContext: stubConsentContext, | ||
| manageCookies: undefined, | ||
| }); |
This file contains hidden or 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,130 @@ | ||
| /** | ||
| * (c) 2026, Micro:bit Educational Foundation and contributors | ||
| * | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
| import { ReactNode, createContext, useEffect, useState } from "react"; | ||
| import { CookieConsent, DeploymentConfig } from "../deployment"; | ||
| import { isStageWithAnalytics } from "../logging/stage"; | ||
|
|
||
| /** | ||
| * Surface of the shared-assets `commonConsent` API | ||
| * (https://shared-assets.microbit.org/common/v2/common.js) that we depend | ||
| * on. Defined here only to give the compliance code a typed handle on | ||
| * `window` — the script itself is the authoritative source of behaviour. | ||
| */ | ||
| interface CommonConsent { | ||
| show: (opts: { userTriggered?: boolean; config: ConsentConfig }) => void; | ||
| hide: () => void; | ||
| } | ||
|
|
||
| interface ConsentConfig { | ||
| ga: Record<string, never> | undefined; | ||
| custom: Array<{ | ||
| type: string; | ||
| category: string; | ||
| name: string; | ||
| purpose: string; | ||
| }>; | ||
| } | ||
|
|
||
| type CommonConsentWindow = Window & { | ||
| commonConsent?: CommonConsent; | ||
| }; | ||
|
|
||
| /** | ||
| * Web compliance backed by the shared-assets `commonConsent` API. Shows | ||
| * the cookie modal, listens for `consentchange`, and exposes a | ||
| * `manageCookies` callback that re-opens the modal on user request. | ||
| * Embedded sites (`window.self !== window.top`) assume the parent | ||
| * handles notices so we no-op there. | ||
| */ | ||
| export const createWebCompliance = ( | ||
| env: Record<string, string> | ||
| ): DeploymentConfig["compliance"] => { | ||
| const consentContext = createContext<CookieConsent | undefined>(undefined); | ||
|
|
||
| const config: ConsentConfig = { | ||
| ga: isStageWithAnalytics(env.VITE_STAGE) ? {} : undefined, | ||
| custom: [ | ||
| { | ||
| type: "session", | ||
| category: "essential", | ||
| name: "sessionSettings", | ||
| purpose: "Used to disable hints based on your prior actions", | ||
| }, | ||
| { | ||
| type: "local", | ||
| category: "essential", | ||
| name: "release-notice", | ||
| purpose: | ||
| "Records which version of the first-time-use notice you've seen so we can decide to show or suppress it in future", | ||
| }, | ||
| { | ||
| type: "local", | ||
| category: "essential", | ||
| name: "settings", | ||
| purpose: | ||
| "Used to store your settings and remember which dialogs you've opted not to be shown in future", | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const showConsent = ( | ||
| { userTriggered }: { userTriggered: boolean } = { userTriggered: false } | ||
| ) => { | ||
| (window as CommonConsentWindow).commonConsent?.show({ | ||
| userTriggered, | ||
| config, | ||
| }); | ||
| }; | ||
|
|
||
| const hideConsent = () => { | ||
| (window as CommonConsentWindow).commonConsent?.hide(); | ||
| }; | ||
|
|
||
| const manageCookies = () => showConsent({ userTriggered: true }); | ||
|
|
||
| const ConsentProvider = ({ children }: { children: ReactNode }) => { | ||
| const [value, setValue] = useState<CookieConsent | undefined>(undefined); | ||
| useEffect(() => { | ||
| // If we're embedded we assume the embedding site is taking | ||
| // responsibility for required notices to avoid nested cookie modals. | ||
| if (inIframe()) { | ||
| return; | ||
| } | ||
| const w = window as CommonConsentWindow; | ||
| const updateListener = (event: Event) => { | ||
| setValue((event as CustomEvent<CookieConsent>).detail); | ||
| }; | ||
| const initListener = () => showConsent(); | ||
| w.addEventListener("consentchange", updateListener); | ||
| if (w.commonConsent) { | ||
| showConsent(); | ||
| } else { | ||
| w.addEventListener("consentinit", initListener); | ||
| } | ||
| return () => { | ||
| w.removeEventListener("consentchange", updateListener); | ||
| w.removeEventListener("consentinit", initListener); | ||
| hideConsent(); | ||
| }; | ||
| }, []); | ||
|
|
||
| return ( | ||
| <consentContext.Provider value={value}> | ||
| {children} | ||
| </consentContext.Provider> | ||
| ); | ||
| }; | ||
|
|
||
| return { ConsentProvider, consentContext, manageCookies }; | ||
| }; | ||
|
|
||
| const inIframe = () => { | ||
| try { | ||
| return window.self !== window.top; | ||
| } catch { | ||
| return true; | ||
| } | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove irrelevant note.