Skip to content

Commit

Permalink
Logsnag
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Jan 3, 2024
1 parent 7769efa commit d5f94d9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
24 changes: 24 additions & 0 deletions apps/website/src/actions/subscribeEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import { LogSnag } from "@logsnag/next/server";
import { getCountryCode } from "@midday/location";

const logsnag = new LogSnag({
token: process.env.LOGSNAG_TOKEN!,
project: process.env.LOGSNAG_PROJECT!,
});

export async function subscribeEmail(formData: FormData, userGroup: string) {
const email = formData.get("email");
const country = await getCountryCode();
Expand All @@ -25,5 +30,24 @@ export async function subscribeEmail(formData: FormData, userGroup: string) {

const json = await res.json();

if (email) {
logsnag.insight.increment({
title: "User Waitlist Count",
value: 1,
icon: "👨",
});

logsnag.track({
channel: "acquisition",
event: "User Joined Waitlist",
notify: true,
icon: "⭐",
user_id: email?.toString(),
properties: {
email: email?.toString(),
},
});
}

return json;
}
19 changes: 4 additions & 15 deletions apps/website/src/components/startpage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { subscribeEmail } from "@/actions/subscribeEmail";
import { useScopedI18n } from "@/locales/client";
import { useLogSnag } from "@logsnag/next";
import { Icons } from "@midday/ui/icons";
import { Loader2 } from "lucide-react";
import Image from "next/image";
Expand Down Expand Up @@ -45,7 +44,6 @@ function SubmitButton() {
export function StartPage() {
const t = useScopedI18n("startpage");
const [isSubmitted, setSubmitted] = useState(false);
const { setUserId, track, identify } = useLogSnag();

return (
<div className="h-screen relative min-h-[770px] md:min-h-[1100px] dark:md:min-h-[1180px]">
Expand Down Expand Up @@ -83,20 +81,11 @@ export function StartPage() {
<form
action={async (formData) => {
await subscribeEmail(formData, "pre-launch");
const email = formData.get("email")?.toString();

track({
channel: "acquisition",
event: "User Joined Waitlist",
notify: true,
icon: "⭐",
user_id: email,
properties: {
email,
},
});

setSubmitted(true);

setTimeout(() => {
setSubmitted(false);
}, 5000);
}}
>
<fieldset className="relative z-50">
Expand Down

0 comments on commit d5f94d9

Please sign in to comment.