Serverless Wiki Analytics
A privacy-respecting, zero-cookie analytics framework designed for static documentation sites. This loop uses Google Apps Script as a serverless backend gateway to record chronological page-view telemetry into a designated Google Sheet, completely bypassing consumer ad-blocker lists with minimal execution overhead and absolute tracker security.
Apps Script Backend Configuration
Create a fresh deployment inside the Google Apps Script environment using the standalone engine below. The system includes a global mutex script lock to safely queue concurrent page pings during rapid navigation bursts. Ensure your web app deployment settings are configured to execute as "Me" and allow access to "Anyone" to receive incoming pings.
function doPost(e) {
const lock = LockService.getScriptLock();
try {
lock.waitLock(30000); // 30-second execution queue buffer
if (!e || !e.postData || !e.postData.contents) {
return ContentService.createTextOutput("EMPTY_BODY").setMimeType(ContentService.MimeType.TEXT);
}
const data = JSON.parse(e.postData.contents);
const sheetId = 'YOUR_GOOGLE_SHEET_ID_HERE';
const sheet = SpreadsheetApp.openById(sheetId).getActiveSheet();
sheet.appendRow([
new Date(),
data.page || 'unknown',
data.time || new Date().toISOString()
]);
return ContentService.createTextOutput("SUCCESS").setMimeType(ContentService.MimeType.TEXT);
} catch(err) {
console.error('Tracking Failed: ' + err.toString());
return ContentService.createTextOutput("ERROR: " + err.toString()).setMimeType(ContentService.MimeType.TEXT);
} finally {
lock.releaseLock();
}
}
Client Snippet & Admin Kill Switch
Inject this asynchronous tracker into your custom theme layout block (e.g., an overridden theme layout template file). Because Google sandboxes web app environments for privacy, filtering out personal traffic by client-side public IP is unreliable. Instead, self-exclude your administration devices by running
localStorage.setItem('skip_analytics', 'true');
in your browser development console (F12) to abort telemetry pings permanently.
<script>
if (localStorage.getItem('skip_analytics') === 'true') {
console.log("Self-enrolled privacy mode: Tracking skipped.");
} else {
// SEND INJECTED TRACKING PING TO GOOGLE APPS SCRIPT
const wikiPage = 'Wiki: ' + window.location.pathname;
fetch('[https://script.google.com/macros/s/AKfycbyfFybhWPso9Zi9vTO5jpHEI_j768JYHG56mxglaUFCSZ7bvVnI42_F1QOIRvFkQOHD/exec](https://script.google.com/macros/s/AKfycbyfFybhWPso9Zi9vTO5jpHEI_j768JYHG56mxglaUFCSZ7bvVnI42_F1QOIRvFkQOHD/exec)', {
method: 'POST',
mode: 'no-cors', // Essential for Google Apps Script to handle cross-origin payloads properly
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
page: wikiPage,
time: new Date().toISOString()
})
}).catch(err => console.log('Analytics ping failed.', err));
}
</script>
Posted
10:12 19 Jun 2026