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:
@@ -850,6 +850,7 @@ const EMPTY_ANALYTICS_EVENTS = {
|
||||
scrollDepth: {},
|
||||
timeOnPage: {},
|
||||
outboundClicks: {},
|
||||
linkClicks: {},
|
||||
utmSources: {},
|
||||
searchQueries: {},
|
||||
notFound: {},
|
||||
@@ -875,6 +876,7 @@ export function loadAnalyticsEventsFromDisk() {
|
||||
scrollDepth: parsed?.scrollDepth ?? {},
|
||||
timeOnPage: parsed?.timeOnPage ?? {},
|
||||
outboundClicks: parsed?.outboundClicks ?? {},
|
||||
linkClicks: parsed?.linkClicks ?? {},
|
||||
utmSources: parsed?.utmSources ?? {},
|
||||
searchQueries: parsed?.searchQueries ?? {},
|
||||
notFound: parsed?.notFound ?? {},
|
||||
@@ -902,6 +904,12 @@ export function recordAnalyticsEvent(type, data) {
|
||||
} else if (type === 'outbound_click') {
|
||||
const url = typeof data.url === 'string' ? data.url.slice(0, 500) : ''
|
||||
if (url) ev.outboundClicks[url] = (ev.outboundClicks[url] ?? 0) + 1
|
||||
} else if (type === 'link_click') {
|
||||
const url = typeof data.url === 'string' ? data.url.slice(0, 500) : ''
|
||||
if (url) {
|
||||
if (!ev.linkClicks[url]) ev.linkClicks[url] = { count: 0, internal: data.internal === true }
|
||||
ev.linkClicks[url].count += 1
|
||||
}
|
||||
} else if (type === 'utm') {
|
||||
const source = typeof data.utm_source === 'string' ? data.utm_source.slice(0, 100) : 'unknown'
|
||||
ev.utmSources[source] = (ev.utmSources[source] ?? 0) + 1
|
||||
|
||||
Reference in New Issue
Block a user