File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5757
5858 sections . forEach ( s => io . observe ( s ) ) ;
5959} ) ( ) ;
60+
61+ // GA4: track project link + contact clicks
62+ ( function trackClicks ( ) {
63+ if ( typeof gtag !== 'function' ) return ;
64+ const clean = ( s ) => ( s || '' ) . replace ( / \s * → \s * $ / , '' ) . trim ( ) ;
65+
66+ document . addEventListener ( 'click' , ( e ) => {
67+ const link = e . target . closest ( 'a' ) ;
68+ if ( ! link ) return ;
69+ const href = link . getAttribute ( 'href' ) || '' ;
70+
71+ // Project links inside a card
72+ const cardLink = link . closest ( '.card-links' ) ;
73+ if ( cardLink ) {
74+ const card = link . closest ( '.card' ) ;
75+ const project = card && card . querySelector ( 'h3' ) ? card . querySelector ( 'h3' ) . textContent . trim ( ) : 'Unknown' ;
76+ gtag ( 'event' , 'project_link_click' , {
77+ project_name : project ,
78+ link_type : clean ( link . textContent ) ,
79+ link_url : href
80+ } ) ;
81+ return ;
82+ }
83+
84+ // Contact / social links
85+ let method = null ;
86+ if ( href . startsWith ( 'mailto:' ) ) method = 'email' ;
87+ else if ( href . includes ( 'linkedin.com' ) ) method = 'linkedin' ;
88+ else if ( href . includes ( 'github.com' ) ) method = 'github' ;
89+ if ( method ) {
90+ gtag ( 'event' , 'contact_click' , { method : method , link_url : href } ) ;
91+ }
92+ } ) ;
93+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments