@profullstack/waitlist 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -89,3 +89,14 @@ a list per domain in the owner's dashboard, `waitlist.signup` domain webhooks):
89
89
  Both send `Access-Control-Allow-Origin: *`.
90
90
 
91
91
  MIT
92
+
93
+ ## A/B testing the look (0.3)
94
+
95
+ Every built page runs one experiment by default, `waitlist-look-v1`: the page's own themed
96
+ look (control) against the high converting looks from `@profullstack/css` (`clarity`,
97
+ `split`, `midnight`, `urgency`). A tiny script in `<head>` gives each visitor a sticky id and
98
+ picks their arm before first paint, with the same hash as `@profullstack/abtest`, so the
99
+ page and [CrawlProof](https://crawlproof.com/dashboard/experiments/waitlist-look-v1) agree.
100
+ The page reports one exposure a day; a signup is the conversion. Both go through the
101
+ waitlist API, which holds the CrawlProof token. Stop the experiment with a winner in
102
+ CrawlProof and every page switches to it. Turn it off per site with `"ab": false`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@profullstack/waitlist",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Email waitlist for any launch page: a <waitlist-form> web component, a live signup chart, and a static-site builder on @profullstack/css + @profullstack/charts.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -46,8 +46,11 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@profullstack/charts": "^0.3.0",
49
- "@profullstack/css": "^0.4.0",
49
+ "@profullstack/css": "^0.6.0",
50
50
  "@profullstack/footer": "^0.7.3",
51
51
  "@resvg/resvg-js": "^2.6.2"
52
+ },
53
+ "devDependencies": {
54
+ "@profullstack/abtest": "^0.1.0"
52
55
  }
53
56
  }
package/src/build.js CHANGED
@@ -19,8 +19,36 @@ const here = dirname(fileURLToPath(import.meta.url));
19
19
  /** The crawlproof project every Moshpit landing and parked page reports to. */
20
20
  export const MOSHPIT_STATS_SITE = '2cbffe9d-1b6e-43f0-85f3-3cadee132048';
21
21
 
22
- /** Every look @profullstack/css/looks ships. */
23
- export const LOOKS = ['neon', 'matrix', 'terminal', 'amber', 'synthwave', 'geocities', 'vaporwave'];
22
+ /**
23
+ * The default A/B test: the page's themed look (control) against the high
24
+ * converting looks from @profullstack/css, recorded in CrawlProof through the
25
+ * waitlist API (moshcoding.com /api/waitlist/ab). Pass `ab: false` to turn it off.
26
+ */
27
+ export const DEFAULT_AB = { experiment: 'waitlist-look-v1', arms: ['themed', 'clarity', 'split', 'midnight', 'urgency'] };
28
+
29
+ /**
30
+ * Runs in <head> before first paint: a sticky visitor id, the arm from the same
31
+ * cyrb53 hash as @profullstack/abtest's assignArm (equal weights), or a declared
32
+ * winner. Sets data-look and window.__wlab. Tiny and dependency-free on purpose.
33
+ */
34
+ export function abHeadScript(ab, themed) {
35
+ const cfg = JSON.stringify({ e: ab.experiment, a: ab.arms, t: themed }).replace(/</g, '\\u003c');
36
+ return `<script>(function(c){try{var L=localStorage,u=L.getItem("wl-unit");if(!u){u=Array.from(crypto.getRandomValues(new Uint8Array(12)),function(b){return(b%36).toString(36)}).join("");L.setItem("wl-unit",u)}
37
+ function h(s){var a=3735928559,b=1103547991;for(var i=0;i<s.length;i++){var k=s.charCodeAt(i);a=Math.imul(a^k,2654435761);b=Math.imul(b^k,1597334677)}a=Math.imul(a^a>>>16,2246822507);a^=Math.imul(b^b>>>13,3266489909);b=Math.imul(b^b>>>16,2246822507);b^=Math.imul(a^a>>>13,3266489909);return 4294967296*(2097151&b)+(a>>>0)}
38
+ var w=L.getItem("wl-winner:"+c.e),arm=w&&c.a.indexOf(w)>=0?w:c.a[Math.floor(h(c.e+"\\0"+u)/Math.pow(2,53)*c.a.length)],d=document.documentElement;
39
+ d.dataset.look=arm==="themed"?c.t:arm;d.dataset.abArm=arm;window.__wlab={experiment:c.e,unit:u,arm:arm,themed:c.t,winner:!!w}}catch(x){}})(${cfg});</script>`;
40
+ }
41
+
42
+ /** Every look @profullstack/css/looks ships (0.6). */
43
+ export const LOOKS = [
44
+ 'neon', 'matrix', 'terminal', 'amber', 'synthwave', 'geocities', 'vaporwave',
45
+ 'prodigy', 'aol', 'compuserve', 'bbs', 'minitel',
46
+ 'editorial', 'swiss', 'brutalist', 'glass', 'bento',
47
+ 'clarity', 'split', 'midnight', 'urgency',
48
+ 'whitecube', 'darkroom', 'polaroid', 'storefront', 'boutique', 'market',
49
+ ];
50
+ /** Looks a name can get by default (its themed look); the high converting ones belong to the A/B test. */
51
+ const THEMED = ['neon', 'matrix', 'terminal', 'amber', 'synthwave', 'geocities', 'vaporwave', 'prodigy', 'aol', 'compuserve', 'bbs', 'minitel', 'editorial', 'swiss', 'brutalist', 'glass', 'bento'];
24
52
 
