@vibiz/cli 0.2.3 → 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/dist/{chunk-RXH3L5IW.js → chunk-ICBMMOJM.js} +190 -6
- package/dist/src-MRGQURG7.js +4344 -0
- package/dist/vibiz.js +1067 -99
- package/package.json +1 -1
- package/templates/nextjs-saas/.env.example +0 -2
- package/templates/nextjs-saas/README.md +10 -11
- package/templates/nextjs-saas/app/dashboard/page.tsx +0 -2
- package/templates/nextjs-saas/app/layout.tsx +0 -2
- package/templates/nextjs-saas/app/page.tsx +2 -6
- package/dist/src-QNWJABRQ.js +0 -3713
- package/templates/nextjs-saas/components/replay-consent.tsx +0 -75
- package/templates/nextjs-saas/components/replay-identify.tsx +0 -21
- package/templates/nextjs-saas/lib/replay.ts +0 -55
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useEffect, useState } from 'react';
|
|
4
|
-
import { Button } from '@/components/ui';
|
|
5
|
-
import { type Consent, readConsent, replay, replayEnabled, writeConsent } from '@/lib/replay';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Asks once whether this visit may be recorded to find and fix problems.
|
|
9
|
-
* Typed text is hidden in the recording either way. Until the visitor says
|
|
10
|
-
* yes, nothing is recorded and nothing is stored for replay.
|
|
11
|
-
*/
|
|
12
|
-
export function ReplayConsent() {
|
|
13
|
-
const [consent, setConsent] = useState<Consent | 'unknown'>('unknown');
|
|
14
|
-
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
if (!replayEnabled()) return;
|
|
17
|
-
const current = readConsent();
|
|
18
|
-
setConsent(current);
|
|
19
|
-
if (current === 'granted') replay('start');
|
|
20
|
-
const reopen = () => setConsent(readConsent());
|
|
21
|
-
window.addEventListener('vibiz-replay-consent', reopen);
|
|
22
|
-
return () => window.removeEventListener('vibiz-replay-consent', reopen);
|
|
23
|
-
}, []);
|
|
24
|
-
|
|
25
|
-
if (consent !== null) return null;
|
|
26
|
-
|
|
27
|
-
const choose = (value: 'granted' | 'denied') => {
|
|
28
|
-
writeConsent(value);
|
|
29
|
-
setConsent(value);
|
|
30
|
-
replay(value === 'granted' ? 'start' : 'stop');
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<div
|
|
35
|
-
role="dialog"
|
|
36
|
-
aria-live="polite"
|
|
37
|
-
aria-label="Recording preferences"
|
|
38
|
-
className="fixed inset-x-4 bottom-4 z-50 mx-auto max-w-md rounded-xl border border-zinc-200 bg-white p-4 shadow-lg sm:right-4 sm:left-auto sm:mx-0"
|
|
39
|
-
>
|
|
40
|
-
<p className="text-sm text-zinc-700">
|
|
41
|
-
May we record how you use this site to find and fix problems? What you type stays hidden.
|
|
42
|
-
</p>
|
|
43
|
-
<div className="mt-3 flex justify-end gap-2">
|
|
44
|
-
<Button variant="ghost" className="h-9" onClick={() => choose('denied')}>
|
|
45
|
-
No thanks
|
|
46
|
-
</Button>
|
|
47
|
-
<Button className="h-9" data-vibiz-name="replay-consent-allow" onClick={() => choose('granted')}>
|
|
48
|
-
Allow
|
|
49
|
-
</Button>
|
|
50
|
-
</div>
|
|
51
|
-
</div>
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** Lets a visitor change their mind: shows the question again. */
|
|
56
|
-
export function ReplayChoicesLink() {
|
|
57
|
-
const [shown, setShown] = useState(false);
|
|
58
|
-
useEffect(() => setShown(replayEnabled()), []);
|
|
59
|
-
if (!shown) return null;
|
|
60
|
-
return (
|
|
61
|
-
<button
|
|
62
|
-
type="button"
|
|
63
|
-
className="underline-offset-4 hover:underline"
|
|
64
|
-
onClick={() => {
|
|
65
|
-
replay('stop');
|
|
66
|
-
try {
|
|
67
|
-
window.localStorage.removeItem('vibiz-replay-consent');
|
|
68
|
-
} catch {}
|
|
69
|
-
window.dispatchEvent(new Event('vibiz-replay-consent'));
|
|
70
|
-
}}
|
|
71
|
-
>
|
|
72
|
-
Recording choices
|
|
73
|
-
</button>
|
|
74
|
-
);
|
|
75
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useEffect } from 'react';
|
|
4
|
-
import { readConsent, replay, replayEnabled } from '@/lib/replay';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Signed-in customers' sessions are always worth keeping: record the whole
|
|
8
|
-
* tab, not just the minutes before an error. Still only with consent.
|
|
9
|
-
*/
|
|
10
|
-
export function ReplaySignedIn() {
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
if (!replayEnabled()) return;
|
|
13
|
-
const apply = () => {
|
|
14
|
-
if (readConsent() === 'granted') replay('always');
|
|
15
|
-
};
|
|
16
|
-
apply();
|
|
17
|
-
window.addEventListener('vibiz-replay-consent', apply);
|
|
18
|
-
return () => window.removeEventListener('vibiz-replay-consent', apply);
|
|
19
|
-
}, []);
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session replay, only with the visitor's consent. The choice is kept in
|
|
3
|
-
* localStorage (after they make it), and nothing is recorded before it.
|
|
4
|
-
* Replay itself is the `replay` resource: without NEXT_PUBLIC_VIBIZ_REPLAY
|
|
5
|
-
* none of this renders.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
type Vibiz = ((...args: unknown[]) => void) & { q?: unknown[][] };
|
|
9
|
-
declare global {
|
|
10
|
-
interface Window {
|
|
11
|
-
vibiz?: Vibiz;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const CONSENT_KEY = 'vibiz-replay-consent';
|
|
16
|
-
/** Fired when the choice changes, so parts of the page can react. */
|
|
17
|
-
export const CONSENT_EVENT = 'vibiz-replay-consent';
|
|
18
|
-
export type Consent = 'granted' | 'denied' | null;
|
|
19
|
-
|
|
20
|
-
export const replayEnabled = () =>
|
|
21
|
-
Boolean(
|
|
22
|
-
process.env.NEXT_PUBLIC_VIBIZ_REPLAY &&
|
|
23
|
-
process.env.NEXT_PUBLIC_VIBIZ_ANALYTICS_KEY &&
|
|
24
|
-
process.env.NEXT_PUBLIC_VIBIZ_ANALYTICS_URL,
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
export function readConsent(): Consent {
|
|
28
|
-
try {
|
|
29
|
-
const v = window.localStorage.getItem(CONSENT_KEY);
|
|
30
|
-
return v === 'granted' || v === 'denied' ? v : null;
|
|
31
|
-
} catch {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function writeConsent(value: Exclude<Consent, null>) {
|
|
37
|
-
try {
|
|
38
|
-
window.localStorage.setItem(CONSENT_KEY, value);
|
|
39
|
-
} catch {
|
|
40
|
-
// storage blocked: the choice holds for this page only
|
|
41
|
-
}
|
|
42
|
-
window.dispatchEvent(new Event(CONSENT_EVENT));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** `vibiz('replay', …)`, queued until the analytics script has loaded. */
|
|
46
|
-
export function replay(command: 'start' | 'always' | 'stop') {
|
|
47
|
-
if (!window.vibiz) {
|
|
48
|
-
const stub: Vibiz = (...args: unknown[]) => {
|
|
49
|
-
stub.q = stub.q ?? [];
|
|
50
|
-
stub.q.push(args);
|
|
51
|
-
};
|
|
52
|
-
window.vibiz = stub;
|
|
53
|
-
}
|
|
54
|
-
window.vibiz('replay', command);
|
|
55
|
-
}
|