@@ -96,64 +96,66 @@ const umamiRegion = profileConfig.umami?.region || "eu";
9696 </div >
9797
9898 <script is :inline define :vars = { {umamiShareId , umamiRegion }} >
99- const fetchUmamiStatss = async () => {
99+ const fetchUmamiStats = async () => {
100100 try {
101101 const pathname = window .location .pathname ;
102102 const shareId = umamiShareId ;
103103 const region = umamiRegion ;
104- console.log(' shareId:' , shareId , ' region:' , region);
105- console.log(' pathname:' , pathname);
104+ console.log(' PostMeta shareId:' , shareId , ' region:' , region);
105+ console.log(' PostMeta pathname:' , pathname);
106106
107107 const shareRes = await fetch (` https://${region }.umami.is/api/share/${shareId } ` );
108- console.log(' shareRes status:' , shareRes.status);
108+ console.log(' PostMeta shareRes status:' , shareRes.status);
109109
110110 if (!shareRes.ok) {
111111 throw new Error (` Share API failed: ${shareRes .status } ` );
112112 }
113113
114114 const shareData = await shareRes .json ();
115- console.log(' shareData:' , shareData);
115+ console.log(' PostMeta shareData:' , shareData);
116116 const token = shareData .token ;
117117 const websiteId = shareData .websiteId || shareData .website_id || shareData .id ;
118- console.log(' token:' , token , ' websiteId:' , websiteId);
118+ console.log(' PostMeta token:' , token , ' websiteId:' , websiteId);
119119
120- const statsUrl = ` https://${region }.umami.is/api/websites/${websiteId }/stats? ` +
121- new URLSearchParams({
122- startAt : ' 1753333200000' ,
123- endAt : Date .now (),
124- unit : ' hour' ,
125- timezone : ' Asia/Hong_Kong ' ,
126- url : pathname ,
127- compare : ' false' ,
128- });
129- console.log(' statsUrl:' , statsUrl );
130-
131- const res = await fetch (statsUrl , {
132- method: ' GET' ,
133- headers: {
134- ' x-umami-share-token' : token ,
135- },
120+ const url = ` https://${region }.umami.is/api/websites/${websiteId }/stats? ` +
121+ new URLSearchParams({
122+ startAt : ' 1753333200000' ,
123+ endAt : Date .now (),
124+ unit : ' hour' ,
125+ timezone : ' Asia/Shanghai ' ,
126+ url : pathname ,
127+ compare : ' false' ,
128+ });
129+ console.log(' PostMeta statsUrl:' , url );
130+
131+ const res = await fetch (url , {
132+ method: ' GET' ,
133+ headers: {
134+ ' x-umami-share-token' : token ,
135+ },
136136 });
137- console.log(' stats res status:' , res.status);
137+ console.log(' PostMeta stats res status:' , res.status);
138+
139+ const data = await res .json ();
140+ console.log(' PostMeta stats data:' , data);
138141
139- if (!res.ok) {
142+ if (res.ok) {
143+ const pageviews = data ?.pageviews ?.value ?? ' N/A' ;
144+ const visits = data ?.visits ?.value ?? ' N/A' ;
145+ document .getElementById (' post-umami-pageviews' ).textContent = pageviews ;
146+ document .getElementById (' post-umami-visits' ).textContent = visits ;
147+ } else {
140148 document .getElementById (' post-umami-pageviews' ).textContent = ' N/A' ;
141149 document .getElementById (' post-umami-visits' ).textContent = ' N/A' ;
142- return ;
143150 }
144- const data = await res .json ();
145- console.log(' stats data:' , data);
146- document.getElementById(' post-umami-pageviews' ).textContent = data.pageviews?.value ?? ' N/A' ;
147- document.getElementById(' post-umami-visits' ).textContent = data.visits?.value ?? ' N/A' ;
148151 } catch (error ) {
149- console.error(' Umami stats error:' , error);
152+ console.error(' PostMeta Umami stats error:' , error);
150153 document.getElementById(' post-umami-pageviews' ).textContent = ' Error' ;
151154 document.getElementById(' post-umami-visits' ).textContent = ' Error' ;
152155 }
153156 };
154- fetchUmamiStatss();
155- setInterval(fetchUmamiStatss, 5000);
157+ fetchUmamiStats();
156158 </script>
157159 </>
158160 )}
159- </div>
161+ </div>
0 commit comments