25
53
  /**
26
54
  * A look that fits the name when none is given: newsgroup hierarchies get their
@@ -29,14 +57,14 @@ export const LOOKS = ['neon', 'matrix', 'terminal', 'amber', 'synthwave', 'geoci
29
57
  */
30
58
  export function lookFor(name) {
31
59
  const first = name.split('.')[0];
32
- const byPrefix = { comp: 'terminal', news: 'amber', alt: 'geocities', sci: 'matrix', rec: 'synthwave', soc: 'vaporwave', talk: 'neon', misc: 'amber' };
60
+ const byPrefix = { comp: 'terminal', news: 'compuserve', alt: 'geocities', sci: 'matrix', rec: 'synthwave', soc: 'aol', talk: 'bbs', misc: 'prodigy' };
33
61
  if (byPrefix[first]) return byPrefix[first];
34
62
  const ending = name.split('.').pop();
35
- const byEnding = { cli: 'terminal', pit: 'terminal', dns: 'terminal', v6: 'terminal', onions: 'matrix', agent: 'matrix', desktop: 'vaporwave', politics: 'neon', lobby: 'amber', whatever: 'geocities', yeah: 'synthwave', rank: 'neon' };
63
+ const byEnding = { cli: 'terminal', pit: 'terminal', dns: 'terminal', v6: 'amber', onions: 'matrix', agent: 'matrix', desktop: 'vaporwave', politics: 'editorial', lobby: 'swiss', whatever: 'geocities', yeah: 'synthwave', rank: 'glass', station: 'minitel', indie: 'bento', gambling: 'brutalist' };
36
64
  if (byEnding[ending]) return byEnding[ending];
37
65
  let h = 0;
38
66
  for (const ch of name) h = (h * 31 + ch.charCodeAt(0)) >>> 0;
39
- return LOOKS[h % LOOKS.length];
67
+ return THEMED[h % THEMED.length];
40
68
  }
41
69
 
42
70
  /** A Moshpit name (label.ending, no dot-TLD of the old internet) -> its pit.world relay host. */
