@sqid-dev/playground 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +67 -2
- package/bin/sqid-playground.js +7 -0
- package/package.json +40 -4
- package/public/panel.css +76 -0
- package/public/panel.js +354 -0
- package/public/recipes.js +194 -0
- package/public/site.css +115 -0
- package/public/site.js +89 -0
- package/src/index.js +70 -0
- package/src/layout.js +89 -0
- package/src/pages/cart.html +16 -0
- package/src/pages/demo.html +19 -0
- package/src/pages/desk.html +23 -0
- package/src/pages/desks.html +18 -0
- package/src/pages/home.html +25 -0
- package/src/pages/pricing.html +29 -0
- package/src/pages/signin.html +13 -0
- package/src/pages/teams.html +11 -0
- package/src/server.js +65 -0
- package/src/sqid.js +167 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SQID
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,68 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Sqid Playground
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A real-looking website with the Sqid panel docked on the side. Open it and watch yourself get
|
|
4
|
+
identified. Try the scenarios, switch recipes on and off, read the record that goes out, then put
|
|
5
|
+
Sqid on your own site from the same panel.
|
|
6
|
+
|
|
7
|
+
The site is **Driftwood**, a made-up standing-desk company: a home page, a product with sizes and
|
|
8
|
+
finishes, pricing, a demo form, a cart and a sign-in. Everything on it exists so you can see what
|
|
9
|
+
Sqid does with it. The panel shows what the SDK on the page actually did; nothing is mocked.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npx -y @sqid-dev/playground
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
That signs you in to Sqid (browser), finds your account's Sandbox site, allows `http://localhost:3000`
|
|
16
|
+
on it, and opens the site. The Sandbox hands every new visitor one of fifty made-up people and never
|
|
17
|
+
spends a credit, so the identification, the webhook record and the recipes all run for real.
|
|
18
|
+
|
|
19
|
+
From Claude Code, the Sqid MCP server offers the same thing when you say "set up Sqid" and have no
|
|
20
|
+
website to paste the snippet into.
|
|
21
|
+
|
|
22
|
+
## What you can try
|
|
23
|
+
|
|
24
|
+
| Tab | What it does |
|
|
25
|
+
| --- | --- |
|
|
26
|
+
| **Start** | The five-step checklist (signed in, site, script, webhook, stream live) and the reveal: anonymous visitor, then the person, with the time it took. "Watch it again" replays it. (The Sandbox pins one person to a device; a private window gets another.) |
|
|
27
|
+
| **Live** | Every SDK event and page action, newest first: connected, `visitor.identified`, clicks, variant switches, form stalls. |
|
|
28
|
+
| **Scenarios** | Who you are right now, and a checklist of things to try on the site: switch sizes without buying, sign in and call `squid.identify()`, stall on the form, sit on the cart, return to pricing, labelled clicks, exit intent. |
|
|
29
|
+
| **Recipes** | The docs recipes, live on this site: DOM personalisation, pricing personalisation, chat, form prefill, exit intent, analytics, the service-provider pattern against a built-in mock database. Toggle one and the page changes; the code shown is the code from the docs. |
|
|
30
|
+
| **Delivery** | Your webhooks on the site (add any https endpoint, send a test), this visitor's full record from the visitor API, and a webhook sample. |
|
|
31
|
+
| **Go live** | Create a real site from its URL and get the snippet, the MCP and CLI one-liners for your app, the API and OEM links for embedding, and the plan box with "Add a card". |
|
|
32
|
+
|
|
33
|
+
Moments (Signals) never fire on a Sandbox site. Add a card in the console and turn Signals on for a
|
|
34
|
+
real site to see `visitor.moment` and the moment webhook.
|
|
35
|
+
|
|
36
|
+
## Options
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
sqid-playground [--port 3000] [--site <id|name>] [--no-open] [--api <origin>]
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Sign-in is the sqid CLI's: `~/.config/sqid/credentials.json`, or `SQID_TOKEN`. `npx -y @sqid-dev/sqid auth login`
|
|
43
|
+
signs in ahead of time; otherwise the playground asks on first run.
|
|
44
|
+
|
|
45
|
+
## How it works
|
|
46
|
+
|
|
47
|
+
- `src/index.js` parses the options and starts the server.
|
|
48
|
+
- `src/sqid.js` is the bridge to the account: sign-in, the Sandbox, origins, webhooks, the visitor
|
|
49
|
+
API (with a key bound to the site), creating a real site. It reuses the sqid CLI's modules, so there
|
|
50
|
+
is one copy of auth.
|
|
51
|
+
- `src/server.js` serves the pages and a small local API under `/_sqid` (localhost only).
|
|
52
|
+
- `src/layout.js` and `src/pages/` are Driftwood. The real Sqid snippet goes before `</head>`.
|
|
53
|
+
- `public/panel.js` is the panel; `public/recipes.js` the recipes; `public/site.js` the site's own
|
|
54
|
+
behaviour (variant picker, cart, sign-in calling `squid.identify`).
|
|
55
|
+
|
|
56
|
+
Nothing is stored except what the CLI already keeps. Scenario progress and recipe toggles live in
|
|
57
|
+
your browser's localStorage.
|
|
58
|
+
|
|
59
|
+
## Development
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
git clone https://github.com/sqid-dev/playground && cd playground
|
|
63
|
+
npm install
|
|
64
|
+
npm test
|
|
65
|
+
npm start
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
MIT. Driftwood and every person the Sandbox hands out are fictional.
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqid-dev/playground",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A real-looking website (Driftwood, a desk company) with a Sqid panel docked on the side: watch a visitor get identified, try the scenarios and recipes, see the record that goes out, then go live on your own site.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"sqid-playground": "bin/sqid-playground.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"src",
|
|
13
|
+
"public",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18.17"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"start": "node bin/sqid-playground.js",
|
|
21
|
+
"test": "node --test test/*.test.js"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@sqid-dev/sqid": "^0.1.0",
|
|
25
|
+
"express": "^4.21.2"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/sqid-dev/playground.git"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://docs.sqid.dev",
|
|
32
|
+
"keywords": [
|
|
33
|
+
"sqid",
|
|
34
|
+
"visitor identification",
|
|
35
|
+
"playground",
|
|
36
|
+
"sandbox",
|
|
37
|
+
"demo"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/public/panel.css
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/* The Sqid panel: dark, docked right, the instrument. */
|
|
2
|
+
.pg-panel{background:#0b0b0d;color:#fafafa;border-left:1px solid #26262b;display:flex;flex-direction:column;font-family:'Inter',system-ui,sans-serif;font-size:13px;position:sticky;top:0;height:100vh;overflow:hidden}
|
|
3
|
+
.pg-panel *{box-sizing:border-box}
|
|
4
|
+
.pg-panel a{color:#22d3ee}
|
|
5
|
+
.pg-top{display:flex;align-items:center;gap:10px;padding:10px 14px;border-bottom:1px solid #26262b;font-size:12px}
|
|
6
|
+
.pg-top .dot{width:8px;height:8px;border-radius:4px;background:#22d3ee;flex-shrink:0}
|
|
7
|
+
.pg-top .name{font-weight:600;letter-spacing:.04em}
|
|
8
|
+
.pg-top .site{color:#a1a1aa;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
9
|
+
.pg-top .conn{margin-left:auto;display:inline-flex;align-items:center;gap:6px;color:#a1a1aa;white-space:nowrap}
|
|
10
|
+
.pg-top .conn i{width:8px;height:8px;border-radius:4px;background:#52525b;display:inline-block}
|
|
11
|
+
.pg-top .conn.on{color:#4ade80}.pg-top .conn.on i{background:#4ade80}
|
|
12
|
+
.pg-tabs{display:flex;gap:0;padding:6px 8px 0;border-bottom:1px solid #26262b}
|
|
13
|
+
.pg-tabs button{padding:9px 8px;border:0;border-bottom:2px solid transparent;background:transparent;color:#a1a1aa;font:inherit;font-size:12.5px;cursor:pointer}
|
|
14
|
+
.pg-tabs button[aria-selected="true"]{color:#fafafa;font-weight:600;border-bottom-color:#22d3ee}
|
|
15
|
+
.pg-body{flex-grow:1;overflow-y:auto;padding:16px 14px;display:flex;flex-direction:column;gap:14px}
|
|
16
|
+
.pg-h{margin:0;font-size:16px;font-weight:600;letter-spacing:-.01em}
|
|
17
|
+
.pg-p{margin:0;color:#a1a1aa;line-height:1.5}
|
|
18
|
+
.pg-label{font-size:11px;font-weight:600;letter-spacing:.08em;color:#71717a}
|
|
19
|
+
.pg-card{display:flex;flex-direction:column;gap:8px;padding:12px;border-radius:10px;background:#141416;border:1px solid #26262b}
|
|
20
|
+
.pg-card.hi{border-color:#22d3ee}
|
|
21
|
+
.pg-card.warn{background:#1a1708;border-color:#713f12}
|
|
22
|
+
.pg-card.warn .pg-label{color:#facc15}
|
|
23
|
+
.pg-row{display:flex;align-items:center;gap:8px}
|
|
24
|
+
.pg-row .grow{flex-grow:1}
|
|
25
|
+
.pg-btn{height:30px;padding:0 11px;border-radius:6px;border:1px solid #3f3f46;background:transparent;color:#fafafa;font:inherit;font-size:12px;cursor:pointer;white-space:nowrap}
|
|
26
|
+
.pg-btn.primary{background:#fafafa;color:#0b0b0d;border-color:#fafafa;font-weight:600}
|
|
27
|
+
.pg-btn.accent{background:#22d3ee;color:#0b0b0d;border-color:#22d3ee;font-weight:600}
|
|
28
|
+
.pg-btn.yellow{background:#facc15;color:#0b0b0d;border-color:#facc15;font-weight:600}
|
|
29
|
+
.pg-btn:disabled{opacity:.5;cursor:default}
|
|
30
|
+
.pg-input{height:34px;border-radius:6px;border:1px solid #3f3f46;background:#0b0b0d;color:#fafafa;padding:0 10px;font:inherit;font-size:12.5px;width:100%}
|
|
31
|
+
.pg-mono{font-family:'JetBrains Mono',monospace;font-size:11.5px;line-height:1.55}
|
|
32
|
+
pre.pg-mono{margin:0;padding:12px;border-radius:8px;background:#141416;border:1px solid #26262b;color:#d4d4d8;overflow-x:auto;white-space:pre}
|
|
33
|
+
.pg-muted{color:#71717a}.pg-ok{color:#4ade80}.pg-acc{color:#22d3ee}.pg-vio{color:#a78bfa}.pg-yel{color:#facc15}
|
|
34
|
+
|
|
35
|
+
.pg-steps{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:8px}
|
|
36
|
+
.pg-step{display:flex;gap:10px;align-items:flex-start;padding:10px 12px;border-radius:10px;background:#141416;border:1px solid #26262b}
|
|
37
|
+
.pg-step.now{border-color:#22d3ee}.pg-step.todo{opacity:.6}
|
|
38
|
+
.pg-step svg{flex-shrink:0;margin-top:1px}
|
|
39
|
+
.pg-step .t{font-weight:500}.pg-step .s{font-size:12px;color:#a1a1aa;line-height:1.45}
|
|
40
|
+
.pg-step .body{display:flex;flex-direction:column;gap:4px;flex-grow:1}
|
|
41
|
+
|
|
42
|
+
.pg-reveal{display:flex;align-items:center;gap:10px}
|
|
43
|
+
.pg-reveal .who{flex:1 1 0;min-width:0;display:flex;flex-direction:column;gap:3px;padding:10px;border-radius:8px;border:1px dashed #3f3f46}
|
|
44
|
+
.pg-reveal .who.known{border:1px solid #22d3ee;background:#0e2a30}
|
|
45
|
+
.pg-reveal .who.anon{opacity:.75}
|
|
46
|
+
.pg-reveal .k{font-size:11px;color:#71717a}.pg-reveal .known .k{color:#22d3ee}
|
|
47
|
+
.pg-reveal .n{font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
48
|
+
.pg-reveal .anon .n{color:#a1a1aa;font-weight:500}
|
|
49
|
+
.pg-reveal .m{font-size:11px;color:#a1a1aa;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
50
|
+
|
|
51
|
+
.pg-log{display:flex;flex-direction:column;gap:5px}
|
|
52
|
+
.pg-log .ev{display:grid;grid-template-columns:52px 1fr;gap:8px;font-family:'JetBrains Mono',monospace;font-size:11.5px;line-height:1.45}
|
|
53
|
+
.pg-log .ev .at{color:#71717a}
|
|
54
|
+
.pg-log .ev .k{font-weight:500}
|
|
55
|
+
.pg-log .ev .d{color:#a1a1aa;word-break:break-word}
|
|
56
|
+
|
|
57
|
+
.pg-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:6px}
|
|
58
|
+
.pg-item{display:flex;align-items:center;gap:10px;padding:9px 12px;border-radius:8px;background:#141416;border:1px solid #26262b}
|
|
59
|
+
.pg-item.now{border-color:#22d3ee}
|
|
60
|
+
.pg-item .r{margin-left:auto;font-size:11px;color:#71717a;white-space:nowrap}
|
|
61
|
+
.pg-item .r a{color:#22d3ee}
|
|
62
|
+
.pg-item svg{flex-shrink:0}
|
|
63
|
+
|
|
64
|
+
.pg-personas{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
|
|
65
|
+
.pg-persona{display:flex;flex-direction:column;gap:2px;align-items:flex-start;padding:10px 12px;border-radius:8px;border:1px solid #26262b;background:#141416;color:#fafafa;font:inherit;text-align:left;cursor:pointer}
|
|
66
|
+
.pg-persona.on{border-color:#22d3ee;background:#0e2a30}
|
|
67
|
+
.pg-persona b{font-size:13px}.pg-persona span{font-size:11px;color:#a1a1aa}
|
|
68
|
+
|
|
69
|
+
.pg-toggle{width:32px;height:18px;border-radius:9px;background:#3f3f46;position:relative;flex-shrink:0;border:0;cursor:pointer;padding:0}
|
|
70
|
+
.pg-toggle i{position:absolute;left:2px;top:2px;width:14px;height:14px;border-radius:7px;background:#a1a1aa}
|
|
71
|
+
.pg-toggle.on{background:#22d3ee}.pg-toggle.on i{left:auto;right:2px;background:#0b0b0d}
|
|
72
|
+
|
|
73
|
+
.pg-tog{display:flex;align-items:center;gap:12px}
|
|
74
|
+
.pg-tog .r{margin-left:auto;font-size:11px;color:#71717a}
|
|
75
|
+
.pg-foot{margin-top:auto;display:flex;flex-direction:column;gap:6px}
|
|
76
|
+
@media (max-width:900px){.pg-panel{position:static;height:auto;max-height:70vh}}
|
package/public/panel.js
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
// The Sqid panel. Six tabs: Start, Live, Scenarios, Recipes, Delivery, Go live. It listens to
|
|
2
|
+
// the real SDK on this page (window.squid), to the page (sqid:page events from site.js) and to
|
|
3
|
+
// the local API (/_sqid/*). Nothing here is mocked: what it shows is what Sqid did.
|
|
4
|
+
(function(){
|
|
5
|
+
'use strict';
|
|
6
|
+
const cfg = window.SQID_PLAYGROUND || { site : {}, page : '' };
|
|
7
|
+
const root = document.getElementById('sqid-panel');
|
|
8
|
+
if(!root){ return; }
|
|
9
|
+
const cap = (s) => String(s || '').replace(/\b[a-z]/g, c => c.toUpperCase());
|
|
10
|
+
const esc = (s) => String(s ?? '').replace(/[&<>"']/g, c => ({ '&' : '&', '<' : '<', '>' : '>', '"' : '"', "'" : ''' }[c]));
|
|
11
|
+
const t0 = performance.timeOrigin ? performance.now() : 0;
|
|
12
|
+
const since = () => ((performance.now() - t0) / 1000).toFixed(2) + 's';
|
|
13
|
+
const store = {
|
|
14
|
+
get(k, d){ try{ let v = JSON.parse(localStorage.getItem('sqid.playground.' + k)); return v == null ? d : v; }catch(error){ return d; } },
|
|
15
|
+
set(k, v){ localStorage.setItem('sqid.playground.' + k, JSON.stringify(v)); },
|
|
16
|
+
sget(k, d){ try{ let v = JSON.parse(sessionStorage.getItem('sqid.playground.' + k)); return v == null ? d : v; }catch(error){ return d; } },
|
|
17
|
+
sset(k, v){ sessionStorage.setItem('sqid.playground.' + k, JSON.stringify(v)); }
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// ---- state --------------------------------------------------------------------------------
|
|
21
|
+
const S = {
|
|
22
|
+
tab : store.get('tab', 'start'),
|
|
23
|
+
state : null, // /_sqid/state
|
|
24
|
+
connected : false,
|
|
25
|
+
visitor : null, // engine.visitor()
|
|
26
|
+
traits : null, // visitor.identified detail
|
|
27
|
+
identified: null,
|
|
28
|
+
timeToId : null,
|
|
29
|
+
log : store.sget('log', []),
|
|
30
|
+
done : store.get('done', {}), // scenario id -> true
|
|
31
|
+
record : null, // last visitor record from the API
|
|
32
|
+
recordErr : null,
|
|
33
|
+
webhooks : [],
|
|
34
|
+
goLive : store.get('golive', null),
|
|
35
|
+
hidden : store.get('hidden', false)
|
|
36
|
+
};
|
|
37
|
+
if(S.hidden){ document.body.classList.add('pg-panel-hidden'); }
|
|
38
|
+
|
|
39
|
+
// ---- log ----------------------------------------------------------------------------------
|
|
40
|
+
function log(kind, detail, cls){
|
|
41
|
+
S.log.unshift({ at : since(), page : cfg.path, kind, detail, cls : cls || 'pg-muted', t : Date.now() });
|
|
42
|
+
S.log = S.log.slice(0, 80);
|
|
43
|
+
store.sset('log', S.log);
|
|
44
|
+
if(S.tab === 'live' || S.tab === 'start' || S.tab === 'scenarios'){ render(); }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ---- scenarios ----------------------------------------------------------------------------
|
|
48
|
+
const SCENARIOS = [
|
|
49
|
+
{ id : 'arrive', t : 'Get identified on arrival', where : '/', label : 'home' },
|
|
50
|
+
{ id : 'variants', t : 'Switch sizes without buying', where : '/desk', label : 'a desk' },
|
|
51
|
+
{ id : 'identify', t : 'Sign in and call squid.identify()', where : '/signin', label : 'Sign in' },
|
|
52
|
+
{ id : 'form', t : 'Start the demo form, stop halfway', where : '/demo', label : 'Book a demo' },
|
|
53
|
+
{ id : 'cart', t : 'Add to cart, then go quiet', where : '/cart', label : 'Cart' },
|
|
54
|
+
{ id : 'pricing', t : 'Come back to Pricing three times', where : '/pricing', label : 'Pricing' },
|
|
55
|
+
{ id : 'label', t : 'Click a labelled button (key event)', where : null, label : 'any page' },
|
|
56
|
+
{ id : 'exit', t : 'Move the mouse to leave (exit intent)', where : null, label : 'any page' }
|
|
57
|
+
];
|
|
58
|
+
function done(id){ if(S.done[id]){ return; } S.done[id] = true; store.set('done', S.done); }
|
|
59
|
+
|
|
60
|
+
document.addEventListener('sqid:page', e => {
|
|
61
|
+
let d = e.detail;
|
|
62
|
+
if(d.what === 'variant_switch'){ log('variants', `${d.option}: ${d.value} (${d.switches} switches, ${d.hovers} hovers)`, 'pg-vio'); if(d.switches >= 3){ done('variants'); } }
|
|
63
|
+
if(d.what === 'variant_hover'){ log('variants', `hovering between options (${d.hovers} looks, ${d.switches} switches)`, 'pg-vio'); }
|
|
64
|
+
if(d.what === 'add_to_cart'){ log('page', `add to cart: ${d.size}, ${d.finish}, qty ${d.qty}`); }
|
|
65
|
+
if(d.what === 'cart_stall'){ log('behaviour', `cart untouched for ${d.after_s}s (cart stall shape)`, 'pg-yel'); done('cart'); }
|
|
66
|
+
if(d.what === 'discount_declined'){ log('behaviour', 'discount code declined (discount_codes shape)', 'pg-yel'); }
|
|
67
|
+
if(d.what === 'form_stall'){ log('behaviour', `form stalled after ${d.fields.join(', ')} (form_stall shape)`, 'pg-yel'); done('form'); }
|
|
68
|
+
if(d.what === 'form_submit'){ log('page', `demo form submitted (${d.fields.length} fields)`); }
|
|
69
|
+
if(d.what === 'identify'){ log('identify', `squid.identify({ email: "${d.email}" })`, 'pg-acc'); done('identify'); }
|
|
70
|
+
if(d.what === 'label_click'){ log('click', `${d.type} "${d.label}"`); done('label'); }
|
|
71
|
+
if(d.what === 'pricing_visit'){ log('page', `pricing visit ${d.visits} this session${d.visits >= 3 ? ' (deliberation shape)' : ''}`); if(d.visits >= 3){ done('pricing'); } }
|
|
72
|
+
if(d.what === 'exit_intent'){ log('behaviour', 'pointer left the page (exit intent)', 'pg-yel'); done('exit'); }
|
|
73
|
+
render();
|
|
74
|
+
});
|
|
75
|
+
document.addEventListener('sqid:recipe', e => log('recipe', `${e.detail.recipe}: ${e.detail.text}`, 'pg-acc'));
|
|
76
|
+
|
|
77
|
+
// ---- the SDK --------------------------------------------------------------------------------
|
|
78
|
+
function whenSquid(cb, tries = 200){
|
|
79
|
+
if(window.squid && window.squid.engine){ return cb(window.squid); }
|
|
80
|
+
if(tries <= 0){ log('sdk', 'the SDK did not load: is this origin allowed on the site?', 'pg-yel'); return render(); }
|
|
81
|
+
setTimeout(() => whenSquid(cb, tries - 1), 100);
|
|
82
|
+
}
|
|
83
|
+
whenSquid(squid => {
|
|
84
|
+
log('sdk', `loaded v${squid.VERSION || '?'}`, 'pg-ok');
|
|
85
|
+
squid.connection().then(c => { S.connected = !!c?.online; log('connected', `device ${String(c?.device || '').slice(0, 8)}… id ${String(c?.id || '').slice(0, 8)}…`, 'pg-ok'); render(); }).catch(() => {});
|
|
86
|
+
let engine = new squid.engine();
|
|
87
|
+
const snap = () => { try{ S.visitor = engine.visitor(); }catch(error){ S.visitor = null; } };
|
|
88
|
+
engine.on('visitor.synced', e => { snap(); log('visitor.synced', S.visitor?.identified ? 'identified' : 'unknown'); });
|
|
89
|
+
engine.on('visitor.identified', e => {
|
|
90
|
+
snap(); S.traits = e.detail; S.identified = true; S.timeToId = e.detail?.time_to_id ?? null;
|
|
91
|
+
log('visitor.identified', `${cap(e.detail?.name) || e.detail?.email || '?'} · ${cap(e.detail?.company)} · ${cap(e.detail?.company_role)}${S.timeToId != null ? ` (${S.timeToId} ms)` : ''}`, 'pg-acc');
|
|
92
|
+
done('arrive');
|
|
93
|
+
window.SqidRecipes && window.SqidRecipes.apply(e.detail);
|
|
94
|
+
loadRecord(); render();
|
|
95
|
+
});
|
|
96
|
+
engine.on('visitor.unknown', e => { snap(); S.traits = null; S.identified = false; S.timeToId = e.detail?.time_to_id ?? null; log('visitor.unknown', `anonymous (${S.timeToId ?? '?'} ms)`); window.SqidRecipes && window.SqidRecipes.apply(null); render(); });
|
|
97
|
+
engine.on('visitor.moment', e => log('visitor.moment', `${e.detail?.kind} → ${e.detail?.decision?.action}: ${e.detail?.decision?.instruction || ''}`, 'pg-yel'));
|
|
98
|
+
engine.on('error', e => log('error', e.detail?.message || String(e.detail), 'pg-yel'));
|
|
99
|
+
snap(); render();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// ---- local API ------------------------------------------------------------------------------
|
|
103
|
+
async function get(path){ let r = await fetch(path); let d = await r.json().catch(() => null); if(!r.ok){ throw Object.assign(new Error(d?.message || r.statusText), { data : d }); } return d; }
|
|
104
|
+
async function post(path, body){ let r = await fetch(path, { method : 'POST', headers : { 'content-type' : 'application/json' }, body : JSON.stringify(body || {}) }); let d = await r.json().catch(() => null); if(!r.ok){ throw Object.assign(new Error(d?.message || r.statusText), { data : d }); } return d; }
|
|
105
|
+
async function loadState(){ try{ S.state = await get('/_sqid/state'); S.webhooks = S.state.webhooks || []; }catch(error){ S.state = { error : error.message }; } render(); }
|
|
106
|
+
let recordFor = null;
|
|
107
|
+
async function loadRecord(){
|
|
108
|
+
let id = S.visitor?.meta?.user_id; if(!id || recordFor === id){ return; }
|
|
109
|
+
recordFor = id; S.record = null; S.recordErr = null;
|
|
110
|
+
try{ S.record = await get(`/_sqid/visitors/${encodeURIComponent(id)}`); }catch(error){ S.recordErr = error.message; }
|
|
111
|
+
render();
|
|
112
|
+
}
|
|
113
|
+
loadState();
|
|
114
|
+
|
|
115
|
+
// ---- actions ----------------------------------------------------------------------------------
|
|
116
|
+
const A = {
|
|
117
|
+
tab(name){ S.tab = name; store.set('tab', name); render(); },
|
|
118
|
+
hide(){ S.hidden = true; store.set('hidden', true); document.body.classList.add('pg-panel-hidden'); mountShow(); },
|
|
119
|
+
again(){
|
|
120
|
+
// Replay the reveal: the page loads as a stranger and Sqid resolves the person again. The
|
|
121
|
+
// Sandbox pins one person to this device (a new visitor id gets the same person back), so a
|
|
122
|
+
// different person needs a private window or another device until the SDK has a reset call.
|
|
123
|
+
S.log = []; store.sset('log', []); recordFor = null;
|
|
124
|
+
sessionStorage.removeItem('rc.exit');
|
|
125
|
+
location.reload();
|
|
126
|
+
},
|
|
127
|
+
toggleRecipe(key){ window.SqidRecipes.toggle(key); window.SqidRecipes.apply(S.traits); render(); },
|
|
128
|
+
showCode(key){ S.code = S.code === key ? null : key; render(); },
|
|
129
|
+
copy(text, btn){ navigator.clipboard?.writeText(text).then(() => { btn.textContent = 'Copied'; setTimeout(() => btn.textContent = 'Copy', 1200); }); },
|
|
130
|
+
async addWebhook(form){
|
|
131
|
+
let url = form.url.value.trim(); let btn = form.querySelector('button[type=submit]'); btn.disabled = true;
|
|
132
|
+
try{ let r = await post('/_sqid/webhooks', { url, event : 'identification' }); S.webhooks = r.webhooks || []; log('webhook', `added ${url}`, 'pg-ok'); form.url.value = ''; }
|
|
133
|
+
catch(error){ log('webhook', `could not add: ${error.message}`, 'pg-yel'); }
|
|
134
|
+
btn.disabled = false; render();
|
|
135
|
+
},
|
|
136
|
+
async testWebhook(id, btn){
|
|
137
|
+
btn.disabled = true; btn.textContent = 'Sending…';
|
|
138
|
+
try{ let r = await post(`/_sqid/webhooks/${id}/test`); log('webhook', `test delivery: ${r?.status || r?.response?.status || 'sent'}`, 'pg-ok'); S.lastTest = r; }
|
|
139
|
+
catch(error){ log('webhook', `test failed: ${error.message}`, 'pg-yel'); }
|
|
140
|
+
btn.disabled = false; btn.textContent = 'Send test'; render();
|
|
141
|
+
},
|
|
142
|
+
async sample(){ try{ S.sample = await get('/_sqid/sample'); }catch(error){ S.sample = { error : error.message }; } S.showSample = true; render(); },
|
|
143
|
+
async createSite(form){
|
|
144
|
+
let btn = form.querySelector('button[type=submit]'); btn.disabled = true; btn.textContent = 'Creating…';
|
|
145
|
+
try{ let r = await post('/_sqid/sites', { name : form.name.value.trim(), url : form.url.value.trim() }); S.goLive = { site : r.site, snippet : r.snippet, origins : r.origins, at : Date.now() }; store.set('golive', S.goLive); log('go live', `site "${r.site.name}" created`, 'pg-ok'); pollSite(); }
|
|
146
|
+
catch(error){ S.goLiveErr = error.message; }
|
|
147
|
+
btn.disabled = false; btn.textContent = 'Create site and get my snippet'; render();
|
|
148
|
+
},
|
|
149
|
+
forgetGoLive(){ S.goLive = null; store.set('golive', null); render(); }
|
|
150
|
+
};
|
|
151
|
+
let polling = null;
|
|
152
|
+
function pollSite(){
|
|
153
|
+
if(polling || !S.goLive?.site?.id){ return; }
|
|
154
|
+
polling = setInterval(async () => {
|
|
155
|
+
try{ let s = await get(`/_sqid/sites/${S.goLive.site.id}/status`); if(s){ S.goLive.status = s; store.set('golive', S.goLive); if(s.connected){ clearInterval(polling); polling = null; log('go live', `${s.name} is connected: the stream is live`, 'pg-ok'); } render(); } }catch(error){ /* keep trying */ }
|
|
156
|
+
}, 5000);
|
|
157
|
+
}
|
|
158
|
+
if(S.goLive && !S.goLive.status?.connected){ pollSite(); }
|
|
159
|
+
|
|
160
|
+
// ---- svg bits -----------------------------------------------------------------------------------
|
|
161
|
+
const ICON = {
|
|
162
|
+
done : '<svg width="18" height="18" viewBox="0 0 20 20" role="img" aria-label="done"><circle cx="10" cy="10" r="9" fill="#22d3ee"></circle><path d="M6 10.5l2.5 2.5L14 7.5" stroke="#0b0b0d" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"></path></svg>',
|
|
163
|
+
now : '<svg width="18" height="18" viewBox="0 0 20 20" role="img" aria-label="current"><circle cx="10" cy="10" r="8" stroke="#22d3ee" stroke-width="2" fill="none"></circle><circle cx="10" cy="10" r="3" fill="#22d3ee"></circle></svg>',
|
|
164
|
+
todo : '<svg width="18" height="18" viewBox="0 0 20 20" role="img" aria-label="pending"><circle cx="10" cy="10" r="8" stroke="#52525b" stroke-width="2" fill="none"></circle></svg>',
|
|
165
|
+
arrow: '<svg width="20" height="20" viewBox="0 0 22 22" role="img" aria-label="became"><path d="M3 11h14M12 6l5 5-5 5" stroke="#22d3ee" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"></path></svg>'
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// ---- render -------------------------------------------------------------------------------------
|
|
169
|
+
function render(){
|
|
170
|
+
if(S.hidden){ return; }
|
|
171
|
+
let st = S.state;
|
|
172
|
+
root.innerHTML = `
|
|
173
|
+
<div class="pg-top">
|
|
174
|
+
<span class="dot" aria-hidden="true"></span><span class="name">SQID ${cfg.site.sandbox ? 'SANDBOX' : 'SITE'}</span>
|
|
175
|
+
<span class="site" title="${esc(cfg.site.id)}">${esc(cfg.site.name || '')}</span>
|
|
176
|
+
<span class="conn ${S.connected ? 'on' : ''}"><i></i>${S.connected ? 'Connected' : 'Connecting'}</span>
|
|
177
|
+
<button class="pg-btn" data-act="hide" title="Hide the panel">Hide</button>
|
|
178
|
+
</div>
|
|
179
|
+
<div class="pg-tabs" role="tablist">${['start', 'live', 'scenarios', 'recipes', 'delivery', 'golive'].map(k => `<button role="tab" aria-selected="${S.tab === k}" data-tab="${k}">${{ start : 'Start', live : 'Live', scenarios : 'Scenarios', recipes : 'Recipes', delivery : 'Delivery', golive : 'Go live' }[k]}</button>`).join('')}</div>
|
|
180
|
+
<div class="pg-body">${({ start : tabStart, live : tabLive, scenarios : tabScenarios, recipes : tabRecipes, delivery : tabDelivery, golive : tabGoLive }[S.tab] || tabStart)(st)}</div>`;
|
|
181
|
+
wire();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function reveal(){
|
|
185
|
+
let v = S.visitor, tr = S.traits;
|
|
186
|
+
let anon = `<div class="who anon"><span class="k">Anonymous</span><span class="n">Visitor ${esc(String(v?.meta?.user_id || '').slice(0, 6) || '…')}…</span><span class="m">${esc(deviceLine())}</span></div>`;
|
|
187
|
+
let known = S.identified
|
|
188
|
+
? `<div class="who known"><span class="k">Identified${S.timeToId != null ? ` in ${(S.timeToId / 1000).toFixed(2)} s` : ''}</span><span class="n">${esc(cap(tr?.name) || tr?.email || '')}</span><span class="m">${esc([cap(tr?.company_role), cap(tr?.company)].filter(Boolean).join(' · '))}</span></div>`
|
|
189
|
+
: S.identified === false
|
|
190
|
+
? `<div class="who anon"><span class="k">Still anonymous</span><span class="n">Sqid could not identify this visitor</span><span class="m">that happens on real sites too</span></div>`
|
|
191
|
+
: `<div class="who anon"><span class="k">Resolving…</span><span class="n">Sqid is looking</span><span class="m">${S.connected ? 'connected, waiting for the answer' : 'connecting'}</span></div>`;
|
|
192
|
+
return `<div class="pg-reveal">${anon}${ICON.arrow}${known}</div>`;
|
|
193
|
+
}
|
|
194
|
+
function deviceLine(){ let ua = navigator.userAgent; let dev = /Mobi/.test(ua) ? 'mobile' : 'desktop'; let ref = document.referrer ? new URL(document.referrer).hostname : 'direct'; return `${dev} · ${ref} · ${cfg.path}`; }
|
|
195
|
+
|
|
196
|
+
function tabStart(st){
|
|
197
|
+
let hooks = S.webhooks || [];
|
|
198
|
+
let steps = [
|
|
199
|
+
{ t : 'Signed in to Sqid', s : st?.email ? `${st.email}${st.plan?.has ? ` · ${st.plan.name || 'Developer'} plan` : ''}` : (st?.error ? st.error : 'checking…'), ok : !!st?.email },
|
|
200
|
+
{ t : `${cfg.site.sandbox ? 'Sandbox' : 'Site'} provisioned`, s : st ? `${st.site.name} · ${location.origin} allowed` : '…', ok : !!st?.site },
|
|
201
|
+
{ t : 'Script added to layout', s : S.connected ? 'This page loads it. Connected.' : 'This page loads it; waiting for the connection.', ok : S.connected },
|
|
202
|
+
{ t : 'Webhook wired', s : hooks.length ? `${hooks.length} endpoint${hooks.length > 1 ? 's' : ''} on the site` : 'Where should identified visitors go? Add your endpoint in Delivery, or just watch the record there.', ok : hooks.length > 0, cta : hooks.length ? null : 'delivery' },
|
|
203
|
+
{ t : 'Stream is live', s : S.identified ? 'A visitor was identified on this page.' : 'Confirmed on the first identification.', ok : !!S.identified }
|
|
204
|
+
];
|
|
205
|
+
let firstTodo = steps.findIndex(x => !x.ok);
|
|
206
|
+
return `
|
|
207
|
+
<h2 class="pg-h">Set up Sqid</h2>
|
|
208
|
+
<p class="pg-p">Five steps. The site on the left is your test site. Nothing here costs credits.</p>
|
|
209
|
+
<ol class="pg-steps">${steps.map((x, i) => `<li class="pg-step ${x.ok ? '' : i === firstTodo ? 'now' : 'todo'}">${x.ok ? ICON.done : i === firstTodo ? ICON.now : ICON.todo}<div class="body"><span class="t">${esc(x.t)}</span><span class="s">${esc(x.s)}</span>${!x.ok && x.cta ? `<div class="pg-row"><button class="pg-btn primary" data-tab="${x.cta}">Open Delivery</button></div>` : ''}</div></li>`).join('')}</ol>
|
|
210
|
+
<div class="pg-card">
|
|
211
|
+
<div class="pg-row"><span class="pg-label">THIS VISITOR</span><button class="pg-btn grow-0" style="margin-left:auto" data-act="again">Watch it again</button></div>
|
|
212
|
+
${reveal()}
|
|
213
|
+
<span class="pg-p" style="font-size:12px">${S.identified ? 'The page loaded as a stranger. Sqid resolved the person and the headline changed. The full record is in Delivery.' : 'The page loaded as a stranger. When Sqid resolves the person, this flips and the headline on the left changes.'}</span>
|
|
214
|
+
</div>
|
|
215
|
+
<div class="pg-foot">
|
|
216
|
+
<span class="pg-label">SAME THING FROM A TERMINAL OR CLAUDE</span>
|
|
217
|
+
<pre class="pg-mono">npx -y @sqid-dev/playground
|
|
218
|
+
<span class="pg-muted">/sqid:setup in Claude Code</span></pre>
|
|
219
|
+
</div>`;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function tabLive(){
|
|
223
|
+
return `
|
|
224
|
+
<div class="pg-row"><h2 class="pg-h">Live</h2><button class="pg-btn" style="margin-left:auto" data-act="clearlog">Clear</button></div>
|
|
225
|
+
<p class="pg-p">Everything the SDK and the page did, newest first. Survives navigation within this tab session.</p>
|
|
226
|
+
<div class="pg-log">${S.log.length ? S.log.map(e => `<div class="ev"><span class="at">${esc(e.at)}</span><span><span class="k ${esc(e.cls)}">${esc(e.kind)}</span> <span class="d">${esc(e.detail)}</span>${e.page && e.page !== cfg.path ? ` <span class="pg-muted">${esc(e.page)}</span>` : ''}</span></div>`).join('') : '<span class="pg-muted">Nothing yet.</span>'}</div>`;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function tabScenarios(){
|
|
230
|
+
let tr = S.traits;
|
|
231
|
+
return `
|
|
232
|
+
<div>
|
|
233
|
+
<span class="pg-label">WHO YOU ARE</span>
|
|
234
|
+
<div class="pg-card hi" style="margin-top:8px">
|
|
235
|
+
<div class="pg-row"><div class="grow"><div><b>${esc(cap(tr?.name) || (S.identified === false ? 'Unknown visitor' : 'Resolving…'))}</b></div><div class="pg-muted" style="font-size:12px">${esc(tr ? [cap(tr.company_role), cap(tr.company), tr.email].filter(Boolean).join(' · ') : 'the Sandbox gives every new visitor one made-up person')}</div></div><button class="pg-btn" data-act="again">Watch it again</button></div>
|
|
236
|
+
</div>
|
|
237
|
+
<p class="pg-p" style="font-size:12px;margin-top:8px">Sandbox test people, like Stripe test cards. Real sites resolve real people; the Sandbox hands out one of fifty and never spends a credit. This device keeps its person; a private window or another device gets a different one.</p>
|
|
238
|
+
</div>
|
|
239
|
+
<div>
|
|
240
|
+
<span class="pg-label">THINGS TO TRY</span>
|
|
241
|
+
<ul class="pg-list" style="margin-top:8px">${SCENARIOS.map(s => { let on = s.where === cfg.path; return `<li class="pg-item ${on && !S.done[s.id] ? 'now' : ''}">${S.done[s.id] ? ICON.done : on ? ICON.now : ICON.todo}<span>${esc(s.t)}</span><span class="r">${S.done[s.id] ? 'done' : s.where ? (on ? '<span class="pg-acc">this page</span>' : `<a href="${s.where}">${esc(s.label)}</a>`) : esc(s.label)}</span></li>`; }).join('')}</ul>
|
|
242
|
+
</div>
|
|
243
|
+
<div class="pg-card">
|
|
244
|
+
<span class="pg-label">WHAT THE SDK SAW HERE</span>
|
|
245
|
+
<div class="pg-log">${S.log.filter(e => e.page === cfg.path).slice(0, 6).map(e => `<div class="ev"><span class="at">${esc(e.at)}</span><span><span class="k ${esc(e.cls)}">${esc(e.kind)}</span> <span class="d">${esc(e.detail)}</span></span></div>`).join('') || '<span class="pg-muted">Nothing on this page yet.</span>'}</div>
|
|
246
|
+
<span class="pg-p" style="font-size:12px">On a real site with Signals on, these shapes become moments (choosing_options, form_stall, cart_stall, deliberation). The Sandbox shows the raw behaviour only.</span>
|
|
247
|
+
</div>`;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function tabRecipes(){
|
|
251
|
+
let R = window.SqidRecipes, on = R.enabled();
|
|
252
|
+
let open = S.code && R.all[S.code] ? S.code : null;
|
|
253
|
+
return `
|
|
254
|
+
<p class="pg-p">Turn a recipe on and this site changes. Each one is the code from the docs, running against the live profile.</p>
|
|
255
|
+
<ul class="pg-list">${Object.entries(R.all).map(([k, r]) => `<li class="pg-item ${open === k ? 'now' : ''}" style="cursor:pointer" data-code="${k}"><button class="pg-toggle ${on.includes(k) && !r.locked ? 'on' : ''}" data-recipe="${k}" ${r.locked ? 'disabled' : ''} aria-label="toggle ${esc(r.title)}"><i></i></button><span>${esc(r.title)}</span><span class="r ${r.locked ? 'pg-yel' : ''}">${esc(r.where)}</span></li>`).join('')}</ul>
|
|
256
|
+
${open ? `<div>
|
|
257
|
+
<div class="pg-row"><span class="pg-label">${esc(R.all[open].title.toUpperCase())}</span><a href="${R.all[open].docs}" target="_blank" rel="noopener" style="margin-left:auto;font-size:12px">Docs</a><button class="pg-btn" data-copy="${open}">Copy</button></div>
|
|
258
|
+
<pre class="pg-mono" style="margin-top:8px">${esc(R.all[open].code)}</pre>
|
|
259
|
+
<span class="pg-p" style="font-size:12px;display:block;margin-top:6px">${R.all[open].locked ? 'Sandbox sites never receive moments. Add a card and put Sqid on a real site to see this one fire.' : S.traits ? `Running with ${esc(cap(S.traits.name) || S.traits.email)}'s profile. Click "Be someone else" in Scenarios to see it change.` : 'Waiting for an identified visitor.'}</span>
|
|
260
|
+
</div>` : '<span class="pg-muted">Click a recipe to see its code.</span>'}`;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function tabDelivery(st){
|
|
264
|
+
let rec = S.record;
|
|
265
|
+
let json = rec ? JSON.stringify(rec, null, 2) : null;
|
|
266
|
+
let hooks = S.webhooks || [];
|
|
267
|
+
return `
|
|
268
|
+
<div>
|
|
269
|
+
<span class="pg-label">WHERE IT GOES</span>
|
|
270
|
+
<ul class="pg-list" style="margin-top:8px">
|
|
271
|
+
${hooks.map(h => `<li class="pg-item"><i style="width:8px;height:8px;border-radius:4px;background:${h.enabled ? '#4ade80' : '#52525b'};flex-shrink:0"></i><span style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap" title="${esc(h.url)}">${esc(h.url)}</span><span class="r"><button class="pg-btn" data-test="${esc(h.id)}">Send test</button></span></li>`).join('')}
|
|
272
|
+
<li class="pg-item"><form class="pg-row grow" data-form="webhook" style="width:100%"><input class="pg-input" name="url" type="url" placeholder="https://your-app.com/api/sqid" required><button class="pg-btn primary" type="submit">Add</button></form></li>
|
|
273
|
+
</ul>
|
|
274
|
+
<span class="pg-p" style="font-size:12px;display:block;margin-top:6px">Any https endpoint works, a request catcher included. Identified visitors on this site are delivered there as the record below.</span>
|
|
275
|
+
</div>
|
|
276
|
+
<div>
|
|
277
|
+
<div class="pg-row"><span class="pg-label">THIS VISITOR'S RECORD</span><span class="pg-mono pg-acc" style="font-size:11px">${rec ? 'profile ' + esc(String(S.visitor?.meta?.user_id || '').slice(0, 8)) + '…' : ''}</span>${json ? `<button class="pg-btn" style="margin-left:auto" data-copytext="record">Copy JSON</button>` : ''}</div>
|
|
278
|
+
${json ? `<pre class="pg-mono" style="margin-top:8px;max-height:360px;overflow:auto" id="pg-record">${esc(json)}</pre>` : `<span class="pg-p" style="font-size:12px;display:block;margin-top:8px">${S.recordErr ? `Could not read the record: ${esc(S.recordErr)}` : S.identified ? 'Loading from the visitor API…' : 'Appears once this visitor is identified. It is the same record a webhook delivers.'}</span>`}
|
|
279
|
+
<div class="pg-row" style="margin-top:8px"><button class="pg-btn" data-act="sample">Show a webhook sample</button><a href="https://docs.sqid.dev/sdk/events" target="_blank" rel="noopener" style="margin-left:auto;font-size:12px">All the fields</a></div>
|
|
280
|
+
${S.showSample ? `<pre class="pg-mono" style="margin-top:8px;max-height:280px;overflow:auto">${esc(JSON.stringify(S.sample, null, 2))}</pre>` : ''}
|
|
281
|
+
</div>
|
|
282
|
+
<div class="pg-card warn">
|
|
283
|
+
<span class="pg-label">MOMENTS ARE OFF IN THE SANDBOX</span>
|
|
284
|
+
<span class="pg-p" style="font-size:12px;color:#d4d4d8">Add a card to start the free credit and Signals turns on for your real site. The form stall or cart stall you cause here would then arrive as a moment with an instruction for your agent.</span>
|
|
285
|
+
<div class="pg-row"><a class="pg-btn yellow" href="${esc(st?.console || 'https://app.sqid.dev')}/billing" target="_blank" rel="noopener" style="display:inline-flex;align-items:center;color:#0b0b0d">Start free credit</a><a href="https://docs.sqid.dev/guides/signals" target="_blank" rel="noopener" style="font-size:12px">About moments</a></div>
|
|
286
|
+
</div>`;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function tabGoLive(st){
|
|
290
|
+
let g = S.goLive;
|
|
291
|
+
return `
|
|
292
|
+
<h2 class="pg-h">Put Sqid on your own thing</h2>
|
|
293
|
+
<p class="pg-p">Same account, same snippet shape. Three ways in; each ends with the stream live and real identifications arriving.</p>
|
|
294
|
+
<div class="pg-card hi">
|
|
295
|
+
<div class="pg-row"><b>My website</b><span class="r pg-acc" style="margin-left:auto;font-size:11px">most people</span></div>
|
|
296
|
+
${g ? `
|
|
297
|
+
<div class="pg-p" style="font-size:12px">Site <b style="color:#fafafa">${esc(g.site.name)}</b> created for ${esc(g.origins.join(', '))}. Paste this before </head> on every page, deploy, open the site once.</div>
|
|
298
|
+
<pre class="pg-mono" id="pg-snippet">${esc(g.snippet)}</pre>
|
|
299
|
+
<div class="pg-row"><button class="pg-btn primary" data-copytext="snippet">Copy snippet</button><span class="pg-mono" style="font-size:11px;color:${g.status?.connected ? '#4ade80' : '#a1a1aa'}">${g.status?.connected ? 'Connected: the stream is live' : g.status?.deployed ? 'Page view seen, waiting for the connection…' : 'Waiting for the first page view…'}</span><button class="pg-btn" style="margin-left:auto" data-act="forget">Done</button></div>
|
|
300
|
+
<a href="${esc(st?.console || 'https://app.sqid.dev')}" target="_blank" rel="noopener" style="font-size:12px">Open the console</a>`
|
|
301
|
+
: `
|
|
302
|
+
<form data-form="site" style="display:flex;flex-direction:column;gap:8px">
|
|
303
|
+
<label class="pg-muted" style="font-size:12px">Public URL<input class="pg-input" name="url" type="url" placeholder="https://www.yourcompany.com" required style="margin-top:4px"></label>
|
|
304
|
+
<label class="pg-muted" style="font-size:12px">Name (optional)<input class="pg-input" name="name" type="text" placeholder="Marketing site" maxlength="50" style="margin-top:4px"></label>
|
|
305
|
+
<button class="pg-btn primary" type="submit">Create site and get my snippet</button>
|
|
306
|
+
${S.goLiveErr ? `<span class="pg-yel" style="font-size:12px">${esc(S.goLiveErr)}</span>` : ''}
|
|
307
|
+
</form>
|
|
308
|
+
<span class="pg-p" style="font-size:12px">Makes the site on your account, shows the one script tag, then waits here for the first real page view.</span>`}
|
|
309
|
+
</div>
|
|
310
|
+
<div class="pg-card">
|
|
311
|
+
<b>My app, from my editor</b>
|
|
312
|
+
<span class="pg-p" style="font-size:12px">Claude Code pastes the snippet into your layout and writes the webhook handler in your framework.</span>
|
|
313
|
+
<pre class="pg-mono">claude mcp add --transport http sqid https://mcp.sqid.dev/mcp
|
|
314
|
+
/sqid:setup</pre>
|
|
315
|
+
<pre class="pg-mono">npx -y @sqid-dev/sqid init</pre>
|
|
316
|
+
</div>
|
|
317
|
+
<div class="pg-card">
|
|
318
|
+
<b>Embedded in my product</b>
|
|
319
|
+
<span class="pg-p" style="font-size:12px">Identify visitors inside your own app or on your customers' sites. Server-side enrichment, the visitor API, and OEM terms for resale.</span>
|
|
320
|
+
<div class="pg-row"><a href="https://docs.sqid.dev/api-reference/overview" target="_blank" rel="noopener" style="font-size:12px">API reference</a><a href="https://sqid.dev/#oem" target="_blank" rel="noopener" style="font-size:12px">OEM program</a></div>
|
|
321
|
+
</div>
|
|
322
|
+
<div class="pg-card" style="background:#0e2a30;border-color:#155e75">
|
|
323
|
+
<div class="pg-row"><b>${esc(st?.plan?.name || 'Developer')} plan${st?.plan?.has ? '' : ' (starts with your first site)'}</b><span class="r" style="margin-left:auto;color:#a5f3fc">${st?.plan?.has ? 'you are on it' : 'free'}</span></div>
|
|
324
|
+
<span class="pg-p" style="font-size:12px;color:#d4d4d8">Real identifications start as soon as your site connects. Add a card to unlock the free credit, moments, and higher caps. No charge until you use it.</span>
|
|
325
|
+
<div class="pg-row"><a class="pg-btn accent" href="${esc(st?.console || 'https://app.sqid.dev')}/billing" target="_blank" rel="noopener" style="display:inline-flex;align-items:center;color:#0b0b0d">Add a card</a><a href="https://sqid.dev/pricing" target="_blank" rel="noopener" style="font-size:12px">Compare plans</a></div>
|
|
326
|
+
</div>`;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// ---- wiring ---------------------------------------------------------------------------------------
|
|
330
|
+
function wire(){
|
|
331
|
+
root.querySelectorAll('[data-tab]').forEach(b => b.addEventListener('click', () => A.tab(b.dataset.tab)));
|
|
332
|
+
root.querySelectorAll('[data-act]').forEach(b => b.addEventListener('click', () => {
|
|
333
|
+
let a = b.dataset.act;
|
|
334
|
+
if(a === 'hide'){ A.hide(); } if(a === 'again'){ A.again(); } if(a === 'sample'){ A.sample(); } if(a === 'forget'){ A.forgetGoLive(); }
|
|
335
|
+
if(a === 'clearlog'){ S.log = []; store.sset('log', []); render(); }
|
|
336
|
+
}));
|
|
337
|
+
root.querySelectorAll('[data-recipe]').forEach(b => b.addEventListener('click', e => { e.stopPropagation(); A.toggleRecipe(b.dataset.recipe); }));
|
|
338
|
+
root.querySelectorAll('[data-code]').forEach(li => li.addEventListener('click', () => A.showCode(li.dataset.code)));
|
|
339
|
+
root.querySelectorAll('[data-copy]').forEach(b => b.addEventListener('click', e => { e.stopPropagation(); A.copy(window.SqidRecipes.all[b.dataset.copy].code, b); }));
|
|
340
|
+
root.querySelectorAll('[data-copytext]').forEach(b => b.addEventListener('click', () => { let el = document.getElementById(b.dataset.copytext === 'record' ? 'pg-record' : 'pg-snippet'); if(el){ A.copy(el.textContent, b); } }));
|
|
341
|
+
root.querySelectorAll('[data-test]').forEach(b => b.addEventListener('click', () => A.testWebhook(b.dataset.test, b)));
|
|
342
|
+
let wf = root.querySelector('form[data-form="webhook"]'); wf && wf.addEventListener('submit', e => { e.preventDefault(); A.addWebhook(wf); });
|
|
343
|
+
let sf = root.querySelector('form[data-form="site"]'); sf && sf.addEventListener('submit', e => { e.preventDefault(); A.createSite(sf); });
|
|
344
|
+
}
|
|
345
|
+
function mountShow(){
|
|
346
|
+
if(document.getElementById('pg-show')){ return; }
|
|
347
|
+
let b = document.createElement('button'); b.id = 'pg-show'; b.className = 'pg-btn primary'; b.textContent = 'Sqid panel';
|
|
348
|
+
b.style.cssText = 'position:fixed;right:16px;bottom:16px;z-index:60;height:36px;box-shadow:0 8px 24px rgba(0,0,0,.25)';
|
|
349
|
+
b.addEventListener('click', () => { S.hidden = false; store.set('hidden', false); document.body.classList.remove('pg-panel-hidden'); b.remove(); render(); });
|
|
350
|
+
document.body.appendChild(b);
|
|
351
|
+
}
|
|
352
|
+
if(S.hidden){ mountShow(); } else { render(); }
|
|
353
|
+
window.SqidRecipes && window.SqidRecipes.apply(null);
|
|
354
|
+
})();
|