mirror of
https://github.com/supabase/supabase.git
synced 2026-10-14 05:39:11 +03:00
* Refactor telemetry event into RQ hook, and update to support PH * Refactor telemetry identify into RQ hook, and update to support PH * Refactor telemetry page into RQ hook, and update to support PH * Clean up and deprecate lib/telemetry * Pretty * Add ts-ignore in docs for telemetry calls temporarily * Add credentials include for send event, page and identify mutation hooks * Add consent check for event and page telemetry, allow RQ mutations for those to fail silently without a toast
43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
import { usePathname } from 'next/navigation'
|
|
|
|
import { useConsent } from 'ui-patterns/ConsentToast'
|
|
|
|
import { unauthedAllowedPost } from './fetch/fetchWrappers'
|
|
|
|
type TelemetryEvent = {
|
|
action: string
|
|
category: string
|
|
label: string
|
|
}
|
|
|
|
const noop = () => {}
|
|
|
|
/**
|
|
* Sends a telemetry event to Logflare for tracking by the product team.
|
|
*
|
|
* Checks for user consent to telemetry before sending.
|
|
*/
|
|
const useSendTelemetryEvent = () => {
|
|
const { hasAcceptedConsent } = useConsent()
|
|
const pathname = usePathname()
|
|
|
|
if (!hasAcceptedConsent) return noop
|
|
|
|
return (event: TelemetryEvent) =>
|
|
unauthedAllowedPost('/platform/telemetry/event', {
|
|
// @ts-ignore - endpoint will accept this just fine
|
|
body: {
|
|
...event,
|
|
page_title: document?.title,
|
|
// @ts-ignore [JOSHEN] To be fixed for PH
|
|
page_location: pathname,
|
|
},
|
|
})
|
|
.then(({ error }) => {
|
|
if (error) console.error(error)
|
|
})
|
|
.catch((error) => console.error(error))
|
|
}
|
|
|
|
export { useSendTelemetryEvent }
|