Files
Amit SharmaandGitHub 81224f324a feat: google ads conversion tracking (#25198)
* feat: google ads conversion tracking

* gaClientid

* store gclid in stripe metadata

* tracking only in the us

* track google campaign id as well

* rename gclid -> google ads

* fix: build

* fix

* refactor

* fix: type check

* fix: type check

* fix: type check

* fix: type check

* fix: store it in cookie

* refactor

* fix

* cleanup

* linked ads tracking

* refactor checkout session tracking
2025-11-25 12:58:10 +00:00

45 lines
1.2 KiB
TypeScript

import type { NextApiRequest } from "next";
import { createDefaultAIPhoneServiceProvider } from "@calcom/features/calAIPhone";
import { getTrackingFromCookies } from "@calcom/lib/tracking";
import { TRPCError } from "@trpc/server";
import type { TrpcSessionUser } from "../../../types";
import type { TBuyInputSchema } from "./buy.schema";
type BuyHandlerOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
req?: NextApiRequest;
};
input: TBuyInputSchema;
};
export const buyHandler = async ({ ctx, input }: BuyHandlerOptions) => {
const userId = ctx.user.id;
const aiService = createDefaultAIPhoneServiceProvider();
const tracking = getTrackingFromCookies(ctx.req?.cookies);
const checkoutSession = await aiService.generatePhoneNumberCheckoutSession({
userId,
teamId: input?.teamId ?? undefined,
agentId: input.agentId,
workflowId: input.workflowId,
tracking,
});
if (checkoutSession) {
return {
checkoutUrl: checkoutSession.url,
message: checkoutSession.message,
phoneNumber: null,
};
}
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Phone number billing is required but not configured.",
});
};