mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-10 10:57:04 +00:00
Move error tracking and analytics to their own files
This commit is contained in:
17
src/app/analytics.ts
Normal file
17
src/app/analytics.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import {page} from "$app/stores"
|
||||
|
||||
const w = window as any
|
||||
|
||||
w.plausible =
|
||||
w.plausible ||
|
||||
function () {
|
||||
;(w.plausible.q = w.plausible.q || []).push(arguments)
|
||||
}
|
||||
|
||||
export const setupAnalytics = () => {
|
||||
page.subscribe($page => {
|
||||
if ($page.route) {
|
||||
w.plausible("pageview", {u: $page.route.id})
|
||||
}
|
||||
})
|
||||
}
|
||||
32
src/app/tracking.ts
Normal file
32
src/app/tracking.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import Bugsnag from "@bugsnag/js"
|
||||
|
||||
export const setupTracking = () => {
|
||||
if (!import.meta.env.VITE_BUGSNAG_API_KEY) return
|
||||
|
||||
// Initialize
|
||||
Bugsnag.start({
|
||||
apiKey: import.meta.env.VITE_BUGSNAG_API_KEY,
|
||||
collectUserIp: false,
|
||||
})
|
||||
|
||||
// Redact long strings, especially hex and bech32 keys which are 64 and 63
|
||||
// characters long, respectively. Put the threshold a little lower in case
|
||||
// someone accidentally enters a key with the last few digits missing
|
||||
const redactErrorInfo = (info: any) =>
|
||||
JSON.parse(
|
||||
JSON.stringify(info || null)
|
||||
.replace(/\d+:{60}\w+:\w+/g, "[REDACTED]")
|
||||
.replace(/\w{60}\w+/g, "[REDACTED]"),
|
||||
)
|
||||
|
||||
Bugsnag.addOnError((event: any) => {
|
||||
// Redact individual properties since the event needs to be
|
||||
// mutated, and we don't want to lose the prototype
|
||||
event.context = redactErrorInfo(event.context)
|
||||
event.request = redactErrorInfo(event.request)
|
||||
event.exceptions = redactErrorInfo(event.exceptions)
|
||||
event.breadcrumbs = redactErrorInfo(event.breadcrumbs)
|
||||
|
||||
return true
|
||||
})
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
<script lang="ts">
|
||||
import "@src/app.css"
|
||||
import Bugsnag from "@bugsnag/js"
|
||||
import {onMount} from "svelte"
|
||||
import {get} from "svelte/store"
|
||||
import {dev} from "$app/environment"
|
||||
import {page} from "$app/stores"
|
||||
import {sleep, take, sortBy, ago, now, HOUR} from "@welshman/lib"
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import {
|
||||
@@ -40,52 +38,13 @@
|
||||
import * as app from "@welshman/app"
|
||||
import AppContainer from "@app/components/AppContainer.svelte"
|
||||
import ModalContainer from "@app/components/ModalContainer.svelte"
|
||||
import {setupTracking} from "@app/tracking"
|
||||
import {setupAnalytics} from "@app/analytics"
|
||||
import {theme} from "@app/theme"
|
||||
import {INDEXER_RELAYS} from "@app/state"
|
||||
import {loadUserData} from "@app/commands"
|
||||
import * as state from "@app/state"
|
||||
|
||||
const setupErrorTracking = () => {
|
||||
if (!import.meta.env.VITE_BUGSNAG_API_KEY) return
|
||||
|
||||
// Initialize
|
||||
Bugsnag.start({
|
||||
apiKey: import.meta.env.VITE_BUGSNAG_API_KEY,
|
||||
collectUserIp: false,
|
||||
})
|
||||
|
||||
// Redact long strings, especially hex and bech32 keys which are 64 and 63
|
||||
// characters long, respectively. Put the threshold a little lower in case
|
||||
// someone accidentally enters a key with the last few digits missing
|
||||
const redactErrorInfo = (info: any) =>
|
||||
JSON.parse(
|
||||
JSON.stringify(info || null)
|
||||
.replace(/\d+:{60}\w+:\w+/g, "[REDACTED]")
|
||||
.replace(/\w{60}\w+/g, "[REDACTED]"),
|
||||
)
|
||||
|
||||
Bugsnag.addOnError((event: any) => {
|
||||
// Redact individual properties since the event needs to be
|
||||
// mutated, and we don't want to lose the prototype
|
||||
event.context = redactErrorInfo(event.context)
|
||||
event.request = redactErrorInfo(event.request)
|
||||
event.exceptions = redactErrorInfo(event.exceptions)
|
||||
event.breadcrumbs = redactErrorInfo(event.breadcrumbs)
|
||||
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
const setupAnalytics = () => {
|
||||
(window as any).plausible.q = []
|
||||
|
||||
page.subscribe($page => {
|
||||
if ($page.route) {
|
||||
(window as any).plausible.q.push(["pageview", {u: $page.route.id}])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Migration: old nostrtalk instance used different sessions
|
||||
if ($session && !$signer) {
|
||||
dropSession($session.pubkey)
|
||||
@@ -153,7 +112,7 @@
|
||||
}
|
||||
|
||||
if (!db) {
|
||||
setupErrorTracking()
|
||||
setupTracking()
|
||||
setupAnalytics()
|
||||
|
||||
ready = initStorage("flotilla", 4, {
|
||||
|
||||
Reference in New Issue
Block a user