@@ -542,18 +542,36 @@ <h3><span class="card-icon">📝</span> Sorting</h3>
542542 // Track page view
543543 analytics . track ( 'page_view' , { page : window . location . pathname } ) ;
544544
545+ // ===============================
546+ // GOATCOUNTER EVENT TRACKING
547+ // ===============================
548+ // Helper function to track events with GoatCounter
549+ function trackEvent ( eventName , title ) {
550+ if ( window . goatcounter && window . goatcounter . count ) {
551+ window . goatcounter . count ( {
552+ path : eventName ,
553+ title : title || eventName ,
554+ event : true
555+ } ) ;
556+ }
557+ }
558+
545559 // ===============================
546560 // SCROLL DEPTH TRACKING
547561 // ===============================
548562 let maxScroll = 0 ;
563+ let scrollMilestones = { 25 : false , 50 : false , 75 : false , 100 : false } ;
549564 window . addEventListener ( 'scroll' , ( ) => {
550565 const scrollPercent = Math . round ( ( window . scrollY / ( document . body . scrollHeight - window . innerHeight ) ) * 100 ) ;
551566 if ( scrollPercent > maxScroll ) {
552567 maxScroll = scrollPercent ;
553568 // Track milestones: 25%, 50%, 75%, 100%
554- if ( [ 25 , 50 , 75 , 100 ] . includes ( scrollPercent ) ) {
555- analytics . track ( 'scroll_depth' , { percent : scrollPercent } ) ;
556- }
569+ [ 25 , 50 , 75 , 100 ] . forEach ( milestone => {
570+ if ( scrollPercent >= milestone && ! scrollMilestones [ milestone ] ) {
571+ scrollMilestones [ milestone ] = true ;
572+ trackEvent ( 'scroll-' + milestone + '-percent' , 'Scrolled ' + milestone + '% of page' ) ;
573+ }
574+ } ) ;
557575 }
558576 } ) ;
559577
@@ -572,16 +590,16 @@ <h3><span class="card-icon">📝</span> Sorting</h3>
572590 . catch ( err => console . log ( 'Failed to fetch stars' , err ) ) ;
573591
574592 // ===============================
575- // TAB SWITCHING
593+ // TAB SWITCHING (with tracking)
576594 // ===============================
577595 function switchTab ( id ) {
578596 document . querySelectorAll ( '.tab-btn' ) . forEach ( b => b . classList . remove ( 'active' ) ) ;
579597 event . target . classList . add ( 'active' ) ;
580598 document . querySelectorAll ( '.code-block' ) . forEach ( b => b . classList . remove ( 'active' ) ) ;
581599 document . getElementById ( 'code-' + id ) . classList . add ( 'active' ) ;
582600
583- // Track tab switch
584- analytics . track ( 'tab_switch' , { tab : id } ) ;
601+ // Track tab switch with GoatCounter
602+ trackEvent ( 'tab-' + id , 'Switched to ' + id + ' install tab' ) ;
585603 }
586604
587605 // ===============================
@@ -602,22 +620,23 @@ <h3><span class="card-icon">📝</span> Sorting</h3>
602620 hint . innerText = original ;
603621 } , 2000 ) ;
604622
605- // Track command copy
606- analytics . track ( 'command_copied ', { command : text . split ( '\n' ) [ 0 ] } ) ;
623+ // Track command copy with GoatCounter
624+ trackEvent ( 'command-copied ', 'Copied install command' ) ;
607625 } ) ;
608626 }
609627
610628 // ===============================
611629 // GITHUB BUTTON CLICK TRACKING
612630 // ===============================
613631 document . getElementById ( 'github-btn' ) ?. addEventListener ( 'click' , ( ) => {
614- analytics . track ( 'github_click ', { location : ' nav' } ) ;
632+ trackEvent ( 'github-click-nav ', 'Clicked GitHub button in nav') ;
615633 } ) ;
616634
617635 // Track all footer GitHub links
618636 document . querySelectorAll ( 'footer a' ) . forEach ( link => {
619637 link . addEventListener ( 'click' , ( ) => {
620- analytics . track ( 'footer_link_click' , { href : link . href } ) ;
638+ const linkName = link . textContent . trim ( ) ;
639+ trackEvent ( 'footer-click-' + linkName . toLowerCase ( ) , 'Clicked ' + linkName + ' in footer' ) ;
621640 } ) ;
622641 } ) ;
623642
0 commit comments