added telemetry to importer (#1525)

* added telemetry to importer

* wip

* ignore typescript errors in jitsu telemetry
pull/1569/head
Peer Richelsen 2022-01-19 17:26:44 +00:00 committed by GitHub
parent 118ee6bfb6
commit c6e60bd706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -9,6 +9,7 @@ export const telemetryEventTypes = {
pageView: "page_view",
bookingConfirmed: "booking_confirmed",
bookingCancelled: "booking_cancelled",
importSubmitted: "import_submitted",
};
/**
@ -70,7 +71,15 @@ function createTelemetryClient(): TelemetryClient {
if (!window) {
console.warn("Jitsu has been called during SSR, this scenario isn't supported yet");
return;
} else if (!window["jitsu"]) {
} else if (
// FIXME
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
!window["jitsu"]
) {
// FIXME
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window["jitsu"] = jitsuClient({
log_level: "ERROR",
tracking_host: "https://t.calendso.com",
@ -79,6 +88,9 @@ function createTelemetryClient(): TelemetryClient {
capture_3rd_party_cookies: false,
});
}
// FIXME
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const res = callback(window["jitsu"]);
if (res && typeof res["catch"] === "function") {
res.catch((e) => {

View File

@ -23,6 +23,7 @@ import { useLocale } from "@lib/hooks/useLocale";
import { getCalendarCredentials, getConnectedCalendars } from "@lib/integrations/calendar/CalendarManager";
import getIntegrations from "@lib/integrations/getIntegrations";
import prisma from "@lib/prisma";
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@lib/telemetry";
import { inferSSRProps } from "@lib/types/inferSSRProps";
import { Schedule as ScheduleType } from "@lib/types/schedule";
@ -48,6 +49,7 @@ type ScheduleFormValues = {
export default function Onboarding(props: inferSSRProps<typeof getServerSideProps>) {
const { t } = useLocale();
const router = useRouter();
const telemetry = useTelemetry();
const DEFAULT_EVENT_TYPES = [
{
@ -267,6 +269,13 @@ export default function Onboarding(props: inferSSRProps<typeof getServerSideProp
<form
className="flex"
onSubmit={formMethods.handleSubmit(async (values) => {
// track the number of imports. Without personal data/payload
telemetry.withJitsu((jitsu) =>
jitsu.track(telemetryEventTypes.importSubmitted, {
...collectPageParameters(),
selectedImport,
})
);
setSubmitting(true);
const response = await fetch(`/api/import/${selectedImport}`, {
method: "POST",