File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ export function getUserEventsId () {
2727 return cookieValue
2828}
2929
30- export async function sendEvent ( {
30+ export function sendEvent ( {
3131 type,
3232 version = '1.0.0' ,
3333 page_render_duration,
@@ -141,7 +141,7 @@ function trackScroll () {
141141 if ( scrollPosition > maxScrollY ) maxScrollY = scrollPosition
142142}
143143
144- async function sendExit ( ) {
144+ function sendExit ( ) {
145145 if ( sentExit ) return
146146 if ( document . visibilityState !== 'hidden' ) return
147147 if ( ! pageEventId ) return
@@ -162,14 +162,24 @@ async function sendExit () {
162162 } )
163163}
164164
165- export default async function initializeEvents ( ) {
165+ export default function initializeEvents ( ) {
166166 // Page event
167167 const { render } = getPerformance ( )
168- const pageEvent = await sendEvent ( {
168+ const pageEvent = sendEvent ( {
169169 type : 'page' ,
170170 page_render_duration : render
171171 } )
172172
173+ // Link event
174+ document . documentElement . addEventListener ( 'click' , evt => {
175+ const link = evt . target . closest ( 'a[href^="http"]' )
176+ if ( ! link ) return
177+ sendEvent ( {
178+ type : 'link' ,
179+ link_url : link . href
180+ } )
181+ } )
182+
173183 // Navigate event
174184 Array . from (
175185 document . querySelectorAll ( '.sidebar-products details' )
You can’t perform that action at this time.
0 commit comments