cal.pub0.org/packages/lib/telemetry.ts

117 lines
3.6 KiB
TypeScript
Raw Normal View History

import type { NextApiRequest, NextApiResponse } from "next";
import type { CollectOpts, EventHandler } from "next-collect";
import { useCollector } from "next-collect/client";
V2 Main (#3549) * Fix breadcrumb colors * HorizontalTabs * Team List Item WIP * Horizontal Tabs * Cards * Remove team list item WIP * Login Page * Add welcome back i118n * EventType page work * Update EventType Icons * WIP Availability * Horizontal Tab Work * Add build command for in root * Update build DIr/command * Add Edit Button + change buttons to v2 * Availablitiy page * Fix IPAD * Make mobile look a little nicer * WIP bookingshell * Remove list items from breaking build * Mian bulk of Booking Page. * Few updates to components * Fix chormatic feedback * Fix banner * Fix Empty Screen * Text area + embded window fixes * Semi fix avatar * Troubleshoot container + Active on count * Improve mobile * NITS * Fix padding on input * Fix icons * Starting to move event types settings to tabs * Begin migration to single page form * Single page tabs * Limits Page * Advanced tab * Add RHF to dependancies * Most of advanced tab * Solved RHF mismtach * Build fixes * RHF conditionals fixes * Improved legibility * Major refactor/organisation into optional V2 UI * Portal EditLocationModal * Fix dialoug form * Update imports * Auto Animate + custom inputs WIP * Custom Inputs * WIP Apps * Fixing stories imports * Stripe app * Remove duplicate dialog * Remove duplicate dialog * Fix embed URL * Fix app toggles + number of active apps * Fix container padding on disabledBorder prop * Removes strict * EventType Team page WIP * Fix embed * NIT * Add Darkmode gray color * V2 Shell WIP * Fix headings on shell V2 * Fix mobile layout with V2 shell * V2 create event type button * Checked Team Select * Hidden to happen on save - not on toggle * Team Attendee Select animation * Fix scheduling type and remove multi select label * Fix overflow on teams url * Even Type move order handles * Fix Embed TS errors * Fix TS errors * Fix Eslint errors * Fix TS errors for UI * Fix ESLINT error * added SidebarCard for promo to v2 and storybook (#3906) Co-authored-by: Julian Benegas <julianbenegas99@gmail.com> Co-authored-by: Alan <alannnc@gmail.com> Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> * Tooltip Provider - Wrapper due to dep upgrade * public event type list darkmode * V2 Color changes to public booking * Remove unused component * Fix typecheck * Removed extra buttons on create ET dialog * ET edit page refactoring * Avoids form wrapping the whole Shell * Nitpicks Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> Co-authored-by: Julian Benegas <julianbenegas99@gmail.com> Co-authored-by: Alan <alannnc@gmail.com>
2022-08-24 20:18:42 +00:00
// Importing types so we're not directly importing next/server
import type { NextRequest, NextResponse } from "next/server";
import { CONSOLE_URL } from "./constants";
export const telemetryEventTypes = {
pageView: "page_view",
apiCall: "api_call",
bookingConfirmed: "booking_confirmed",
bookingCancelled: "booking_cancelled",
importSubmitted: "import_submitted",
login: "login",
embedView: "embed_view",
embedBookingConfirmed: "embed_booking_confirmed",
onboardingFinished: "onboarding_finished",
onboardingStarted: "onboarding_started",
signup: "signup",
team_created: "team_created",
website: {
pageView: "website_page_view",
},
Managed event-types (#6876) * WIP * Locked fields manager * Leftovers * Bad merge fix * Type import fix * Moving away from classes * Progress refactoring locked logic * Covering apps, webhooks and workflows * Supporting webhooks and workflows (TBT) * Restoring yarn.lock * Progress * Refactoring code, adding default values * Fixing CRUD for children * Connect app link and case-sensitive lib renaming * Translation missing * Locked indicators, empty screens, locations * Member card and hidden status + missing i18n * Missing existent children shown * Showing preview for already created children * Email notification almost in place * Making progress over notif email * Fixing nodemailer by mixed FE/BE mixup * Delete dialog * Adding tests * New test * Reverting unneeded change * Removed console.log * Tweaking email * Reverting not applicable webhook changes * Reverting dev email api * Fixing last changes due to tests * Changing user-evType relationship * Availability and slug replacement tweaks * Fixing event type delete * Sometimes slug is not there... * Removing old webhooks references Changed slug hint * Fixing types * Fixing hiding event types actions * Changing delete dialog text * Removing unneeded code * Applying feedback * Update yarn.lock * Making sure locked fields values are static * Applying feedback * Feedback + relying on children list, not users * Removing console.log * PR Feedback * Telemetry for slug replacement action * More unit tests * Relying on schedule and editor tweaks * Fixing conteiner classname * PR Feedback * PR Feedback * Updating unit tests * Moving stuff to ee, added feature flag * type fix * Including e2e * Reverting unneeded changes in EmptyScreen * Fixing some UI issues after merging tokens * Fixing missing disabled locked fields * Theme fixes + e2e potential fix * Fixing e2e * Fixing login relying on network * Tweaking e2e * Removing unneeded code --------- Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: zomars <zomars@me.com>
2023-04-13 02:10:23 +00:00
slugReplacementAction: "slug_replacement_action",
};
2022-05-17 20:43:27 +00:00
export function collectPageParameters(
route?: string,
extraData: Record<string, unknown> = {}
): Record<string, unknown> {
const host = document.location.host;
const docPath = route ?? "";
return {
page_url: route,
doc_encoding: document.characterSet,
url: document.location.protocol + "//" + host + (docPath ?? ""),
...extraData,
};
}
const reportUsage: EventHandler = async (event, { fetch }) => {
2022-06-06 21:33:13 +00:00
const ets = telemetryEventTypes;
if ([ets.bookingConfirmed, ets.embedBookingConfirmed].includes(event.eventType)) {
const key = process.env.CALCOM_LICENSE_KEY;
const url = `${CONSOLE_URL}/api/deployments/usage?key=${key}&quantity=1`;
try {
return fetch(url, { method: "POST", mode: "cors" });
} catch (e) {
console.error(`Error reporting booking for key: '${key}'`, e);
return Promise.resolve();
}
} else {
return Promise.resolve();
}
};
export const nextCollectBasicSettings: CollectOpts = {
drivers: [
process.env.CALCOM_LICENSE_KEY && process.env.NEXT_PUBLIC_IS_E2E !== "1" ? reportUsage : undefined,
process.env.CALCOM_TELEMETRY_DISABLED === "1" || process.env.NEXT_PUBLIC_IS_E2E === "1"
? undefined
: {
2022-06-02 20:06:13 +00:00
type: "jitsu",
opts: {
key: "s2s.2pvs2bbpqq1zxna97wcml.esb6cikfrf7yn0qoh1nj1",
server: "https://t.calendso.com",
},
},
process.env.TELEMETRY_DEBUG && { type: "echo", opts: { disableColor: true } },
],
eventTypes: [
{ "*.ttf": null },
{ "*.webmanifest": null },
{ "*.json": null },
{ "*.svg": null },
{ "*.map": null },
{ "*.png": null },
{ "*.gif": null },
{ "/api/collect-events": null },
{ "/api*": null },
{ "/img*": null },
{ "/favicon*": null },
{ "/*": telemetryEventTypes.pageView },
],
};
export const extendEventData = (
req: NextRequest | NextApiRequest,
res: NextResponse | NextApiResponse,
original: any
) => {
const onVercel =
typeof req.headers?.get === "function"
? !!req.headers.get("x-vercel-id")
: !!(req.headers as any)?.["x-vercel-id"];
const pageUrl = original?.page_url || req.url || undefined;
const cookies = req.cookies as { [key: string]: any };
return {
title: "",
ipAddress: "",
queryString: "",
page_url: pageUrl,
2022-06-02 17:53:02 +00:00
licensekey: process.env.CALCOM_LICENSE_KEY,
isTeamBooking:
original?.isTeamBooking === undefined
? pageUrl?.includes("team/") || undefined
: original?.isTeamBooking,
referrer: "",
onVercel,
isAuthorized: !!cookies["next-auth.session-token"] || !!cookies["__Secure-next-auth.session-token"],
utc_time: new Date().toISOString(),
};
};
export const useTelemetry = useCollector;