@@ -79,6 +107,7 @@ export function normalize(spec) {
79
107
  look: LOOKS.includes(spec.look) ? spec.look : lookFor(name),
80
108
  marquee: spec.marquee || `Welcome to ${name}! You are visitor #000${(name.length * 7919) % 9000 + 1000}. Sign the waitlist below!`,
81
109
  crawlproof: spec.crawlproof === undefined ? (moshpit ? MOSHPIT_STATS_SITE : null) : spec.crawlproof,
110
+ ab: spec.ab === false ? null : { ...DEFAULT_AB, ...(spec.ab || {}) },
82
111
  lang: spec.lang || 'en',
83
112
  locale: spec.locale || 'en_US',
84
113
  siteName: spec.siteName || spec.title || name,
@@ -113,6 +142,7 @@ export function pageHtml(s, { footers = '', noindex = false } = {}) {
113
142
  <head>
114
143
  <meta charset="utf-8">
115
144
  <meta name="viewport" content="width=device-width, initial-scale=1">
145
+ ${s.ab ? abHeadScript(s.ab, s.look) : ''}
116
146
  ${headTags(s, { noindex })}
117
147
  <link rel="stylesheet" href="assets/profullstack.css">
118
148
  <link rel="stylesheet" href="assets/looks.css">
package/src/index.js CHANGED
@@ -42,14 +42,44 @@ export function messageFor(res, email) {
42
42
  }
43
43
 
44
44
  /** POST one signup. Resolves to the API body plus `status`; never throws on HTTP errors. */
45
- export async function join({ email, dn, ref = null, api = DEFAULT_API, fetchImpl = globalThis.fetch }) {
45
+ /** The page's A/B context set by the head script (window.__wlab), or null. */
46
+ export function abContext() {
47
+ const a = globalThis.__wlab;
48
+ return a && a.experiment && a.unit ? { experiment: a.experiment, unit: a.unit } : null;
49
+ }
50
+
51
+ /**
52
+ * Report that this visitor saw their arm (once per day per experiment), and adopt a
53
+ * winner when the experiment has been stopped with one.
54
+ */
55
+ export async function reportExposure({ api = DEFAULT_API, dn, fetchImpl = globalThis.fetch, storage = globalThis.localStorage } = {}) {
56
+ const a = globalThis.__wlab;
57
+ if (!a || a.winner) return null;
58
+ try {
59
+ const st = await fetchImpl(new URL(`/api/waitlist/ab?experiment=${encodeURIComponent(a.experiment)}`, api).href).then((r) => (r.ok ? r.json() : null));
60
+ if (st && st.status === 'stopped' && st.winner) {
61
+ storage?.setItem(`wl-winner:${a.experiment}`, st.winner);
62
+ if (globalThis.document) document.documentElement.dataset.look = st.winner === 'themed' ? a.themed : st.winner;
63
+ return { winner: st.winner };
64
+ }
65
+ const key = `wl-exposed:${a.experiment}:${new Date().toISOString().slice(0, 10)}`;
66
+ if (storage?.getItem(key)) return { already: true };
67
+ await fetchImpl(new URL('/api/waitlist/ab', api).href, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ experiment: a.experiment, unit: a.unit, dn }) });
68
+ storage?.setItem(key, '1');
69
+ return { exposed: a.arm };
70
+ } catch {
71
+ return null;
72
+ }
73
+ }
74
+
75
+ export async function join({ email, dn, ref = null, api = DEFAULT_API, fetchImpl = globalThis.fetch, ab = abContext() }) {
46
76
  const clean = cleanEmail(email);
47
77
  if (!clean) return { ok: false, status: 400, error: "That doesn't look like an email." };
48
78
  try {
49
79
  const res = await fetchImpl(new URL('/api/waitlist', api).href, {
50
80
  method: 'POST',
51
81
  headers: { 'content-type': 'application/json' },
52
- body: JSON.stringify({ email: clean, dn, ref }),
82
+ body: JSON.stringify(ab ? { email: clean, dn, ref, ab } : { email: clean, dn, ref }),
53
83
  });
54
84
  const body = await res.json().catch(() => ({}));
55
85
  return { ...body, ok: Boolean(res.ok && body.ok), status: res.status };
@@ -79,6 +109,7 @@ export class WaitlistForm extends HTMLElementBase {
79
109
  connectedCallback() {
80
110
  if (this.dataset.ready) return;
81
111
  this.dataset.ready = '1';
112
+ reportExposure({ api: this.getAttribute('api') || DEFAULT_API, dn: this.getAttribute('dn') || location.hostname });
82
113
  const id = `wl-${Math.random().toString(36).slice(2, 8)}`;
83
114
  this.innerHTML = `
84
115
  <form class="stack waitlist-form" novalidate>
package/src/seo.js CHANGED
@@ -168,12 +168,12 @@ export function llmsTxt(s) {
168
168
  '',
169
169
  `- Status: waitlist (not launched yet)`,
170
170
  `- Site: ${s.url}`,
171
- s.moshpit ? `- Moshpit name: https://${s.name}` : '',
172
- s.audience ? `- Who it is for: ${s.audience}` : '',
173
- `- How to join: enter an email at ${s.url} and confirm it, or POST {"email","dn":"${s.dn}"} to ${s.api}/api/waitlist`,
171
+ s.moshpit ? `- Moshpit name: https://${s.name}` : null,
172
+ s.audience ? `- Who it is for: ${s.audience}` : null,
173
+ `- How to join: enter an email at ${s.url} and confirm it, or POST {"email":"you@example.com","dn":"${s.dn}"} to ${s.api}/api/waitlist`,
174
174
  `- Waitlist count: ${s.api}/api/waitlist/stats?dn=${encodeURIComponent(s.dn)}`,
175
175
  '',
176
- ].filter((l, i, a) => l !== '' || a[i - 1] !== '');
176
+ ].filter((l) => l !== null);
177
177
  if (s.points.length) lines.push('## What is coming', '', ...s.points.map((p) => `- ${p}`), '');
178
178
  lines.push('## Questions', '');
179
179
  for (const f of s.faq) lines.push(`### ${f.q}`, '', f.a, '');