This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 833
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
4 changed files
with
86 additions
and
31 deletions.
There are no files selected for viewing
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,42 @@ | ||
/* | ||
Copyright 2024 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import SettingController from "./SettingController"; | ||
import { SettingLevel } from "../SettingLevel"; | ||
import PosthogTrackers, { InteractionName } from "../../PosthogTrackers"; | ||
|
||
/** | ||
* Controller that sends events to analytics when a setting is changed. | ||
* Since it will only trigger events when the setting is changed, | ||
* (and the value isn't reported: only the fact that it's been toggled) | ||
* it won't be useful for tracking what percentage of a userbase has a given setting | ||
* enabled, but many of our settings can be set per device and Posthog only supports | ||
* per-user properties, so this isn't straightforward. This is only for seeing how | ||
* often people interact with the settings. | ||
*/ | ||
export default class AnalyticsController extends SettingController { | ||
/** | ||
* | ||
* @param interactionName The name of the event to send to analytics | ||
*/ | ||
public constructor(private interactionName: InteractionName) { | ||
super(); | ||
} | ||
|
||
public onChange(_level: SettingLevel, _roomId: string | null, _newValue: any): void { | ||
PosthogTrackers.trackInteraction(this.interactionName); | ||
} | ||
} |
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,35 @@ | ||
/* | ||
Copyright 2024 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import PosthogTrackers from "../../../src/PosthogTrackers"; | ||
import AnalyticsController from "../../../src/settings/controllers/AnalyticsController"; | ||
import { SettingLevel } from "../../../src/settings/SettingLevel"; | ||
|
||
describe("AnalyticsController", () => { | ||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it("Tracks a Posthog interaction on change", () => { | ||
const trackInteractionSpy = jest.spyOn(PosthogTrackers, "trackInteraction"); | ||
|
||
const controller = new AnalyticsController("WebSettingsNotificationsTACOnlyNotificationsToggle"); | ||
|
||
controller.onChange(SettingLevel.DEVICE, null, false); | ||
|
||
expect(trackInteractionSpy).toHaveBeenCalledWith("WebSettingsNotificationsTACOnlyNotificationsToggle"); | ||
}); | ||
}); |
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