Track all link clicks (internal + external) in analytics; v1.1.33
Replaces outbound-only tracking with a useLinkClickTracking hook that captures every <a> click on the site. Stores as link_click events keyed by destination URL, with an internal flag. Admin analytics page gains a Link Clicks table sorted by count, showing type (internal/external). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -173,7 +173,7 @@ export function register(app) {
|
||||
const { isBot } = detectBot(ua)
|
||||
if (isBot) { res.json({ ok: false, reason: 'bot' }); return }
|
||||
const type = typeof req.body?.type === 'string' ? req.body.type : ''
|
||||
const ALLOWED_TYPES = ['scroll_depth', 'time_on_page', 'outbound_click', 'utm', 'search_query', 'not_found', 'audio_pause', 'audio_completion', 'audio_listen_time']
|
||||
const ALLOWED_TYPES = ['scroll_depth', 'time_on_page', 'outbound_click', 'link_click', 'utm', 'search_query', 'not_found', 'audio_pause', 'audio_completion', 'audio_listen_time']
|
||||
if (!ALLOWED_TYPES.includes(type)) { res.status(400).json({ ok: false, reason: 'invalid-type' }); return }
|
||||
recordAnalyticsEvent(type, req.body)
|
||||
res.json({ ok: true })
|
||||
@@ -378,6 +378,10 @@ export function register(app) {
|
||||
.map(([url, count]) => ({ url, count }))
|
||||
.sort((a, b) => b.count - a.count)
|
||||
.slice(0, 20),
|
||||
topLinkClicks: Object.entries(state.analyticsEvents.linkClicks ?? {})
|
||||
.map(([url, { count, internal }]) => ({ url, count, internal }))
|
||||
.sort((a, b) => b.count - a.count)
|
||||
.slice(0, 50),
|
||||
topUTMSources: Object.entries(state.analyticsEvents.utmSources ?? {})
|
||||
.map(([source, count]) => ({ source, count }))
|
||||
.sort((a, b) => b.count - a.count),
|
||||
|
||||
Reference in New Issue
Block a user