Skip to content
Open
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
40 changes: 36 additions & 4 deletions app/signup/EmailSignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,44 @@ export default function EmailSignupForm()
{
const [email, setEmail] = useState("");

function handleSubmit(event: React.FormEvent<HTMLFormElement>)
{
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();

// Placeholder: wire up server action / API route later
console.log("Email submitted:", email);
const sessionID = Math.random().toString(36).substring(7); // This is a temporary placeholder. You may replace it later.
const sourcePage = "Signup Page";

// Sending data to the API route
try {
const response = await fetch('/api/track', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
event_type: 'click_signup',
payload: {
email,
timestamp: new Date().toISOString(),
sourcePage,
sessionID,
},
}),
});

const result = await response.json();

if (response.ok) {
console.log('Email submitted successfully:', result);
alert('Thank you for subscribing!');
setEmail('');
} else {
console.error('Error:', result.error);
alert('Something went wrong. Please try again.');
}
} catch (error) {
console.error('Request failed', error);
alert('There was a problem with your submission. Please try again later.');
}
}

return (
Expand Down
3 changes: 3 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function middleware(req: any, res: any, next: () => void) {
// Your middleware logic here
}
56 changes: 28 additions & 28 deletions package-lock.json

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