mirror of
https://github.com/supabase/supabase.git
synced 2026-06-24 21:09:03 +08:00
Add a docs feedback widget to allow upvoting and downvoting pages. Votes (completely anonymized, barely more than a counter) go to a database in the main supabase-com project. If the user has accepted telemetry, the votes also go to Logflare with a bit more info. Post-vote, logged-in users can leave a comment, which goes to the `platform/feedback/send` endpoint. There is a warning in the feedback modal that the feedback is not anonymous.
42 lines
990 B
TypeScript
42 lines
990 B
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,
|
|
page_location: pathname,
|
|
},
|
|
})
|
|
.then(({ error }) => {
|
|
if (error) console.error(error)
|
|
})
|
|
.catch((error) => console.error(error))
|
|
}
|
|
|
|
export { useSendTelemetryEvent }
|