Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

feat: Install PostHog and implement data capture on various buttons #1437

Merged
merged 4 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"humanize-duration": "^3.27.1",
"onegraph-apollo-client": "^3.1.2",
"onegraph-auth": "^4.0.2",
"posthog-js": "^1.20.4",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-hot-keys": "^2.7.1",
Expand Down
13 changes: 11 additions & 2 deletions src/components/CreateGoals.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import api from "../lib/apiGraphQL";
import {goalsReducer} from "../lib/reducers";
import {devProductive} from "../illustrations";
import Cards from "./Card";
import {CreateGoalsContainer, OnBoardingText} from "../styles/Container"
import {CreateGoalsContainer, OnBoardingText} from "../styles/Container";
import {capturePostHogAnayltics} from "../lib/analytics";

function CreateApp() {
return (
Expand All @@ -31,6 +32,8 @@ function CreateApp() {
function CreateGoals({installNeeded, user, onRepoCreation}) {
const [installReady, setInstallReady] = useState(installNeeded);
const _handleRepoCreation = () => {
capturePostHogAnayltics('Onboarding Flow', 'repoCreationBtn', 'clicked');

api.fetchOwnerId(user.login).then(ownerRes => {
const {
data: {
Expand Down Expand Up @@ -96,7 +99,13 @@ function CreateGoals({installNeeded, user, onRepoCreation}) {
rel="noreferrer"
target="_blank"
href={`https://github.com/apps/open-sauced/installations/new/permissions?target_id=${user && user.id}`}>
<Button primary minWidth={175} maxWidth={175} disabled={!installReady}>Create database</Button>
<Button
primary minWidth={175}
maxWidth={175}
disabled={!installReady}
onClick={() => capturePostHogAnayltics('Onboarding Flow', 'databaseCreationbtn', 'clicked')}>
Create database
</Button>
</a>
</SpaceBetween>
</Cards>
Expand Down
6 changes: 6 additions & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import api from "./lib/apiGraphQL";
import {getAppVersion} from "./lib/appVersion";
import {validateToken} from "./lib/validateToken";
import { registerSW } from 'virtual:pwa-register';
import { initiatePostHog, capturePostHogAnayltics } from "./lib/analytics";

const apolloClient = new OneGraphApolloClient({
oneGraphAuth: Config.auth,
Expand All @@ -24,6 +25,8 @@ function Index() {
const [isAdmin, setIsAdmin] = useState(null);

useEffect(() => {
initiatePostHog();

registerSW({
immediate: true,
onNeedRefresh: () => {
Expand Down Expand Up @@ -76,6 +79,9 @@ function Index() {

const _handleLogIn = () => {
const auth = Config.auth;

capturePostHogAnayltics('User Login', 'userLogin', 'true');

auth
.login("github")
.then(() => {
Expand Down
25 changes: 25 additions & 0 deletions src/lib/analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import posthog from "posthog-js";

function initiatePostHog () {
posthog.init(process.env.POSTHOG_ID, { api_host: 'https://app.posthog.com' });
return;
}

function capturePostHogAnayltics ( analyticsTitle, analyticsProperty, analyticsValue) {
const propertyIsMissingOrIncorrectType = !(typeof analyticsTitle === "string" &&
typeof analyticsProperty == "string" &&
analyticsValue);
if(propertyIsMissingOrIncorrectType) throw new Error("Property is missing or is incorrect type.");

const analyticsObject = {};
analyticsObject[analyticsProperty] = analyticsValue;

posthog.capture(analyticsTitle, analyticsObject);

return;
}

export {
initiatePostHog,
capturePostHogAnayltics
};