Skip to content

Commit 1a9d434

Browse files
committed
Implement a custom alert that asks the user if they want analytics enabled.
1 parent d63bb4f commit 1a9d434

File tree

10 files changed

+322
-118
lines changed

10 files changed

+322
-118
lines changed

apps/reactotron-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"electron-window-state": "^5.0.3",
5858
"immer": "^10.0.3",
5959
"react": "18.2.0",
60+
"react-confirm-alert": "^3.0.6",
6061
"react-dom": "18.2.0",
6162
"react-ga4": "^2.1.0",
6263
"react-hotkeys": "^2.0.0",

apps/reactotron-app/src/main/menu.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Menu, app, shell } from "electron"
2-
import Store from "electron-store"
3-
4-
const configStore = new Store()
2+
import configStore from "../renderer/config"
53

64
const isDarwin = process.platform === "darwin"
75

apps/reactotron-app/src/renderer/App.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react"
1+
import React, { useEffect } from "react"
22
import { HashRouter as Router, Route, Routes } from "react-router-dom"
33
import styled from "styled-components"
44

@@ -15,7 +15,7 @@ import Overlay from "./pages/reactNative/Overlay"
1515
import Storybook from "./pages/reactNative/Storybook"
1616
import CustomCommands from "./pages/customCommands"
1717
import Help from "./pages/help"
18-
import { usePageTracking } from "./util/analyticsHelpers"
18+
import { useAnalytics, usePageTracking } from "./util/analyticsHelpers"
1919

2020
const AppContainerComponent = styled.div`
2121
position: absolute;
@@ -28,8 +28,20 @@ const AppContainerComponent = styled.div`
2828
flex-direction: column;
2929
background-color: ${(props) => props.theme.background};
3030
`
31+
32+
// This wrapper container is used to track page views within the app automatically using react-router-dom
33+
// as well as to initialize analytics on app load.
3134
const AppContainer: React.FC<{ children: React.ReactNode }> = ({ children }) => {
3235
usePageTracking()
36+
const { initializeAnalytics } = useAnalytics()
37+
38+
useEffect(() => {
39+
const timer = setTimeout(() => {
40+
initializeAnalytics()
41+
}, 250)
42+
return () => clearTimeout(timer)
43+
}, [])
44+
3345
return <AppContainerComponent>{children}</AppContainerComponent>
3446
}
3547

apps/reactotron-app/src/renderer/KeybindHandler.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ function KeybindHandler({ children }) {
101101
// Tab Navigation
102102
OpenHomeTab: () => {
103103
window.location.hash = "/"
104-
105104
sendKeyboardShortcutAnalyticsEvent("OpenHomeTab")
106105
},
107106
OpenTimelineTab: () => {
@@ -137,6 +136,7 @@ function KeybindHandler({ children }) {
137136
},
138137
TakeSnapshot: () => {
139138
createSnapshot()
139+
sendKeyboardShortcutAnalyticsEvent("TakeSnapshot")
140140
},
141141

142142
// Miscellaneous

apps/reactotron-app/src/renderer/config.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,41 @@ const schema = {
99
type: "number",
1010
default: 500,
1111
},
12+
analyticsOptOut: {
13+
type: "string",
14+
default: "unknown",
15+
},
1216
}
1317

14-
const configStore = new Store({ schema } as any)
18+
const configStore = new Store({
19+
schema,
20+
defaults: {
21+
serverPort: schema.serverPort.default,
22+
commandHistory: schema.commandHistory.default,
23+
analyticsOptOut: schema.analyticsOptOut.default,
24+
},
25+
beforeEachMigration: (_store, context) => {
26+
console.log(`[main-config] migrate from ${context.fromVersion}${context.toVersion}`)
27+
},
28+
migrations: {
29+
"1.0.0": (store) => {
30+
// Added analyticsOptOut in order to track if the user has opted out of analytics
31+
// and present the user with a blocking dialog box.
32+
// When the user makes a choice, it will be set to "true" or "false"
33+
store.set("analyticsOptOut", "unknown")
34+
},
35+
},
36+
} as any)
1537

1638
// Setup defaults
1739
if (!configStore.has("serverPort")) {
18-
configStore.set("serverPort", 9090)
40+
configStore.set("serverPort", schema.serverPort.default)
1941
}
2042
if (!configStore.has("commandHistory")) {
21-
configStore.set("commandHistory", 500)
43+
configStore.set("commandHistory", schema.commandHistory.default)
44+
}
45+
if (!configStore.has("analyticsOptOut")) {
46+
configStore.set("analyticsOptOut", schema.analyticsOptOut.default)
2247
}
2348

2449
export default configStore
277 KB
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const reactotronLogo: string = require("./Reactotron-128.png").default
2+
export const reactotronAnalytics: string = require("./Reactotron-analytics.png").default
23
export const storybookActiveImg: string = require("./storybook-logo-color.png").default
34
export const storybookInactiveImg: string = require("./storybook-logo.png").default

apps/reactotron-app/src/renderer/util/analyticsHelpers.ts

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)