feat: add utm tracking on booking (#19965)
* add tracking to booking + pass to handleNewBooking * save tracking to booking * return undefined if no utm params * add test for handleNewBooking * fix type error in test * refactor code * code clean up * code clean up * add missing import * fix type import * add utm params to insights (#20063) * add utm params to insights * remove duplicates * remove duplicate columns --------- Co-authored-by: CarinaWolli <[email protected]> --------- Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: Omar López <[email protected]>
This commit is contained in:
16 files changed
+354
-4
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import { useSearchParams } from "next/navigation";
|
||||
|
||||
import { useIsPlatform } from "@calcom/atoms/hooks/useIsPlatform";
|
||||
import { useBookerTime } from "@calcom/features/bookings/Booker/components/hooks/useBookerTime";
|
||||
import type { UseBookingFormReturnType } from "@calcom/features/bookings/Booker/components/hooks/useBookingForm";
|
||||
@@ -10,6 +12,7 @@ import type { RoutingFormSearchParams } from "@calcom/platform-types";
|
||||
import type { BookingCreateBody } from "@calcom/prisma/zod/custom/booking";
|
||||
import { showToast } from "@calcom/ui";
|
||||
|
||||
import { getUtmTrackingParameters } from "../../lib/getUtmTrackingParameters";
|
||||
import type { UseCreateBookingInput } from "./useCreateBooking";
|
||||
|
||||
type Callbacks = { onSuccess?: () => void; onError?: (err: any) => void };
|
||||
@@ -62,6 +65,7 @@ export const useHandleBookEvent = ({
|
||||
const errorMessage = err?.message ? t(err.message) : t("can_you_try_again");
|
||||
showToast(errorMessage, "error");
|
||||
};
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const handleBookEvent = (inputTimeSlot?: string) => {
|
||||
const values = bookingForm.getValues();
|
||||
@@ -109,12 +113,17 @@ export const useHandleBookEvent = ({
|
||||
routingFormSearchParams,
|
||||
};
|
||||
|
||||
const tracking = getUtmTrackingParameters(searchParams);
|
||||
|
||||
if (isInstantMeeting) {
|
||||
handleInstantBooking(mapBookingToMutationInput(bookingInput), callbacks);
|
||||
} else if (event.data?.recurringEvent?.freq && recurringEventCount && !rescheduleUid) {
|
||||
handleRecBooking(mapRecurringBookingToMutationInput(bookingInput, recurringEventCount), callbacks);
|
||||
handleRecBooking(
|
||||
mapRecurringBookingToMutationInput(bookingInput, recurringEventCount, tracking),
|
||||
callbacks
|
||||
);
|
||||
} else {
|
||||
handleBooking({ ...mapBookingToMutationInput(bookingInput), locationUrl }, callbacks);
|
||||
handleBooking({ ...mapBookingToMutationInput(bookingInput), locationUrl, tracking }, callbacks);
|
||||
}
|
||||
// Clears form values stored in store, so old values won't stick around.
|
||||
setFormValues({});
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import type { ReadonlyURLSearchParams } from "next/navigation";
|
||||
|
||||
export function getUtmTrackingParameters(searchParams: ReadonlyURLSearchParams | null) {
|
||||
if (!searchParams) return undefined;
|
||||
|
||||
const utmParams = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
|
||||
|
||||
const tracking = Object.fromEntries(
|
||||
utmParams.map((param) => [param, searchParams.get(param) ?? undefined])
|
||||
);
|
||||
|
||||
return Object.values(tracking).every((value) => value === undefined) ? undefined : tracking;
|
||||
}
|
||||
Reference in new issue
Block a user