PluginProbe
Extendify / 0.10.1
Extendify v0.10.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Onboarding / hooks / useSentry.js

useSentry.js in Extendify 0.10.1, at src/Onboarding/hooks/useSentry.js

53 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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