Skip to content

Commit

Permalink
Merge pull request #632 from tone-row/dev
Browse files Browse the repository at this point in the history
v1.45.4
  • Loading branch information
rob-gordon authored Dec 16, 2023
2 parents e40696d + 66ad7f8 commit eb5652b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "app",
"version": "1.45.3",
"version": "1.45.4",
"main": "module/module.js",
"license": "MIT",
"scripts": {
Expand Down
32 changes: 30 additions & 2 deletions app/src/lib/sendLoopsEvent.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
// keep a simple cache that prevents the same loops event from being sent twice
// in the same session
const sentEvents = new Set<string>();

export function sendLoopsEvent(body: { email: string; eventName: string }) {
if (process.env.REACT_APP_VERCEL_ENV !== "production") return;
if (process.env.REACT_APP_VERCEL_ENV !== "production") {
console.log("Not sending loops event in dev mode");
return;
}

const key = `${body.email}:${body.eventName}`;
if (sentEvents.has(key)) {
console.log(
`Loops event: ${body.eventName} for ${body.email} already sent`
);
return;
}
sentEvents.add(key);

console.log(`Loops event: ${body.eventName} for ${body.email} sent`);

fetch("/api/loops-event", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body),
});
})
.then((res) => {
if (!res.ok) {
console.error("Failed to send loops event", res);
} else {
console.log("Sent loops event", body);
}
})
.catch((err) => {
console.error("Failed to send loops event", err);
});
}

export function loopsNewSubscriber(email: string) {
Expand Down

1 comment on commit eb5652b

@vercel
Copy link

@vercel vercel bot commented on eb5652b Dec 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.