Entries
0 entries
▼
Spin History
Results are saved to your connected Google Sheet automatically once configured in Settings.
0 entries
Results are saved to your connected Google Sheet automatically once configured in Settings.
Connect a Google Sheet so every spin result (timestamp, winner, and the full option list) is saved automatically. Follow the steps below once, then paste the URL you get at the end into the field at the bottom.
Code.gs and paste in the script below.
/**
* Google Apps Script backend for the Wheel Spinner site.
* Deploy this as a Web App and paste the resulting /exec URL
* into the site's Settings panel.
*/
const SHEET_NAME = "Spins";
function getSheet_() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
let sheet = ss.getSheetByName(SHEET_NAME);
if (!sheet) {
sheet = ss.insertSheet(SHEET_NAME);
sheet.appendRow(["Timestamp", "Winner", "Options"]);
}
return sheet;
}
function doPost(e) {
try {
const data = JSON.parse(e.postData.contents);
const sheet = getSheet_();
sheet.appendRow([
data.timestamp ? new Date(data.timestamp) : new Date(),
data.winner || "",
Array.isArray(data.options) ? data.options.join(", ") : "",
]);
return ContentService
.createTextOutput(JSON.stringify({ status: "success" }))
.setMimeType(ContentService.MimeType.JSON);
} catch (err) {
return ContentService
.createTextOutput(JSON.stringify({ status: "error", message: err.message }))
.setMimeType(ContentService.MimeType.JSON);
}
}
function doGet(e) {
try {
const sheet = getSheet_();
const values = sheet.getDataRange().getValues();
const [header, ...rows] = values;
const records = rows.map((row) => {
const record = {};
header.forEach((key, i) => (record[key] = row[i]));
return record;
});
return ContentService
.createTextOutput(JSON.stringify({ status: "success", records }))
.setMimeType(ContentService.MimeType.JSON);
} catch (err) {
return ContentService
.createTextOutput(JSON.stringify({ status: "error", message: err.message }))
.setMimeType(ContentService.MimeType.JSON);
}
}
/exec).