Skip to content

Commit

Permalink
feat: Add event tracking for Lens authorization and verification routes
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Mar 1, 2025
1 parent 7db3587 commit 8a470a6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions apps/api/src/helpers/trackEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Errors } from "@hey/data/errors";
import axios from "axios";

const trackEvent = async (event: string, metadata?: Record<string, any>) => {
try {
const { data } = await axios.post(
"https://queue.simpleanalyticscdn.com/events",
{
type: "event",
hostname: "hey.xyz",
ua: "HeyServer/0.1 (+https://hey.xyz)",
event,
metadata
},
{ headers: { "Content-Type": "application/json" } }
);

return data;
} catch {
throw new Error(Errors.SomethingWentWrong);
}
};

export default trackEvent;
3 changes: 3 additions & 0 deletions apps/api/src/routes/lens/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Request, Response } from "express";
import catchedError from "src/helpers/catchedError";
import { VERIFICATION_ENDPOINT } from "src/helpers/constants";
import { noBody } from "src/helpers/responses";
import trackEvent from "src/helpers/trackEvent";

export const post = async (req: Request, res: Response) => {
const { body } = req;
Expand Down Expand Up @@ -35,6 +36,8 @@ export const post = async (req: Request, res: Response) => {
});
}

trackEvent("authorization");

return res.status(200).json({
allowed: true,
sponsored: true,
Expand Down
3 changes: 3 additions & 0 deletions apps/api/src/routes/lens/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Request, Response } from "express";
import catchedError from "src/helpers/catchedError";
import { heyWalletClient } from "src/helpers/heyWalletClient";
import { noBody } from "src/helpers/responses";
import trackEvent from "src/helpers/trackEvent";
import { type Address, checksumAddress } from "viem";

const TYPES = {
Expand Down Expand Up @@ -81,6 +82,8 @@ export const post = async (req: Request, res: Response) => {
});
}

trackEvent("verification", { operation });

return res.status(200).json({ allowed: true, signature });
} catch (error) {
return catchedError(res, error);
Expand Down

0 comments on commit 8a470a6

Please sign in to comment.