1
0
mirror of synced 2026-01-07 18:01:41 -05:00

Measure how often arriving with a broken hash (#49430)

This commit is contained in:
Peter Bengtsson
2024-02-28 15:25:58 -05:00
committed by GitHub
parent 55c854e943
commit 6f4e4169a2
3 changed files with 44 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ import { Lead } from 'src/frame/components/ui/Lead'
import { PermissionsStatement } from 'src/frame/components/ui/PermissionsStatement'
import { ArticleGridLayout } from './ArticleGridLayout'
import { ArticleInlineLayout } from './ArticleInlineLayout'
import { MeasureBrokenHashes } from './MeasureBrokenHashes'
import { PlatformPicker } from 'src/tools/components/PlatformPicker'
import { ToolPicker } from 'src/tools/components/ToolPicker'
import { MiniTocs } from 'src/frame/components/ui/MiniTocs'
@@ -102,6 +103,7 @@ export const ArticlePage = () => {
<DefaultLayout>
<LinkPreviewPopover />
{isDev && <ClientSideRefresh />}
<MeasureBrokenHashes />
{router.pathname.includes('/rest/') && <RestRedirect />}
{currentLayout === 'inline' ? (
<ArticleInlineLayout

View File

@@ -0,0 +1,42 @@
/**
* This component never renders anything but on initial mount, it checks
* if the hash is broken and sends this as a measurement analytics point.
*
* This experiment is meant to be temporary. At least until we know and
* have documented how often this happens.
*
*/
import { useEffect } from 'react'
import { useRouter } from 'next/router'
import { sendEvent, EventType } from 'src/events/components/events'
const EXPERIMENT_NAME = 'broken_hash'
function sendHash(hash: string) {
const broken = !document.querySelector(`#${hash},a[name="${hash}"]`)
sendEvent({
type: EventType.experiment,
experiment_name: EXPERIMENT_NAME,
experiment_variation: hash,
experiment_success: broken,
})
}
export function MeasureBrokenHashes() {
const { asPath } = useRouter()
useEffect(() => {
try {
if (asPath.includes('#')) {
const hash = asPath.split('#')[1]
if (hash) sendHash(hash)
}
} catch (error) {
console.error('Error measuring broken hash', error)
}
}, [])
return null
}