| 1 |
import { useEffect } from '@wordpress/element' |
| 2 |
import * as Sentry from '@sentry/react' |
| 3 |
import { BrowserTracing } from '@sentry/tracing' |
| 4 |
import { useGlobalStore } from '@onboarding/state/Global' |
| 5 |
import { usePagesStore } from '@onboarding/state/Pages' |
| 6 |
|
| 7 |
if (window.extOnbData.insightsEnabled) { |
| 8 |
Sentry.init({ |
| 9 |
dsn: 'https://c5c1aec4298743d399e86509ee4cef9c@o1352321.ingest.sentry.io/6633543', |
| 10 |
integrations: [new BrowserTracing()], |
| 11 |
release: window.extOnbData?.version, |
| 12 |
environment: window?.extOnbData?.devbuild ? 'dev' : 'production', |
| 13 |
|
| 14 |
// TODO: consider lowering this in production to reduce the amount of data sent |
| 15 |
tracesSampleRate: 1.0, |
| 16 |
beforeSend(event) { |
| 17 |
// Check if it is an exception, and if so, show the report dialog |
| 18 |
if (event.exception) { |
| 19 |
Sentry.showReportDialog({ eventId: event.event_id }) |
| 20 |
} |
| 21 |
return event |
| 22 |
}, |
| 23 |
}) |
| 24 |
} |
| 25 |
export { Sentry } |
| 26 |
export const useSentry = () => { |
| 27 |
const orderId = useGlobalStore((state) => state.orderId) |
| 28 |
const { pages, currentPageIndex } = usePagesStore() |
| 29 |
|
| 30 |
useEffect(() => { |
| 31 |
if (!window.extOnbData.insightsEnabled) return |
| 32 |
Sentry.setUser({ id: window.extOnbData?.insightsId }) |
| 33 |
Sentry.configureScope((scope) => { |
| 34 |
scope.setExtra('Partner', window.extOnbData?.partnerName) |
| 35 |
scope.setExtra('Site', window.extOnbData?.home) |
| 36 |
scope.setExtra('Order ID', orderId) |
| 37 |
scope.setExtra('Insights ID', window.extOnbData?.insightsId) |
| 38 |
}) |
| 39 |
}, [orderId]) |
| 40 |
|
| 41 |
useEffect(() => { |
| 42 |
if (!window.extOnbData.insightsEnabled) return |
| 43 |
const p = [...pages].map((p) => p[0]) |
| 44 |
Sentry.addBreadcrumb({ |
| 45 |
type: 'navigation', |
| 46 |
category: 'step', |
| 47 |
message: `Navigated to ${p[currentPageIndex]}`, |
| 48 |
}) |
| 49 |
}, [currentPageIndex, pages]) |
| 50 |
|
| 51 |
return { Sentry } |
| 52 |
} |
| 53 |
|