diff --git a/package.json b/package.json index cef558c..b53e56b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@isimplifyme/ui", - "version": "1.6.0", + "version": "1.7.0", "description": "React/Next.js UI library for iSimplifyMe properties \u2014 design system, article layouts, SEO helpers, bot middleware, and the iSM Concierge widget.", "homepage": "https://isimplifyme.com", "type": "module", diff --git a/src/concierge.test.tsx b/src/concierge.test.tsx index bb7e051..0632527 100644 --- a/src/concierge.test.tsx +++ b/src/concierge.test.tsx @@ -331,3 +331,33 @@ describe('the disclaimer band exists before it has anything to say', () => { expect(after?.textContent).toContain('Not a person.'); }); }); + +// ── Open beacon (apex `{"event":"open"}`, fleet audit 2026-11-05) ────────── +// Ships to every site on a `^` range, so the default path is pinned too: no +// focus, no beacon. +describe('open beacon', () => { + function beacons() { + const calls = (globalThis.fetch as unknown as { mock: { calls: [string, RequestInit?][] } }).mock.calls; + return calls.filter(([, init]) => typeof init?.body === 'string' && init.body.includes('"event":"open"')); + } + + it('sends nothing before the input is focused', () => { + render(); + expect(beacons()).toHaveLength(0); + }); + + it('sends exactly one beacon, to the configured endpoint, on first focus', () => { + const { input } = render({ endpoint: '/api/x' }); + act(() => { + input.focus(); + }); + act(() => { + input.blur(); + input.focus(); + }); + const sent = beacons(); + expect(sent).toHaveLength(1); + expect(sent[0][0]).toBe('/api/x'); + expect(JSON.parse(String(sent[0][1]?.body))).toEqual({ event: 'open', pathname: window.location.pathname }); + }); +}); diff --git a/src/concierge.tsx b/src/concierge.tsx index 7e6c882..2f550f1 100644 --- a/src/concierge.tsx +++ b/src/concierge.tsx @@ -262,6 +262,23 @@ export default function ConciergeWidget({ const [isLoading, setIsLoading] = useState(false); const [sessionId, setSessionId] = useState(null); const [isFocused, setIsFocused] = useState(false); + + // Count the visitor's first engagement per page load: apex `{"event":"open"}` + // through the same proxy (apex lib/concierge/opens, #578). This bar is always + // visible and `isOpen` only flips on the first send, so the step before a + // conversation is the first focus of the input. Until 2026-11 nothing + // recorded it. Best effort; never blocks the bar. + const openCounted = useRef(false); + useEffect(() => { + if (!isFocused || openCounted.current) return; + openCounted.current = true; + fetch(endpoint, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ event: 'open', pathname: window.location.pathname }), + keepalive: true, + }).catch(() => {}); + }, [isFocused, endpoint]); const [error, setError] = useState(null); const [isMac, setIsMac] = useState(true); // Narrow viewports get no keyboard shortcut chip. Starts false so the