Skip to content

Commit 22e7137

Browse files
committed
Add telemetry to frontend
1 parent d70d1f2 commit 22e7137

File tree

7 files changed

+35
-14
lines changed

7 files changed

+35
-14
lines changed

frontend/components/analytics/posthog.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import posthog from "posthog-js";
2+
import { ENV, POSTHOG_API_KEY, POSTHOG_HOST, TELEMETRY_ENABLED } from "../utilities/config";
23

34
export const initPostHog = () => {
45
if (typeof window !== "undefined") {
5-
if (process.env.NEXT_PUBLIC_ENV == "production") {
6-
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_API_KEY, {
7-
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
6+
if (ENV == "production" && TELEMETRY_ENABLED) {
7+
posthog.init(POSTHOG_API_KEY, {
8+
api_host: POSTHOG_HOST,
89
});
910
}
1011
}

frontend/components/basic/dialog/AddUserDialog.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Fragment } from "react";
33
import InputField from "../InputField";
44
import { useRouter } from "next/router";
55
import Button from "../buttons/Button";
6+
import { STRIPE_PRODUCT_STARTER } from "../../utilities/config";
67

78
const AddUserDialog = ({
89
isOpen,
@@ -70,7 +71,7 @@ const AddUserDialog = ({
7071
isRequired
7172
/>
7273
</div>
73-
{currentPlan == process.env.NEXT_PUBLIC_STRIPE_PRODUCT_STARTER && <div className="flex flex-row">
74+
{currentPlan == STRIPE_PRODUCT_STARTER && <div className="flex flex-row">
7475
<button
7576
type="button"
7677
className="inline-flex justify-center rounded-md py-1 text-sm text-gray-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2"

frontend/components/dashboard/DashboardInputField.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import guidGenerator from "../utilities/randomId";
66

77
/**
88
* This function splits the input of a dashboard field into the parts that are inside and outside of ${...}
9-
* @param {*} text - the value of the input in the Dashboard Input Field
9+
* @param {string} text - the value of the input in the Dashboard Input Field
1010
* @returns
1111
*/
1212
const findReferences = (text) => {
@@ -25,11 +25,12 @@ const findReferences = (text) => {
2525

2626
/**
2727
* This component renders the input fields on the dashboard
28-
* @param {*} index - the order number of a keyPair
29-
* @param {*} onChangeHandler - what happens when the input is modified
30-
* @param {*} type - whether the input field is for a Key Name or for a Key Value
31-
* @param {*} value - value of the InputField
32-
* @param {*} blurred - whether the input field should be blurred (behind the gray dots) or not; this can be turned on/off in the dashboard
28+
* @param {object} obj - the order number of a keyPair
29+
* @param {number} obj.index - the order number of a keyPair
30+
* @param {function} obj.onChangeHandler - what happens when the input is modified
31+
* @param {string} obj.type - whether the input field is for a Key Name or for a Key Value
32+
* @param {string} obj.value - value of the InputField
33+
* @param {boolean} obj.blurred - whether the input field should be blurred (behind the gray dots) or not; this can be turned on/off in the dashboard
3334
* @returns
3435
*/
3536
const DashboardInputField = ({index, onChangeHandler, type, value, blurred}) => {

frontend/components/utilities/attemptLogin.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { initPostHog } from "../analytics/posthog";
66
import getOrganizations from "../../pages/api/organization/getOrgs";
77
import getOrganizationUserProjects from "../../pages/api/organization/GetOrgUserProjects";
88
import SecurityClient from "./SecurityClient";
9+
import { ENV } from "./config";
910

1011
const nacl = require("tweetnacl");
1112
nacl.util = require("tweetnacl-util");
@@ -154,7 +155,7 @@ const attemptLogin = async (
154155
}
155156
try {
156157
if (email) {
157-
if (process.env.NEXT_PUBLIC_ENV == "production") {
158+
if (ENV == "production") {
158159
const posthog = initPostHog();
159160
posthog.identify(email);
160161
posthog.capture("User Logged In");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const ENV = process.env.NEXT_PUBLIC_ENV! || 'development'; // investigate
2+
const POSTHOG_API_KEY = process.env.NEXT_PUBLIC_POSTHOG_API_KEY!;
3+
const POSTHOG_HOST = process.env.NEXT_PUBLIC_POSTHOG_HOST! || 'https://app.posthog.com';
4+
const STRIPE_PRODUCT_PRO = process.env.NEXT_PUBLIC_STRIPE_PRODUCT_PRO!;
5+
const STRIPE_PRODUCT_STARTER = process.env.NEXT_PUBLIC_STRIPE_PRODUCT_STARTER!;
6+
const TELEMETRY_ENABLED = (process.env.NEXT_PUBLIC_TELEMETRY_ENABLED! !== 'false');
7+
8+
export {
9+
ENV,
10+
POSTHOG_API_KEY,
11+
POSTHOG_HOST,
12+
STRIPE_PRODUCT_PRO,
13+
STRIPE_PRODUCT_STARTER,
14+
TELEMETRY_ENABLED
15+
};

frontend/pages/_app.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { publicPaths } from "../const.js";
77
import { useEffect } from "react";
88
import { useRouter } from "next/router";
99
import { initPostHog } from "../components/analytics/posthog";
10+
import { ENV } from "../components/utilities/config";
1011

1112
config.autoAddCss = false;
1213

@@ -20,7 +21,7 @@ const App = ({ Component, pageProps, ...appProps }) => {
2021

2122
const handleRouteChange = () => {
2223
if (typeof window !== "undefined") {
23-
if (process.env.NEXT_PUBLIC_ENV == "production") {
24+
if (ENV == "production") {
2425
posthog.capture("$pageview");
2526
}
2627
}

frontend/pages/settings/billing/[id].js

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Plan from "../../../components/billing/Plan";
44
import getOrganizationSubscriptions from "../../api/organization/GetOrgSubscription"
55
import getOrganizationUsers from "../../api/organization/GetOrgUsers"
66
import NavHeader from "../../../components/navigation/NavHeader";
7+
import { STRIPE_PRODUCT_PRO, STRIPE_PRODUCT_STARTER } from "../../../components/utilities/config";
78

89

910
export default function SettingsBilling() {
@@ -20,7 +21,7 @@ export default function SettingsBilling() {
2021
subtext: "$5 per member/month afterwards.",
2122
buttonTextMain: "Downgrade",
2223
buttonTextSecondary: "Learn More",
23-
current: currentPlan == process.env.NEXT_PUBLIC_STRIPE_PRODUCT_STARTER,
24+
current: currentPlan == STRIPE_PRODUCT_STARTER,
2425
},
2526
{
2627
key: 2,
@@ -31,7 +32,7 @@ export default function SettingsBilling() {
3132
text: "Keep up with key management as you grow.",
3233
buttonTextMain: "Upgrade",
3334
buttonTextSecondary: "Learn More",
34-
current: currentPlan == process.env.NEXT_PUBLIC_STRIPE_PRODUCT_PRO,
35+
current: currentPlan == STRIPE_PRODUCT_PRO,
3536
},
3637
{
3738
key: 3,

0 commit comments

Comments
 (0)