Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 51 additions & 23 deletions apps/dialog/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,40 @@ import * as Wagmi from '~/lib/Wagmi.ts'
import { App } from './App.js'
import './styles.css'

// Initialize Sentry conditionally based on telemetry setting
let sentryInitialized = false

if (import.meta.env.PROD) {
Sentry.init({
dsn: 'https://457697aad11614a3f667c8e61f6b9e20@o4509056062849024.ingest.us.sentry.io/4509080285741056',
enabled: document.referrer
? TrustedHosts.hostnames.includes(new URL(document.referrer).hostname)
: true,
environment: Env.get(),
integrations: [
Sentry.replayIntegration(),
Sentry.tanstackRouterBrowserTracingIntegration(Router.router),
],
replaysOnErrorSampleRate: 1.0,
replaysSessionSampleRate: 0.1,
})
// Check localStorage for telemetry preference
const telemetryDisabled = localStorage.getItem('__porto_telemetry_disabled') === 'true'

if (!telemetryDisabled) {
Sentry.init({
dsn: 'https://457697aad11614a3f667c8e61f6b9e20@o4509056062849024.ingest.us.sentry.io/4509080285741056',
enabled: document.referrer
? TrustedHosts.hostnames.includes(new URL(document.referrer).hostname)
: true,
environment: Env.get(),
integrations: [
Sentry.replayIntegration(),
Sentry.tanstackRouterBrowserTracingIntegration(Router.router),
],
replaysOnErrorSampleRate: 1.0,
replaysSessionSampleRate: 0.1,
})
sentryInitialized = true
}
}

