File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change 1
1
<!-- Display GoatCounter pageviews -->
2
2
< script >
3
- let pv = document . getElementById ( 'pageviews' ) ;
3
+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
4
+ const pv = document . getElementById ( 'pageviews' ) ;
4
5
5
- if ( pv !== null ) {
6
- const uri = location . pathname . replace ( / \/ $ / , '' ) ;
7
- const url = `https://{{ site.analytics.goatcounter.id }}.goatcounter.com/counter/${ encodeURIComponent ( uri ) } .json` ;
6
+ if ( pv !== null ) {
7
+ const uri = location . pathname . replace ( / \/ $ / , '' ) ;
8
+ const url = `https://{{ site.analytics.goatcounter.id }}.goatcounter.com/counter/${ encodeURIComponent ( uri ) } .json` ;
8
9
9
- fetch ( url )
10
+ fetch ( url )
10
11
. then ( ( response ) => response . json ( ) )
11
12
. then ( ( data ) => {
12
13
const count = data . count . replace ( / \s / g, '' ) ;
15
16
. catch ( ( error ) => {
16
17
pv . innerText = '1' ;
17
18
} ) ;
18
- }
19
+ }
20
+ } ) ;
19
21
</ script >
You can’t perform that action at this time.
0 commit comments