RezinaLMS-CustomerEnd/tools/waitlist-apps-script.gs
kirukib 270d36a237 feat(waitlist): SMS or email signup, motion, portrait reel, contact footer
- Hero toggle: SMS (default, international picker) or Email; step 2 asks only the name
- Apps Script accepts either contact, dedupes on email or phone (checks updated)
- Headline words rise in, sections and course photos reveal on scroll, hero photos drift
- Portrait reel under the hero; courses swipe on phones; Why us as big numbers on hairlines
- Footer: landing-style card with Contact us (Telegram, phone, email), credits, Powered by Yaltopia Tech

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 14:20:33 +03:00

68 lines
3.4 KiB
JavaScript

/**
* Waitlist receiver for apps/demo/public/waitlist/index.html → one row per signup in a Google Sheet.
*
* Setup (once, in the Google account that should own the list):
* 1. Create a Google Sheet, e.g. "Sirkul Makeup waitlist".
* 2. Extensions → Apps Script. Replace Code.gs with this file and save.
* 3. Deploy → New deployment → type "Web app". Execute as: Me. Who has access: Anyone.
* 4. Authorize, then copy the Web app URL (ends in /exec).
* 5. Paste it into ENDPOINT (the page POSTs signups and GETs the count) in apps/demo/public/waitlist/index.html, then commit and deploy.
* After editing this script, use Deploy → Manage deployments → Edit → New version (the URL stays the same).
*/
const SHEET_NAME = 'Signups';
const HEADER = ['Signed up (UTC)', 'Name', 'Email', 'Phone', 'Language', 'Page'];
function doPost(e) {
let data;
try { data = JSON.parse((e && e.postData && e.postData.contents) || '{}'); } catch (_) { return reply({ ok: false, error: 'bad_json' }); }
if (data.company) return reply({ ok: true }); // honeypot filled → bot; pretend success
const row = clean(data);
if (row.error) return reply({ ok: false, error: row.error });
const lock = LockService.getScriptLock();
lock.waitLock(10000);
try {
const sheet = getSheet();
const last = sheet.getLastRow();
// Email (col C) and phone (col D) either may be blank; a match on either one is the same person.
const seen = last > 1 ? sheet.getRange(2, 3, last - 1, 2).getValues().some((r) => (row.email && String(r[0]).toLowerCase() === row.email) || (row.phone && String(r[1]).replace(/^'/, '') === row.phone)) : false;
if (!seen) {
sheet.appendRow([new Date().toISOString(), safe(row.name), safe(row.email), row.phone ? "'" + row.phone : '', safe(row.locale), safe(row.page)]);
}
} finally { lock.releaseLock(); }
return reply({ ok: true });
}
/** Public signup count for the page's "people waiting" pill. Only the number leaves the sheet. */
function doGet() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SHEET_NAME);
return reply({ ok: true, count: sheet ? Math.max(0, sheet.getLastRow() - 1) : 0 });
}
/** Server-side check: the page validates too, but anyone can POST here. */
function clean(d) {
const name = String(d.name || '').trim().slice(0, 80);
const email = String(d.email || '').trim().toLowerCase().slice(0, 120);
const phone = String(d.phone || '').replace(/[\s()-]/g, '');
// People sign up by SMS or by email: a name plus at least one valid contact.
if (name.length < 2) return { error: 'name' };
if (email && !/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email)) return { error: 'email' };
if (phone && !/^\+\d{8,15}$/.test(phone)) return { error: 'phone' };
if (!email && !phone) return { error: 'contact' };
return { name, email, phone, locale: String(d.locale || '').slice(0, 20), page: String(d.page || '').slice(0, 200) };
}
/** Cells starting with = + - @ would run as formulas when someone opens the sheet. */
function safe(v) { return /^[=+\-@]/.test(v) ? "'" + v : v; }
function getSheet() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
let sheet = ss.getSheetByName(SHEET_NAME);
if (!sheet) { sheet = ss.insertSheet(SHEET_NAME); sheet.appendRow(HEADER); sheet.setFrozenRows(1); }
return sheet;
}
function reply(obj) {
return ContentService.createTextOutput(JSON.stringify(obj)).setMimeType(ContentService.MimeType.JSON);
}