Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 427be43

Browse files
authored
Add analytics to activity toggles (#12418)
* Add analytics to activity toggles Requires matrix-org/matrix-analytics-events#101 * Add test * Fix comment a bit * Update to new analytics events package
1 parent 6dd6a76 commit 427be43

File tree

4 files changed

+86
-31
lines changed

4 files changed

+86
-31
lines changed

src/settings/Settings.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import ServerSupportUnstableFeatureController from "./controllers/ServerSupportU
4747
import { WatchManager } from "./WatchManager";
4848
import { CustomTheme } from "../theme";
4949
import SettingsStore from "./SettingsStore";
50+
import AnalyticsController from "./controllers/AnalyticsController";
5051

5152
export const defaultWatchManager = new WatchManager();
5253

@@ -597,11 +598,13 @@ export const SETTINGS: { [setting: string]: ISetting } = {
597598
displayName: _td("settings|showbold"),
598599
default: false,
599600
invertedSettingName: "feature_hidebold",
601+
controller: new AnalyticsController("WebSettingsNotificationsShowBoldToggle"),
600602
},
601603
"Notifications.tac_only_notifications": {
602604
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
603605
displayName: _td("settings|tac_only_notifications"),
604606
default: true,
607+
controller: new AnalyticsController("WebSettingsNotificationsTACOnlyNotificationsToggle"),
605608
},
606609
"feature_ask_to_join": {
607610
isFeature: true,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Copyright 2024 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import SettingController from "./SettingController";
18+
import { SettingLevel } from "../SettingLevel";
19+
import PosthogTrackers, { InteractionName } from "../../PosthogTrackers";
20+
21+
/**
22+
* Controller that sends events to analytics when a setting is changed.
23+
* Since it will only trigger events when the setting is changed,
24+
* (and the value isn't reported: only the fact that it's been toggled)
25+
* it won't be useful for tracking what percentage of a userbase has a given setting
26+
* enabled, but many of our settings can be set per device and Posthog only supports
27+
* per-user properties, so this isn't straightforward. This is only for seeing how
28+
* often people interact with the settings.
29+
*/
30+
export default class AnalyticsController extends SettingController {
31+
/**
32+
*
33+
* @param interactionName The name of the event to send to analytics
34+
*/
35+
public constructor(private interactionName: InteractionName) {
36+
super();
37+
}
38+
39+
public onChange(_level: SettingLevel, _roomId: string | null, _newValue: any): void {
40+
PosthogTrackers.trackInteraction(this.interactionName);
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright 2024 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import PosthogTrackers from "../../../src/PosthogTrackers";
18+
import AnalyticsController from "../../../src/settings/controllers/AnalyticsController";
19+
import { SettingLevel } from "../../../src/settings/SettingLevel";
20+
21+
describe("AnalyticsController", () => {
22+
afterEach(() => {
23+
jest.restoreAllMocks();
24+
});
25+
26+
it("Tracks a Posthog interaction on change", () => {
27+
const trackInteractionSpy = jest.spyOn(PosthogTrackers, "trackInteraction");
28+
29+
const controller = new AnalyticsController("WebSettingsNotificationsTACOnlyNotificationsToggle");
30+
31+
controller.onChange(SettingLevel.DEVICE, null, false);
32+
33+
expect(trackInteractionSpy).toHaveBeenCalledWith("WebSettingsNotificationsTACOnlyNotificationsToggle");
34+
});
35+
});

yarn.lock

+6-31
Original file line numberDiff line numberDiff line change
@@ -1859,9 +1859,9 @@
18591859
integrity sha512-Es6WcD0nO5l+2BOQS4uLfNPYQaNDfbot3X1XUoloz+x0mPDS3eeORZJl06HXjwBG1fOGwCRnzK88LMdxKRrd6Q==
18601860

18611861
"@matrix-org/analytics-events@^0.19.0":
1862-
version "0.19.0"
1863-
resolved "https://registry.yarnpkg.com/@matrix-org/analytics-events/-/analytics-events-0.19.0.tgz#e20e4df54530ed1c755ab728e9c22891e376f9e2"
1864-
integrity sha512-wN/hbpTpOxz2u3zHbsJgVMi88oKmK1yqeSZuif3yNW68XQnV2cc0XGUEpl0fgLOl6fj1bZOtxbDg5rCLbqf4CQ==
1862+
version "0.19.1"
1863+
resolved "https://registry.yarnpkg.com/@matrix-org/analytics-events/-/analytics-events-0.19.1.tgz#304d48b7b8e51117dfd9c1cf46a65e8bee9f46cb"
1864+
integrity sha512-bYWJIkOzl4Jt02fg1+XoQv5xZ3mP6qBzNmytt1UVfKLaGgLBSvlk9gXx2/3GhSuPBq99/CljEX/zABJ//mexAw==
18651865

18661866
"@matrix-org/emojibase-bindings@^1.1.2":
18671867
version "1.1.3"
@@ -8652,16 +8652,7 @@ string-length@^4.0.1:
86528652
char-regex "^1.0.2"
86538653
strip-ansi "^6.0.0"
86548654

8655-
"string-width-cjs@npm:string-width@^4.2.0":
8656-
version "4.2.3"
8657-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
8658-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
8659-
dependencies:
8660-
emoji-regex "^8.0.0"
8661-
is-fullwidth-code-point "^3.0.0"
8662-
strip-ansi "^6.0.1"
8663-
8664-
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
8655+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
86658656
version "4.2.3"
86668657
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
86678658
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -8755,14 +8746,7 @@ string_decoder@~1.1.1:
87558746
dependencies:
87568747
safe-buffer "~5.1.0"
87578748

8758-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
8759-
version "6.0.1"
8760-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
8761-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
8762-
dependencies:
8763-
ansi-regex "^5.0.1"
8764-
8765-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
8749+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
87668750
version "6.0.1"
87678751
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
87688752
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -9555,7 +9539,7 @@ which@^2.0.1:
95559539
dependencies:
95569540
isexe "^2.0.0"
95579541

9558-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
9542+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
95599543
version "7.0.0"
95609544
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
95619545
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -9573,15 +9557,6 @@ wrap-ansi@^6.2.0:
95739557
string-width "^4.1.0"
95749558
strip-ansi "^6.0.0"
95759559

9576-
wrap-ansi@^7.0.0:
9577-
version "7.0.0"
9578-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
9579-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
9580-
dependencies:
9581-
ansi-styles "^4.0.0"
9582-
string-width "^4.1.0"
9583-
strip-ansi "^6.0.0"
9584-
95859560
wrap-ansi@^8.1.0:
95869561
version "8.1.0"
95879562
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)