-
Notifications
You must be signed in to change notification settings - Fork 946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(reactotron-app): Add basic analytics to Reactotron app with react-ga4
#1406
Draft
markrickert
wants to merge
11
commits into
master
Choose a base branch
from
mrickert/feat/analytics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8d6e249
Add react-ga4 for analytics tracking.
markrickert 327879e
Add automatic page tracking.
markrickert 0ca34ea
Add a lot of analytics events for the app.
markrickert 1a5002f
Implement a custom alert that asks the user if they want analytics en…
markrickert 03eda42
Allow the opt out status be a string or number.
markrickert 8bb9dc5
Add analytics event to docs link
markrickert 587a5ff
Fix the types on the electron-store configStore.
markrickert cefdb24
Adds better types for analytics categories and actions
markrickert 6fa3ad6
Remove react-confirm-alert and use our own UI
markrickert 1ce3ae7
Send an opt-out event when the user opt-sout. Then no more logs.
markrickert 44dd363
Merge branch 'master' into mrickert/feat/analytics
jamonholmgren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
118 changes: 118 additions & 0 deletions
118
apps/reactotron-app/src/renderer/components/AnalyticsOptOut/index.tsx
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,118 @@ | ||
import React from "react" | ||
import styled, { useTheme } from "styled-components" | ||
import FadeIn from "react-fade-in" | ||
import { reactotronAnalytics } from "../../images" | ||
import configStore from "../../config" | ||
import { useAnalytics } from "../../util/analyticsHelpers" | ||
|
||
const Overlay = styled.div` | ||
position: absolute; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
display: flex; | ||
background-color: ${(props) => props.theme.backgroundLighter}; | ||
justify-content: center; | ||
align-items: center; | ||
` | ||
|
||
const AlertContainer = styled.div` | ||
padding: 30px; | ||
text-align: left; | ||
border-radius: 10px; | ||
background: ${(props) => props.theme.backgroundDarker}; | ||
color: ${(props) => props.theme.foregroundLight}; | ||
|
||
box-shadow: 0 20px 75px ${(props) => props.theme.backgroundSubtleLight}; | ||
width: 80%; | ||
max-width: 500px; | ||
` | ||
|
||
const AlertHeader = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
margin-bottom: 20px; | ||
` | ||
|
||
const AlertHeaderImage = styled.img` | ||
height: 128px; | ||
` | ||
|
||
const ButtonGroup = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: flex-start; | ||
margin-top: 20px; | ||
` | ||
|
||
const Button = styled.button` | ||
outline: none; | ||
background: ${(props) => props.theme.backgroundLighter}; | ||
border: none; | ||
display: inline-block; | ||
padding: 6px 18px; | ||
color: ${(props) => props.theme.background}; | ||
margin-right: 10px; | ||
border-radius: 5px; | ||
font-size: 16px; | ||
cursor: pointer; | ||
` | ||
|
||
// This is a custom alert that we use to ask the user if they want to opt-in to analytics | ||
// We use this instead of the default alert because we want to style it to match our app. | ||
const AnalyticsOptOut = ({ onClose }) => { | ||
const theme = useTheme() | ||
const { sendOptOutAnalyticsEvent } = useAnalytics() | ||
|
||
return ( | ||
<FadeIn wrapperTag={Overlay}> | ||
<AlertContainer> | ||
<AlertHeader> | ||
<AlertHeaderImage src={reactotronAnalytics} /> | ||
</AlertHeader> | ||
<h1>Opt in to Reactotron analytics?</h1> | ||
<p>Help us improve Reactotron!</p> | ||
<p> | ||
We'd like to collect anonymous usage data to enhance Reactotron's performance | ||
and features. This data includes general usage patterns and interactions. No personal | ||
information will be collected. | ||
</p> | ||
<p> | ||
You can change this setting at any time and by opting in, you can contribute to making | ||
Reactotron better for everyone! | ||
</p> | ||
<p>Would you like to participate?</p> | ||
<ButtonGroup> | ||
<Button | ||
onClick={() => { | ||
configStore.set("analyticsOptOut", true) | ||
sendOptOutAnalyticsEvent() | ||
onClose() | ||
}} | ||
style={{ | ||
backgroundColor: theme.tag, | ||
}} | ||
> | ||
No, don't collect any data | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
configStore.set("analyticsOptOut", false) | ||
onClose() | ||
}} | ||
style={{ | ||
marginTop: 20, | ||
backgroundColor: theme.string, | ||
fontWeight: "bold", | ||
}} | ||
> | ||
Yes, I understand no personal information will be collected | ||
</Button> | ||
</ButtonGroup> | ||
</AlertContainer> | ||
</FadeIn> | ||
) | ||
} | ||
|
||
export default AnalyticsOptOut |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const reactotronLogo: string = require("./Reactotron-128.png").default | ||
export const reactotronAnalytics: string = require("./Reactotron-analytics.png").default | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's throw this over to Justin and see what he'd like graphic wise. |
||
export const storybookActiveImg: string = require("./storybook-logo-color.png").default | ||
export const storybookInactiveImg: string = require("./storybook-logo.png").default |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are we waiting for here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While developing, I found that there was the possibility of this component rendering a couple times. This delay with the clearTimeout is meant to only initialize the analytics once the electron renderer process has completely opened the app and react has stopped reacting. Not sure if there's a better way to handle this other than some memoizing