Skip to content

Commit e4e5717

Browse files
reakaleekclaude
andauthored
Telemetry: capture middle-click CTA opens (#3605)
Middle-click ("open in new tab") on a CTA link fires the DOM auxclick event, not click, so those engagements were never emitted as cta_clicked. Bind the existing handler to auxclick (button 1 only) alongside click. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 6b14cad commit e4e5717

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

  • src/Elastic.Documentation.Site/Assets

src/Elastic.Documentation.Site/Assets/main.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,24 @@ document.addEventListener('htmx:load', function () {
209209
])
210210
})
211211

212-
// Delegated listener: survives htmx swaps without needing re-init, unlike the
212+
// Delegated listeners: survive htmx swaps without needing re-init, unlike the
213213
// runInitSteps above which bind directly to elements that get replaced.
214214
// logInfo's export survives this same-tab navigation: the batch processor flushes on
215215
// 'pagehide' (registered in initializeOtel) via a keepalive fetch, which browsers keep
216216
// alive past unload.
217-
document.addEventListener('click', function (event: MouseEvent) {
217+
function handleCtaActivation(event: MouseEvent) {
218218
const cta = (event.target as HTMLElement)?.closest<HTMLAnchorElement>(
219219
'a[data-cta]'
220220
)
221221
if (!cta) return
222222
logCtaEvent('cta_clicked', cta)
223+
}
224+
document.addEventListener('click', handleCtaActivation)
225+
// 'auxclick' with button 1 covers middle-click (open in new tab), which does NOT
226+
// fire 'click' per the DOM spec - without this those opens went untracked. Button 2
227+
// (right-click / context menu) also fires auxclick but isn't a real engagement.
228+
document.addEventListener('auxclick', function (event: MouseEvent) {
229+
if (event.button === 1) handleCtaActivation(event)
223230
})
224231

225232
// Don't remove style tags because they are used by the elastic global nav.

0 commit comments

Comments
 (0)