@@ -62,24 +62,30 @@ function addMatomoStatistics() {
6262 return ;
6363 }
6464
65- ( window as any ) . _paq = ( window as any ) . _paq || [ ] ;
65+ try {
66+ ( window as any ) . _paq = ( window as any ) . _paq || [ ] ;
6667
67- // Push all configuration commands first
68- ( window as any ) . _paq . push ( [ 'setTrackerUrl' , environment . matomo . hostUrl + 'matomo.php' ] ) ;
69- ( window as any ) . _paq . push ( [ 'setSiteId' , environment . matomo . siteId ] ) ;
70- ( window as any ) . _paq . push ( [ 'enableLinkTracking' ] ) ;
68+ // Push all configuration commands first
69+ ( window as any ) . _paq . push ( [ 'setTrackerUrl' , environment . matomo . hostUrl + 'matomo.php' ] ) ;
70+ ( window as any ) . _paq . push ( [ 'setSiteId' , environment . matomo . siteId ] ) ;
71+ ( window as any ) . _paq . push ( [ 'enableLinkTracking' ] ) ;
7172
72- const g = document . createElement ( 'script' ) ;
73- g . type = 'text/javascript' ;
74- g . async = true ;
75- g . defer = true ;
76- g . src = environment . matomo . hostUrl + 'matomo.js' ;
77- document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( g ) ;
73+ const g = document . createElement ( 'script' ) ;
74+ g . type = 'text/javascript' ;
75+ g . async = true ;
76+ g . defer = true ;
77+ g . src = environment . matomo . hostUrl + 'matomo.js' ;
78+ document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( g ) ;
79+ } catch ( error ) {
80+ if ( ! environment . production ) {
81+ console . error ( 'Error initializing Matomo:' , error ) ;
82+ }
83+ }
7884}
7985
8086// support async tag or hmr
8187if ( document . readyState === 'complete' && ! hasTransferState ) {
8288 void main ( ) ;
8389} else {
84- document . addEventListener ( 'DOMContentLoaded' , ( ) => main ( ) ) ;
90+ document . addEventListener ( 'DOMContentLoaded' , ( ) => void main ( ) ) ;
8591}
0 commit comments