Follow these 4 steps to capture all exam data in your own Google Sheet:
- Open Google Sheets -> create a new spreadsheet.
- In Row 1, add these exact headers (A->N):
Timestamp | Name | Email | Phone | Topic | Score% | Correct | Wrong | Violations | TimeTaken | ViolationLog | ResultMessage | EmailStatus | FaceSnapshotUrl
- Go to Extensions -> Apps Script. Replace all existing code
with:
function saveFaceSnapshot(d) {
if (!d.faceSnapshot) return '';
var match = d.faceSnapshot.match(/^data:(image\/[a-zA-Z0-9.+-]+);base64,(.+)$/);
if (!match) return '';
var mimeType = match[1];
var bytes = Utilities.base64Decode(match[2]);
var safeName = String(d.name || 'candidate').replace(/[^a-zA-Z0-9_-]/g, '_');
var timestamp = Utilities.formatDate(new Date(), 'Asia/Kolkata', 'yyyyMMdd_HHmmss');
var blob = Utilities.newBlob(bytes, mimeType, 'face_' + safeName + '_' + timestamp + '.jpg');
var file = DriveApp.createFile(blob);
return file.getUrl();
}
function saveSubmission(d) {
var sheet = SpreadsheetApp
.getActiveSpreadsheet()
.getActiveSheet();
var faceSnapshotUrl = '';
try {
faceSnapshotUrl = saveFaceSnapshot(d);
} catch (err) {
faceSnapshotUrl = 'Failed: ' + err.message;
}
var emailStatus = 'Not sent';
try {
if (d.email) {
MailApp.sendEmail({
to: d.email,
subject: 'ParikshaSetu Scholarship Test Submitted',
body: d.resultMessage
});
emailStatus = 'Sent to ' + d.email;
} else {
emailStatus = 'Failed: No email found';
}
} catch (err) {
emailStatus = 'Failed: ' + err.message;
}
sheet.appendRow([
d.timestamp, d.name, d.email, d.phone,
d.topic, d.score, d.correct, d.wrong,
d.violations, d.timeTaken, d.violationLog,
d.resultMessage, emailStatus, faceSnapshotUrl
]);
return ContentService
.createTextOutput(JSON.stringify({status:'ok', emailStatus:emailStatus, faceSnapshotUrl:faceSnapshotUrl}))
.setMimeType(ContentService.MimeType.JSON);
}
function doPost(e) {
return saveSubmission(JSON.parse(e.postData.contents));
}
function doGet(e) {
return saveSubmission(JSON.parse(e.parameter.data));
}
- Click Deploy -> New deployment -> Web app.
Set
Execute as = Me, Who has access = Anyone. Click Deploy.
- Copy the Web App URL and paste it into the URL field on the
login screen.
Warning: If you see a CORS error in the browser console, that's normal - the data is still submitted correctly
via no-cors mode.