(() => {
const EVENT_ENDPOINT =
"https://twdsjzrajfvjovrphucn.supabase.co/functions/v1/mkt-event";
const IDENTIFY_ENDPOINT =
"https://twdsjzrajfvjovrphucn.supabase.co/functions/v1/mkt-identify";
const REDIRECT_DELAY_MS = 350;
const FALLBACK_REDIRECT_MS = 700;
const qs = new URLSearchParams(window.location.search);
const target = qs.get("target");
const txt = (v) =>
typeof v === "string" && v.trim().length > 0 ? v.trim() : null;
const uuid = () =>
crypto.randomUUID?.() ||
"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
const v = c === "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
const visitor_id =
txt(localStorage.getItem("visitor_id")) || (localStorage.setItem("visitor_id", uuid()), localStorage.getItem("visitor_id"));
const session_id =
txt(sessionStorage.getItem("mkt_session_id")) ||
(sessionStorage.setItem("mkt_session_id", uuid()), sessionStorage.getItem("mkt_session_id"));
if (!target) return;
let destinationUrl;
try {
destinationUrl = new URL(target);
} catch {
return;
}
const contact_email = txt(qs.get("contact_email"))?.toLowerCase() || null;
const contact_name = txt(qs.get("contact_name"));
const payload = {
link_type: "google_calendar",
destination_url: destinationUrl.toString(),
contact_name,
contact_email,
page_url: window.location.href,
page_path: window.location.pathname,
visitor_id
};
const post = (url, body) =>
fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
keepalive: true
}).catch(() => {});
if (contact_email) {
post(IDENTIFY_ENDPOINT, {
visitor_id,
identity_type: "email",
identity_value: contact_email,
source: "framer",
is_primary: true,
name: contact_name
});
}
post(EVENT_ENDPOINT, {
session_id,
event_name: "schedule_link_click",
payload
});
setTimeout(() => {
window.location.replace(destinationUrl.toString());
}, REDIRECT_DELAY_MS);
})();