Skip to content

Commit e35611b

Browse files
Merge pull request OwnTube-tv#435 from mykhailodanilenko/feature/finalize-diagnostics-events
Add remaining analytics events and opt-out functionality
2 parents 694e198 + e48d129 commit e35611b

File tree

23 files changed

+101
-30
lines changed

23 files changed

+101
-30
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "react-native-device-info/jest/react-native-device-info-mock";

OwnTube.tv/api/axiosInstance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { useAuthSessionStore } from "../store";
33
import { parseISOToEpoch } from "../utils";
44
import { parseAuthSessionData } from "../utils/auth";
55
import { OAuthClientLocal, UserLogin } from "@peertube/peertube-types";
6-
import { APP_IDENTIFIER } from "./constants";
76
import { postHogInstance } from "../diagnostics";
87
import { CustomPostHogEvents, CustomPostHogExceptions } from "../diagnostics/constants";
8+
import { APP_IDENTIFIER } from "./sharedConstants";
99

1010
export const axiosInstance = axios.create({
1111
withCredentials: false,

OwnTube.tv/api/constants.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { VideosCommonQuery } from "@peertube/peertube-types";
2-
import buildInfo from "../build-info.json";
32

43
// Common query parameters for fetching videos that are classified as "local", "non-live", and "Safe-For-Work"
54
export const commonQueryParams: VideosCommonQuery = {
@@ -49,5 +48,3 @@ export enum MUTATION_KEYS {
4948
export const WRONG_SERVER_VERSION_STATUS_CODE = 444;
5049

5150
export const GLOBAL_QUERY_STALE_TIME = 3_600_000; // 1 hour in ms
52-
53-
export const APP_IDENTIFIER = `${buildInfo.GITHUB_REPOSITORY}@${buildInfo.GITHUB_SHA_SHORT} (https://github.com/${buildInfo.GITHUB_ACTOR})`;

OwnTube.tv/api/sharedConstants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import buildInfo from "../build-info.json";
2+
3+
export const APP_IDENTIFIER = `${buildInfo.GITHUB_REPOSITORY}@${buildInfo.GITHUB_SHA_SHORT} (https://github.com/${buildInfo.GITHUB_ACTOR})`;

OwnTube.tv/components/ComboBoxInput/ComboBoxInput.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const ComboBoxInput = ({
1515
width,
1616
allowCustomOptions,
1717
getCustomOptionText,
18+
onChangeText,
1819
}: ComboBoxInputProps) => {
1920
const { colors } = useTheme();
2021
const modalControls = useFullScreenModalContext();
@@ -49,6 +50,7 @@ const ComboBoxInput = ({
4950
modalControls.toggleModal(true);
5051
modalControls.setContent(modalContent);
5152
}}
53+
onChangeText={onChangeText}
5254
editable={false}
5355
placeholder={placeholder}
5456
placeholderTextColor={colors.text}

OwnTube.tv/components/ComboBoxInput/ComboBoxInput.web.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const ComboBoxInput = ({
1515
width,
1616
allowCustomOptions,
1717
getCustomOptionText,
18+
onChangeText,
1819
}: ComboBoxInputProps) => {
1920
const { colors } = useTheme();
2021
const listRef = useRef<FlatList | null>(null);
@@ -26,6 +27,11 @@ const ComboBoxInput = ({
2627
[value, onSelect],
2728
);
2829

30+
const handleTextChange = (text: string) => {
31+
setInputValue(text);
32+
onChangeText?.(text);
33+
};
34+
2935
return (
3036
<View
3137
testID={testID}
@@ -47,7 +53,7 @@ const ComboBoxInput = ({
4753
}, 300);
4854
}}
4955
value={inputValue}
50-
onChangeText={setInputValue}
56+
onChangeText={handleTextChange}
5157
onSubmitEditing={(event) => {
5258
if (allowCustomOptions && event.nativeEvent.text && getCustomOptionText) {
5359
onSelect({ label: getCustomOptionText(event.nativeEvent.text), value: event.nativeEvent.text })();

OwnTube.tv/components/ComboBoxInput/models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ export interface ComboBoxInputProps {
1212
width?: number;
1313
allowCustomOptions?: boolean;
1414
getCustomOptionText?: (input: string) => string;
15+
onChangeText?: (text: string) => void;
1516
}

OwnTube.tv/components/VideoControlsOverlay/components/modals/Settings.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import DeviceCapabilities from "../../../DeviceCapabilities";
1818
import Picker from "../../../shared/Picker";
1919
import { useGetInstanceInfoQuery } from "../../../../api";
2020
import { usePostHog } from "posthog-react-native/lib/posthog-react-native/src/hooks/usePostHog";
21+
import { useState } from "react";
22+
import { PostHogPersistedProperty } from "posthog-react-native/lib/posthog-core/src/types";
2123

2224
interface SettingsProps {
2325
onClose: () => void;
@@ -33,6 +35,9 @@ export const Settings = ({ onClose }: SettingsProps) => {
3335

3436
const { data: instanceInfo } = useGetInstanceInfoQuery(backend);
3537
const { currentInstanceConfig } = useAppConfigContext();
38+
const [isOptedOut, setIsOptedOut] = useState(
39+
posthog.getPersistedProperty(PostHogPersistedProperty.OptedOut) || false,
40+
);
3641

3742
const handleLeaveInstance = () => {
3843
writeToAsyncStorage(STORAGE.DATASOURCE, "").then(() => {
@@ -48,12 +53,16 @@ export const Settings = ({ onClose }: SettingsProps) => {
4853
const handleToggleDebugMode = (debugModeOn: boolean) => {
4954
setIsDebugMode(debugModeOn);
5055
writeToAsyncStorage(STORAGE.DEBUG_MODE, String(debugModeOn));
56+
};
5157

52-
if (debugModeOn) {
58+
const handleToggleOptOutCheckbox = (optOut: boolean) => {
59+
if (!optOut) {
5360
posthog.optIn();
5461
} else {
5562
posthog.optOut();
5663
}
64+
65+
setIsOptedOut(optOut);
5766
};
5867

5968
return (
@@ -78,7 +87,14 @@ export const Settings = ({ onClose }: SettingsProps) => {
7887
items={LANGUAGE_OPTIONS}
7988
/>
8089
<Spacer height={spacing.xl} />
81-
<Checkbox checked={isDebugMode} onChange={handleToggleDebugMode} label={t("debugLogging")} />
90+
<Checkbox
91+
disabled={isOptedOut}
92+
checked={isDebugMode && !isOptedOut}
93+
onChange={handleToggleDebugMode}
94+
label={t("debugLogging")}
95+
/>
96+
<Spacer height={spacing.md} />
97+
<Checkbox checked={isOptedOut} onChange={handleToggleOptOutCheckbox} label={t("optOutOfDiagnostics")} />
8298
<Spacer height={spacing.xl} />
8399
{!primaryBackend && (
84100
<>

OwnTube.tv/components/VideoView/VideoView.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ const VideoView = ({
378378
});
379379
};
380380

381+
const handleSetSpeed = (speed: number) => {
382+
setPlaybackSpeed(speed);
383+
captureDiagnosticsEvent(CustomPostHogEvents.PlaybackSpeedChanged, { playbackSpeed: speed });
384+
};
385+
381386
const allowQualityControls = Platform.OS !== "ios" || !videoData?.streamingPlaylists?.length;
382387

383388
return (
@@ -410,7 +415,7 @@ const VideoView = ({
410415
handleShare={handleShare}
411416
handleOpenSettings={handleOpenSettings}
412417
handleHideOverlay={hideOverlay}
413-
handleSetSpeed={setPlaybackSpeed}
418+
handleSetSpeed={handleSetSpeed}
414419
speed={playbackSpeed}
415420
selectedQuality={selectedQuality}
416421
handleSetQuality={allowQualityControls ? handleSetQuality : undefined}

OwnTube.tv/components/VideoView/VideoView.web.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ const VideoView = ({
543543
};
544544

545545
const handleSetSpeed = (speed: number) => {
546+
captureDiagnosticsEvent(CustomPostHogEvents.PlaybackSpeedChanged, { playbackSpeed: speed });
546547
playerRef.current?.playbackRate(speed);
547548
};
548549
const [isCCShown, setIsCCShown] = useState(false);

0 commit comments

Comments
 (0)