mirror of
https://github.com/supabase/supabase.git
synced 2026-10-19 08:09: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
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
'use client'
|
|
|
|
import { useTelemetryProps } from 'common'
|
|
import { usePathname } from 'next/navigation'
|
|
import { useCallback, useEffect } from 'react'
|
|
import { useConsent } from 'ui-patterns/ConsentToast'
|
|
import { BASE_PATH, IS_PLATFORM } from '~/lib/constants'
|
|
import { unauthedAllowedPost } from '~/lib/fetch/fetchWrappers'
|
|
|
|
const useSendPageTelemetryWithConsent = () => {
|
|
const { hasAcceptedConsent } = useConsent()
|
|
const telemetryProps = useTelemetryProps()
|
|
|
|
const sendPageTelemetry = useCallback(
|
|
(route: string) => {
|
|
if (!(IS_PLATFORM && hasAcceptedConsent)) return
|
|
|
|
unauthedAllowedPost('/platform/telemetry/page', {
|
|
body: {
|
|
// @ts-ignore [JOSHEN] To be fixed for PH
|
|
referrer: document.referrer,
|
|
title: document.title,
|
|
route: `${BASE_PATH}${route}`,
|
|
ga: {
|
|
screen_resolution: telemetryProps?.screenResolution,
|
|
language: telemetryProps?.language,
|
|
session_id: '',
|
|
},
|
|
},
|
|
}).catch((e) => {
|
|
console.error('Problem sending telemetry:', e)
|
|
})
|
|
},
|
|
[telemetryProps, hasAcceptedConsent]
|
|
)
|
|
|
|
return sendPageTelemetry
|
|
}
|
|
|
|
const PageTelemetry = () => {
|
|
const pathname = usePathname()
|
|
const sendPageTelemetry = useSendPageTelemetryWithConsent()
|
|
|
|
useEffect(() => {
|
|
if (pathname) {
|
|
sendPageTelemetry(pathname)
|
|
}
|
|
}, [pathname, sendPageTelemetry])
|
|
|
|
return null
|
|
}
|
|
|
|
export { PageTelemetry }
|