const offInitialized = Events.onInitialized(porto, async (payload, event) => {
const { chainIds, mode, referrer, theme } = payload
const { chainIds, mode, referrer, telemetry, theme } = payload

// Store telemetry preference in localStorage
if (telemetry === false) {
localStorage.setItem('__porto_telemetry_disabled', 'true')
} else {
localStorage.removeItem('__porto_telemetry_disabled')
}

// Prevent showing stale route from a previous action.
const pathname = Router.router.state.location.pathname.replace(/\/+$/, '')
Expand Down Expand Up @@ -163,15 +179,27 @@ const rootElement = document.querySelector('div#root')
if (!rootElement) throw new Error('Root element not found')

createRoot(rootElement, {
onCaughtError: Sentry.reactErrorHandler((error) => {
console.error(error)
}),
onRecoverableError: Sentry.reactErrorHandler((error) => {
console.error(error)
}),
onUncaughtError: Sentry.reactErrorHandler((error) => {
console.error(error)
}),
onCaughtError: sentryInitialized
? Sentry.reactErrorHandler((error) => {
console.error(error)
})
: (error) => {
console.error(error)
},
onRecoverableError: sentryInitialized
? Sentry.reactErrorHandler((error) => {
console.error(error)
})
: (error) => {
console.error(error)
},
onUncaughtError: sentryInitialized
? Sentry.reactErrorHandler((error) => {
console.error(error)
})
: (error) => {
console.error(error)
},
}).render(
<StrictMode>
<App />
Expand Down
15 changes: 15 additions & 0 deletions apps/docs/pages/sdk/api/porto/create.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ Available:
- [`Storage.localStorage()`](/sdk/api/storage#storagelocalstorage): Uses `window.localStorage{:ts}`
- [`Storage.cookie()`](/sdk/api/storage#storagecookie): Uses `document.cookie{:ts}`

### telemetry

- **Type:** `boolean | undefined`
- **Default:** `true{:ts}`

Whether to enable telemetry and error tracking. When set to `false`, disables anonymous error reporting via Sentry in the Porto dialog and authentication interfaces.

```ts twoslash
import { Porto } from 'porto'

const porto = Porto.create({
telemetry: false, // Disable telemetry
})
```

### transports

- **Type:** `{ [chainId: string]: Transport }{:ts}`
Expand Down
51 changes: 36 additions & 15 deletions apps/id/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,50 @@ import * as Router from '~/lib/Router.js'
import { App } from './App.js'
import './styles.css'

// Initialize Sentry conditionally based on telemetry setting
let sentryInitialized = false

if (import.meta.env.PROD) {
Sentry.init({
dsn: 'https://1b4e28921c688e2b03d1b63f8d018913@o4509056062849024.ingest.us.sentry.io/4509080371724288',
environment: Env.get(),
integrations: [
Sentry.replayIntegration(),
Sentry.tanstackRouterBrowserTracingIntegration(Router.router),
],
replaysOnErrorSampleRate: 1.0,
replaysSessionSampleRate: 0.1,
})
// Check localStorage for telemetry preference
const telemetryDisabled = localStorage.getItem('__porto_telemetry_disabled') === 'true'

if (!telemetryDisabled) {
Sentry.init({
dsn: 'https://1b4e28921c688e2b03d1b63f8d018913@o4509056062849024.ingest.us.sentry.io/4509080371724288',
environment: Env.get(),
integrations: [
Sentry.replayIntegration(),
Sentry.tanstackRouterBrowserTracingIntegration(Router.router),
],
replaysOnErrorSampleRate: 1.0,
replaysSessionSampleRate: 0.1,
})
sentryInitialized = true
}
}

const rootElement = document.querySelector('div#root')

if (!rootElement) throw new Error('Root element not found')

createRoot(rootElement, {
onCaughtError: Sentry.reactErrorHandler(),
onRecoverableError: Sentry.reactErrorHandler(),
onUncaughtError: Sentry.reactErrorHandler((error, errorInfo) => {
console.warn('Uncaught error', error, errorInfo.componentStack)
}),
onCaughtError: sentryInitialized
? Sentry.reactErrorHandler()
: (error) => {
console.error(error)
},
onRecoverableError: sentryInitialized
? Sentry.reactErrorHandler()
: (error) => {
console.error(error)
},
onUncaughtError: sentryInitialized
? Sentry.reactErrorHandler((error, errorInfo) => {
console.warn('Uncaught error', error, errorInfo.componentStack)
})
: (error) => {
console.warn('Uncaught error', error)
},
}).render(
<StrictMode>
<App />
Expand Down
13 changes: 10 additions & 3 deletions src/core/Dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type Dialog = {
setup: (parameters: {
host: string
internal: Internal
telemetry?: boolean | undefined
theme?: ThemeFragment | undefined
themeController?: ThemeController | undefined
}) => {
Expand Down Expand Up @@ -83,7 +84,7 @@ export function iframe(options: iframe.Options = {}) {
return from({
name: 'iframe',
setup(parameters) {
const { host, internal, theme, themeController } = parameters
const { host, internal, telemetry, theme, themeController } = parameters
const { store } = internal

const fallback = popup().setup(parameters)
Expand Down Expand Up @@ -191,6 +192,7 @@ export function iframe(options: iframe.Options = {}) {
chainIds: compatibleChainIds,
mode: 'iframe',
referrer: getReferrer(),
telemetry,
theme,
type: 'init',
})
Expand Down Expand Up @@ -310,6 +312,7 @@ export function iframe(options: iframe.Options = {}) {
messenger.send('__internal', {
mode: 'iframe',
referrer: getReferrer(),
telemetry,
type: 'init',
})

Expand Down Expand Up @@ -340,6 +343,7 @@ export function iframe(options: iframe.Options = {}) {
messenger.send('__internal', {
mode: 'iframe',
referrer: getReferrer(),
telemetry,
type: 'init',
})
},
Expand Down Expand Up @@ -445,7 +449,7 @@ export function popup(options: popup.Options = {}) {
return from({
name: 'popup',
setup(parameters) {
const { host, internal, themeController } = parameters
const { host, internal, telemetry, themeController } = parameters
const { store } = internal

const hostUrl = new URL(host)
Expand Down Expand Up @@ -515,6 +519,7 @@ export function popup(options: popup.Options = {}) {
messenger.send('__internal', {
mode: resolvedType === 'page' ? 'page' : 'popup',
referrer: getReferrer(),
telemetry,
theme: themeController?.getTheme() ?? parameters.theme,
type: 'init',
})
Expand Down Expand Up @@ -826,7 +831,7 @@ export function experimental_inline(options: inline.Options) {
return from({
name: 'inline',
setup(parameters) {
const { host, internal, theme, themeController } = parameters
const { host, internal, telemetry, theme, themeController } = parameters
const { store } = internal

let open = false
Expand Down Expand Up @@ -874,6 +879,7 @@ export function experimental_inline(options: inline.Options) {
messenger.send('__internal', {
mode: 'inline-iframe',
referrer: getReferrer(),
telemetry,
theme,
type: 'init',
})
Expand All @@ -896,6 +902,7 @@ export function experimental_inline(options: inline.Options) {
messenger.send('__internal', {
mode: 'iframe',
referrer: getReferrer(),
telemetry,
type: 'init',
})
},
Expand Down
1 change: 1 addition & 0 deletions src/core/Messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export type Schema = [
icon?: string | { light: string; dark: string } | undefined
title: string
}
telemetry?: boolean | undefined
theme?: Theme.ThemeFragment | undefined
}
| {
Expand Down
6 changes: 6 additions & 0 deletions src/core/Porto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export function create(
relay: parameters.relay ?? defaultConfig.relay,
storage: parameters.storage ?? defaultConfig.storage,
storageKey: parameters.storageKey ?? defaultConfig.storageKey,
telemetry: parameters.telemetry ?? true,
transports,
} satisfies Config

Expand Down Expand Up @@ -210,6 +211,11 @@ export type Config<
* Key to use for store.
*/
storageKey?: string | undefined
/**
* Whether to enable telemetry/error tracking.
* @default true
*/
telemetry?: boolean | undefined
/**
* Public RPC Transport overrides to use for each chain.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/core/internal/modes/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,11 +958,12 @@ export function dialog(parameters: dialog.Parameters = {}) {
name: 'dialog',
setup(parameters) {
const { internal } = parameters
const { store } = internal
const { config, store } = internal

const dialog = renderer.setup({
host,
internal,
telemetry: config.telemetry,
theme,
themeController,
})
Expand Down
Loading