Skip to content

Commit

Permalink
Implement basic event capture
Browse files Browse the repository at this point in the history
  • Loading branch information
sepal committed Oct 30, 2023
1 parent 9e49be8 commit 75b69c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/components/Analytics.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
"use client";
import { useJune } from "@/lib/hooks/useJune";
import { useAuth, useUser } from "@clerk/nextjs";
import { usePostHog } from "posthog-js/react";
import { useEffect } from "react";

const UserAnalytics = () => {
const { isLoaded, isSignedIn, user } = useUser();
const analytics = useJune();
const posthog = usePostHog();
useEffect(() => {
if (!isLoaded || !isSignedIn || !user) {
return;
}
posthog.identify(user.id, {
email: user.emailAddresses[0].emailAddress,
});
}, []);

if (!isLoaded || !isSignedIn || !user) {
return null;
Expand All @@ -14,6 +25,7 @@ const UserAnalytics = () => {
email: user.emailAddresses[0].emailAddress,
avatar: user.imageUrl,
});

return <></>;
};

Expand Down
11 changes: 8 additions & 3 deletions src/components/Editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useRouter } from "next/navigation";
import { useJune } from "@/lib/hooks/useJune";
import { ArrowDownTrayIcon } from "@heroicons/react/24/solid";
import { cn } from "@/lib/utils";
import { usePostHog } from "posthog-js/react";

enum State {
EMPTY_VIDEO,
Expand Down Expand Up @@ -51,6 +52,7 @@ const Editor = ({ defaultCredits, defaultMeme = undefined }: Props) => {
const [credits, setCredits] = useState<number | undefined>(defaultCredits);
const router = useRouter();
const analytics = useJune();
const posthog = usePostHog();

const getCredits = async () => {
const resp = await fetch("/api/user");
Expand Down Expand Up @@ -133,7 +135,8 @@ const Editor = ({ defaultCredits, defaultMeme = undefined }: Props) => {
e.preventDefault();
const text = prompt.trim();
if (text.length <= 3) return;
analytics?.track("Generate Video");
analytics?.track("generate_video");
posthog.capture("generate_video");
generateVideo();
}}
>
Expand Down Expand Up @@ -181,7 +184,8 @@ const Editor = ({ defaultCredits, defaultMeme = undefined }: Props) => {
onClick={(e) => {
e.preventDefault();
generateVideo();
analytics?.track("Retry generating Video");
analytics?.track("retry_generating_video");
posthog.capture("retry_generating_video");
}}
disabled={state == State.SAVING_MEME}
>
Expand All @@ -192,7 +196,8 @@ const Editor = ({ defaultCredits, defaultMeme = undefined }: Props) => {
e.preventDefault();
setState(State.SAVING_MEME);
await generateGif();
await analytics?.track("Save meme");
await analytics?.track("save_meme");
await posthog.capture("save_meme");
router.push(`/meme/${meme?.id}`);
}}
disabled={state == State.SAVING_MEME}
Expand Down

0 comments on commit 75b69c3

Please sign in to comment.