Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
Feature/posthog analytics (#204)
Browse files Browse the repository at this point in the history
* Add posthogjs

* Create providers.tsx

* Add posthog

* Add posthognode

* Create posthogTracker.ts

* Add tracker to gh action

* make posthog early

* fix list filtering

* Rename tracker

* Add tracker

* Add tracker

* Streamline data fetching

* Add tracker
  • Loading branch information
EstebanDalelR committed Aug 4, 2023
1 parent c047847 commit 655a195
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 23 deletions.
44 changes: 28 additions & 16 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import "@primer/css/index.scss";

import AuthProvider from "../lib/auth/AuthProvider";
import Navbar from "../components/Navbar";
import { getServerSession } from "next-auth";

import Navbar from "../components/Navbar";
import Header from "../components/Header";
import { authOptions } from "./api/auth/[...nextauth]/route";
import LogInBtn from "../components/login-btn";

import AuthProvider from "../lib/auth/AuthProvider";

import { PHProvider, PostHogPageview } from "./providers";

import { authOptions } from "./api/auth/[...nextauth]/route";
import { ReactNode, Suspense } from "react";

export const metadata = {
title: {
template: "%s | Watermelon",
Expand All @@ -17,26 +24,31 @@ export const metadata = {
export default async function RootLayout({
children,
}: {
children: React.ReactNode;
children: ReactNode;
}) {
const session = await getServerSession(authOptions);
let userEmail = session?.user?.email;
let userName = session?.user?.name;

return (
<html lang="en" data-color-mode="dark" data-dark-theme="dark">
<body>
{userEmail ? (
<>
<Header userEmail={userEmail} userToken={userName} />
<Navbar>
<AuthProvider>{children}</AuthProvider>
</Navbar>
</>
) : (
<LogInBtn />
)}
</body>
<Suspense fallback={null}>
<PostHogPageview />
</Suspense>
<PHProvider>
<body>
{userEmail ? (
<>
<Header userEmail={userEmail} userToken={userName} />
<Navbar>
<AuthProvider>{children}</AuthProvider>
</Navbar>
</>
) : (
<LogInBtn />
)}
</body>
</PHProvider>
</html>
);
}
26 changes: 19 additions & 7 deletions pages/api/actions/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import linearMarkdown from "../../../utils/actions/markdownHelpers/linear";
import countMarkdown from "../../../utils/actions/markdownHelpers/count";

import addActionLog from "../../../utils/db/github/addActionLog";
import PostHogTracker from "../../../lib/track/posthogTracker";
const app = new App({
appId: process.env.GITHUB_APP_ID!,
privateKey: process.env.GITHUB_PRIVATE_KEY!,
Expand Down Expand Up @@ -301,12 +302,10 @@ export default async (req, res) => {
searchStringSet
.concat(` ${title.split("/").join(" ")}`)
.concat(` ${body}`.split("\n").join(" "))
.split("\n")
.flatMap((line) => line.split(","))
.map((commit: string) => commit.toLowerCase())
.filter((commit) => !stopwords.includes(commit))
.join(" ")
.split(" ")
.flatMap((word) => word.split(","))
.map((word: string) => word.toLowerCase())
.filter((word) => !stopwords.includes(word))
)
).join(" ");
// select six random words from the search string
Expand Down Expand Up @@ -376,7 +375,8 @@ export default async (req, res) => {
if (businessLogicSummary) {
textToWrite += businessLogicSummary;
} else {
textToWrite += "Error getting summary" + businessLogicSummary.error + "\n";
textToWrite +=
"Error getting summary" + businessLogicSummary.error + "\n";
}
} else {
textToWrite += `AI Summary deactivated by ${userLogin} \n`;
Expand Down Expand Up @@ -412,6 +412,19 @@ export default async (req, res) => {
isPrivateRepo: repository.private,
repoName: repo,
});

PostHogTracker().capture({
distinctId: watermelon_user,
event: "GitHub Action",
properties: {
user: userLogin,
owner,
repo,
action: payload.action,
//@ts-ignore
issue_number: number,
},
});
await addActionLog({
randomWords,
ghValue,
Expand All @@ -428,7 +441,6 @@ export default async (req, res) => {
count,
watermelon_user,
});

// Fetch all comments on the PR
const comments = await octokit.request(
"GET /repos/{owner}/{repo}/issues/{issue_number}/comments?sort=created&direction=desc",
Expand Down
1 change: 1 addition & 0 deletions pages/api/extension/getContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import getAllData from "../../../utils/db/user/getAllData";
import updateTokensFromJira from "../../../utils/jira/updateTokens";
import updateTokens from "../../../utils/db/jira/updateTokens";
import searchMessageByText from "../../../utils/slack/searchMessageByText";
import PostHogTracker from "../../../lib/track/posthogTracker";
function replaceSpecialChars(inputString) {
const specialChars = /[!"#$%&/()=?_"{}¨*]/g; // Edit this list to include or exclude characters
return inputString.toLowerCase().replace(specialChars, " ");
Expand Down
1 change: 1 addition & 0 deletions pages/api/hover/getHoverData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { trackEvent } from "../../../utils/analytics/azureAppInsights";
import updateTokensFromJira from "../../../utils/jira/updateTokens";
import updateTokens from "../../../utils/db/jira/updateTokens";
import searchMessageByText from "../../../utils/slack/searchMessageByText";
import PostHogTracker from "../../../lib/track/posthogTracker";
function replaceSpecialChars(inputString) {
const specialChars = /[!"#$%&/()=?_"{}¨*]/g; // Edit this list to include or exclude characters
return inputString.toLowerCase().replace(specialChars, " ");
Expand Down

0 comments on commit 655a195

Please sign in to comment.