diff --git a/package.json b/package.json index b9e65824ad..d5700d1c30 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "linkifyjs": "^4.0.0-beta.4", "lodash": "^4.17.20", "maplibre-gl": "^1.15.2", - "matrix-analytics-events": "github:matrix-org/matrix-analytics-events.git#b183e6316826be11bbcc82d44b8f71921acd9d76", + "matrix-analytics-events": "github:matrix-org/matrix-analytics-events.git#bdabdd63280f052cedeeb0c25443f3d55f7c7108", "matrix-events-sdk": "^0.0.1-beta.6", "matrix-js-sdk": "github:matrix-org/matrix-js-sdk#develop", "matrix-widget-api": "^0.1.0-beta.18", diff --git a/src/PosthogAnalytics.ts b/src/PosthogAnalytics.ts index dec956d3ad..343aea6235 100644 --- a/src/PosthogAnalytics.ts +++ b/src/PosthogAnalytics.ts @@ -23,6 +23,7 @@ import PlatformPeg from './PlatformPeg'; import SdkConfig from './SdkConfig'; import { MatrixClientPeg } from "./MatrixClientPeg"; import SettingsStore from "./settings/SettingsStore"; +import { ScreenName } from "./PosthogTrackers"; /* Posthog analytics tracking. * @@ -148,20 +149,20 @@ export class PosthogAnalytics { } } + // we persist the last `$screen_name` and send it for all events until it is replaced + private lastScreen: ScreenName = "Loading"; + private sanitizeProperties = (properties: posthog.Properties): posthog.Properties => { // Callback from posthog to sanitize properties before sending them to the server. // // Here we sanitize posthog's built in properties which leak PII e.g. url reporting. // See utils.js _.info.properties in posthog-js. - // Replace the $current_url with a redacted version. - // $redacted_current_url is injected by this class earlier in capture(), as its generation - // is async and can't be done in this non-async callback. - if (!properties['$redacted_current_url']) { - logger.log("$redacted_current_url not set in sanitizeProperties, will drop $current_url entirely"); + if (properties["eventName"] === "$pageview") { + this.lastScreen = properties["$current_url"]; } - properties['$current_url'] = properties['$redacted_current_url']; - delete properties['$redacted_current_url']; + // We inject a screen identifier in $current_url as per https://posthog.com/tutorials/spa + properties["$current_url"] = this.lastScreen; if (this.anonymity == Anonymity.Anonymous) { // drop referrer information for anonymous users @@ -204,7 +205,7 @@ export class PosthogAnalytics { return; } const { origin, hash, pathname } = window.location; - properties['$redacted_current_url'] = getRedactedCurrentLocation(origin, hash, pathname); + properties["redactedCurrentUrl"] = getRedactedCurrentLocation(origin, hash, pathname); this.posthog.capture(eventName, { ...this.propertiesForNextEvent, ...properties, diff --git a/src/PosthogTrackers.ts b/src/PosthogTrackers.ts index 5b65262056..b07ba5569c 100644 --- a/src/PosthogTrackers.ts +++ b/src/PosthogTrackers.ts @@ -15,25 +15,25 @@ limitations under the License. */ import { PureComponent, SyntheticEvent } from "react"; -import { Screen as ScreenEvent } from "matrix-analytics-events/types/typescript/Screen"; +import { WebScreen as ScreenEvent } from "matrix-analytics-events/types/typescript/WebScreen"; import { Interaction as InteractionEvent } from "matrix-analytics-events/types/typescript/Interaction"; import PageType from "./PageTypes"; import Views from "./Views"; import { PosthogAnalytics } from "./PosthogAnalytics"; -export type ScreenName = ScreenEvent["screenName"]; +export type ScreenName = ScreenEvent["$current_url"]; export type InteractionName = InteractionEvent["name"]; const notLoggedInMap: Record, ScreenName> = { - [Views.LOADING]: "WebLoading", + [Views.LOADING]: "Loading", [Views.WELCOME]: "Welcome", [Views.LOGIN]: "Login", [Views.REGISTER]: "Register", [Views.FORGOT_PASSWORD]: "ForgotPassword", - [Views.COMPLETE_SECURITY]: "WebCompleteSecurity", - [Views.E2E_SETUP]: "WebE2ESetup", - [Views.SOFT_LOGOUT]: "WebSoftLogout", + [Views.COMPLETE_SECURITY]: "CompleteSecurity", + [Views.E2E_SETUP]: "E2ESetup", + [Views.SOFT_LOGOUT]: "SoftLogout", }; const loggedInPageTypeMap: Record = { @@ -70,8 +70,8 @@ export default class PosthogTrackers { ? loggedInPageTypeMap[this.pageType] : notLoggedInMap[this.view]; PosthogAnalytics.instance.trackEvent({ - eventName: "$screen", - screenName, + eventName: "$pageview", + $current_url: screenName, durationMs, }); } @@ -80,8 +80,8 @@ export default class PosthogTrackers { if (!screenName) return; this.override = screenName; PosthogAnalytics.instance.trackEvent({ - eventName: "$screen", - screenName, + eventName: "$pageview", + $current_url: screenName, }); } diff --git a/src/components/views/dialogs/UserSettingsDialog.tsx b/src/components/views/dialogs/UserSettingsDialog.tsx index 5ca0601655..e1fc863acb 100644 --- a/src/components/views/dialogs/UserSettingsDialog.tsx +++ b/src/components/views/dialogs/UserSettingsDialog.tsx @@ -94,14 +94,14 @@ export default class UserSettingsDialog extends React.Component _td("General"), "mx_UserSettingsDialog_settingsIcon", , - "WebUserSettingsGeneral", + "UserSettingsGeneral", )); tabs.push(new Tab( UserTab.Appearance, _td("Appearance"), "mx_UserSettingsDialog_appearanceIcon", , - "WebUserSettingsAppearance", + "UserSettingsAppearance", )); if (SettingsStore.getValue(UIFeature.Flair)) { tabs.push(new Tab( @@ -109,7 +109,7 @@ export default class UserSettingsDialog extends React.Component _td("Flair"), "mx_UserSettingsDialog_flairIcon", , - "WebUserSettingFlair", + "UserSettingFlair", )); } tabs.push(new Tab( @@ -117,28 +117,28 @@ export default class UserSettingsDialog extends React.Component _td("Notifications"), "mx_UserSettingsDialog_bellIcon", , - "WebUserSettingsNotifications", + "UserSettingsNotifications", )); tabs.push(new Tab( UserTab.Preferences, _td("Preferences"), "mx_UserSettingsDialog_preferencesIcon", , - "WebUserSettingsPreferences", + "UserSettingsPreferences", )); tabs.push(new Tab( UserTab.Keyboard, _td("Keyboard"), "mx_UserSettingsDialog_keyboardIcon", , - "WebUserSettingsKeyboard", + "UserSettingsKeyboard", )); tabs.push(new Tab( UserTab.Sidebar, _td("Sidebar"), "mx_UserSettingsDialog_sidebarIcon", , - "WebUserSettingsSidebar", + "UserSettingsSidebar", )); if (SettingsStore.getValue(UIFeature.Voip)) { @@ -147,7 +147,7 @@ export default class UserSettingsDialog extends React.Component _td("Voice & Video"), "mx_UserSettingsDialog_voiceIcon", , - "WebUserSettingsVoiceVideo", + "UserSettingsVoiceVideo", )); } @@ -156,7 +156,7 @@ export default class UserSettingsDialog extends React.Component _td("Security & Privacy"), "mx_UserSettingsDialog_securityIcon", , - "WebUserSettingsSecurityPrivacy", + "UserSettingsSecurityPrivacy", )); // Show the Labs tab if enabled or if there are any active betas if (SdkConfig.get()['showLabsSettings'] @@ -167,7 +167,7 @@ export default class UserSettingsDialog extends React.Component _td("Labs"), "mx_UserSettingsDialog_labsIcon", , - "WebUserSettingsLabs", + "UserSettingsLabs", )); } if (this.state.mjolnirEnabled) { @@ -176,7 +176,7 @@ export default class UserSettingsDialog extends React.Component _td("Ignored users"), "mx_UserSettingsDialog_mjolnirIcon", , - "WebUserSettingMjolnir", + "UserSettingMjolnir", )); } tabs.push(new Tab( @@ -184,7 +184,7 @@ export default class UserSettingsDialog extends React.Component _td("Help & About"), "mx_UserSettingsDialog_helpIcon", this.props.onFinished(true)} />, - "WebUserSettingsHelpAbout", + "UserSettingsHelpAbout", )); return tabs; diff --git a/yarn.lock b/yarn.lock index 2e9b55066d..d8cf4152ec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6249,9 +6249,9 @@ mathml-tag-names@^2.1.3: resolved "https://registry.yarnpkg.com/mathml-tag-names/-/mathml-tag-names-2.1.3.tgz#4ddadd67308e780cf16a47685878ee27b736a0a3" integrity sha512-APMBEanjybaPzUrfqU0IMU5I0AswKMH7k8OTLs0vvV4KZpExkTkY87nR/zpbuTPj+gARop7aGUbl11pnDfW6xg== -"matrix-analytics-events@github:matrix-org/matrix-analytics-events.git#b183e6316826be11bbcc82d44b8f71921acd9d76": +"matrix-analytics-events@github:matrix-org/matrix-analytics-events.git#bdabdd63280f052cedeeb0c25443f3d55f7c7108": version "0.0.1" - resolved "https://codeload.github.com/matrix-org/matrix-analytics-events/tar.gz/b183e6316826be11bbcc82d44b8f71921acd9d76" + resolved "https://codeload.github.com/matrix-org/matrix-analytics-events/tar.gz/bdabdd63280f052cedeeb0c25443f3d55f7c7108" matrix-events-sdk@^0.0.1-beta.6: version "0.0.1-beta.6"