site-vigil-visitors 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 +12 -11
- package/bin/cli.mjs +28 -18
- package/dist/react.d.ts +2 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +1 -1
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ After installing, run:
|
|
|
31
31
|
npx site-vigil-visitors init
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
This prompts for your site ID, then adds the import and the `<
|
|
34
|
+
This prompts for your site ID, then adds the import and the `<SiteVigil />`
|
|
35
35
|
component to your app entry file (`src/App.tsx`, `src/App.jsx`, `src/main.tsx`,
|
|
36
36
|
or `src/main.jsx`). To skip the prompt:
|
|
37
37
|
|
|
@@ -55,8 +55,9 @@ npm uninstall site-vigil-visitors
|
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
`remove` scans every file under `src/` and strips all tracking code: import
|
|
58
|
-
statements referencing this package and any `<
|
|
59
|
-
multi-line, either quote style)
|
|
58
|
+
statements referencing this package and any `<SiteVigil />` elements (single- or
|
|
59
|
+
multi-line, either quote style), including the legacy `<Tracking />` name used
|
|
60
|
+
before v0.3.0. If a file still references the package in a
|
|
60
61
|
way it cannot safely remove (for example custom `createTracker` usage), it
|
|
61
62
|
lists that file for manual review.
|
|
62
63
|
|
|
@@ -69,11 +70,11 @@ lists that file for manual review.
|
|
|
69
70
|
### React
|
|
70
71
|
|
|
71
72
|
```tsx
|
|
72
|
-
import {
|
|
73
|
+
import { SiteVigil } from 'site-vigil-visitors/react'
|
|
73
74
|
|
|
74
75
|
export function App() {
|
|
75
76
|
return (
|
|
76
|
-
<
|
|
77
|
+
<SiteVigil
|
|
77
78
|
siteId="my-site"
|
|
78
79
|
endpoint="https://t.site-vigil.com"
|
|
79
80
|
/>
|
|
@@ -111,12 +112,12 @@ tracker.trackEvent('cta_click', { label: 'Register' })
|
|
|
111
112
|
## React usage
|
|
112
113
|
|
|
113
114
|
```tsx
|
|
114
|
-
import {
|
|
115
|
+
import { SiteVigil } from 'site-vigil-visitors/react'
|
|
115
116
|
|
|
116
117
|
export function App() {
|
|
117
118
|
return (
|
|
118
119
|
<>
|
|
119
|
-
<
|
|
120
|
+
<SiteVigil
|
|
120
121
|
siteId="my-site"
|
|
121
122
|
endpoint="https://t.site-vigil.com"
|
|
122
123
|
/>
|
|
@@ -131,12 +132,12 @@ export function App() {
|
|
|
131
132
|
Here is a minimal Vite + React example using the package:
|
|
132
133
|
|
|
133
134
|
```tsx
|
|
134
|
-
import {
|
|
135
|
+
import { SiteVigil } from 'site-vigil-visitors/react'
|
|
135
136
|
|
|
136
137
|
export default function App() {
|
|
137
138
|
return (
|
|
138
139
|
<div>
|
|
139
|
-
<
|
|
140
|
+
<SiteVigil
|
|
140
141
|
siteId="demo-site"
|
|
141
142
|
endpoint="https://t.site-vigil.com"
|
|
142
143
|
/>
|
|
@@ -174,11 +175,11 @@ Use the React wrapper inside a client component:
|
|
|
174
175
|
```tsx
|
|
175
176
|
'use client'
|
|
176
177
|
|
|
177
|
-
import {
|
|
178
|
+
import { SiteVigil } from 'site-vigil-visitors/react'
|
|
178
179
|
|
|
179
180
|
export default function TrackingClient() {
|
|
180
181
|
return (
|
|
181
|
-
<
|
|
182
|
+
<SiteVigil
|
|
182
183
|
siteId="next-app"
|
|
183
184
|
endpoint="https://t.site-vigil.com"
|
|
184
185
|
/>
|
package/bin/cli.mjs
CHANGED
|
@@ -80,13 +80,18 @@ function patchImports(content) {
|
|
|
80
80
|
const pos = last.index + last[0].length
|
|
81
81
|
return (
|
|
82
82
|
content.slice(0, pos) +
|
|
83
|
-
`\nimport {
|
|
83
|
+
`\nimport { SiteVigil } from ${q}${PACKAGE}/react${q}` +
|
|
84
84
|
content.slice(pos)
|
|
85
85
|
)
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
function hasComponent(content) {
|
|
89
|
+
// <Tracking> is the pre-0.3.0 component name
|
|
90
|
+
return /<(?:SiteVigil|Tracking)[\s/>]/.test(content)
|
|
91
|
+
}
|
|
92
|
+
|
|
88
93
|
function patchJsx(content, siteId) {
|
|
89
|
-
if (content
|
|
94
|
+
if (hasComponent(content)) return content
|
|
90
95
|
|
|
91
96
|
// Insert <Tracking /> as the last child of the file's final JSX closing tag —
|
|
92
97
|
// in a typical app entry file that is the root element of the main return.
|
|
@@ -102,18 +107,18 @@ function patchJsx(content, siteId) {
|
|
|
102
107
|
const prevIndent = prevLine.match(/^[ \t]*/)[0]
|
|
103
108
|
const indent = prevIndent.length > closeIndent.length ? prevIndent : closeIndent + ' '
|
|
104
109
|
|
|
105
|
-
const trackingLine = `${indent}<
|
|
110
|
+
const trackingLine = `${indent}<SiteVigil siteId="${siteId}" endpoint="${ENDPOINT}" />\n`
|
|
106
111
|
return content.slice(0, last.index) + trackingLine + content.slice(last.index)
|
|
107
112
|
}
|
|
108
113
|
|
|
109
114
|
function printManual(siteId) {
|
|
110
115
|
console.log(`Add this import to your app entry file:
|
|
111
116
|
|
|
112
|
-
import {
|
|
117
|
+
import { SiteVigil } from '${PACKAGE}/react'
|
|
113
118
|
|
|
114
119
|
Then add the component inside your JSX tree:
|
|
115
120
|
|
|
116
|
-
<
|
|
121
|
+
<SiteVigil
|
|
117
122
|
siteId="${siteId}"
|
|
118
123
|
endpoint="${ENDPOINT}"
|
|
119
124
|
/>
|
|
@@ -140,8 +145,8 @@ async function init() {
|
|
|
140
145
|
|
|
141
146
|
let content = await readFile(found.path, 'utf-8')
|
|
142
147
|
|
|
143
|
-
if (content
|
|
144
|
-
console.log(`\n<
|
|
148
|
+
if (hasComponent(content)) {
|
|
149
|
+
console.log(`\n<SiteVigil /> is already present in ${found.rel}. Nothing to do.`)
|
|
145
150
|
return
|
|
146
151
|
}
|
|
147
152
|
|
|
@@ -157,14 +162,13 @@ async function init() {
|
|
|
157
162
|
await writeFile(found.path, patched, 'utf-8')
|
|
158
163
|
|
|
159
164
|
console.log(`
|
|
160
|
-
Done! Added <
|
|
165
|
+
Done! Added <SiteVigil /> to ${found.rel}.
|
|
161
166
|
|
|
162
167
|
To verify:
|
|
163
168
|
1. Start your dev server
|
|
164
169
|
2. Open DevTools -> Network, filter for "t.site-vigil.com"
|
|
165
170
|
3. Reload - you should see a POST with status 200
|
|
166
|
-
|
|
167
|
-
Note: make sure "${siteId}" is registered in your Supabase websites table (tracking_id column).
|
|
171
|
+
4. Check your dashboard at https://app.site-vigil.com - a visit for "${siteId}" should be recorded
|
|
168
172
|
`)
|
|
169
173
|
}
|
|
170
174
|
|
|
@@ -181,15 +185,21 @@ function stripTracking(content) {
|
|
|
181
185
|
''
|
|
182
186
|
)
|
|
183
187
|
|
|
184
|
-
// <Tracking
|
|
185
|
-
|
|
188
|
+
// <Tracking> is the pre-0.3.0 component name; keep stripping it so remove
|
|
189
|
+
// also cleans up sites integrated with older versions.
|
|
190
|
+
const NAMES = /SiteVigil|Tracking/
|
|
186
191
|
|
|
187
|
-
// <
|
|
188
|
-
result = result.replace(
|
|
192
|
+
// <SiteVigil ... /> on its own line(s), self-closing (possibly multi-line)
|
|
193
|
+
result = result.replace(
|
|
194
|
+
new RegExp(`^[ \\t]*<(?:${NAMES.source})\\b[\\s\\S]*?/>[ \\t]*\\r?\\n?`, 'gm'), '')
|
|
195
|
+
|
|
196
|
+
// <SiteVigil>...</SiteVigil> with children, on its own line(s)
|
|
197
|
+
result = result.replace(
|
|
198
|
+
new RegExp(`^[ \\t]*<(${NAMES.source})\\b[\\s\\S]*?</\\1>[ \\t]*\\r?\\n?`, 'gm'), '')
|
|
189
199
|
|
|
190
200
|
// any inline occurrences that were not at the start of a line
|
|
191
|
-
result = result.replace(
|
|
192
|
-
result = result.replace(
|
|
201
|
+
result = result.replace(new RegExp(`<(?:${NAMES.source})\\b[\\s\\S]*?/>`, 'g'), '')
|
|
202
|
+
result = result.replace(new RegExp(`<(${NAMES.source})\\b[\\s\\S]*?</\\1>`, 'g'), '')
|
|
193
203
|
|
|
194
204
|
return result
|
|
195
205
|
}
|
|
@@ -210,7 +220,7 @@ async function remove() {
|
|
|
210
220
|
|
|
211
221
|
for (const file of files) {
|
|
212
222
|
const content = await readFile(file, 'utf-8')
|
|
213
|
-
if (!content.includes(PACKAGE) && !content
|
|
223
|
+
if (!content.includes(PACKAGE) && !hasComponent(content)) continue
|
|
214
224
|
|
|
215
225
|
const stripped = stripTracking(content)
|
|
216
226
|
if (stripped !== content) {
|
|
@@ -218,7 +228,7 @@ async function remove() {
|
|
|
218
228
|
changed.push(relative(cwd, file))
|
|
219
229
|
}
|
|
220
230
|
|
|
221
|
-
if (/site-vigil|createTracker|<Tracking\b/.test(stripped)) {
|
|
231
|
+
if (/site-vigil|createTracker|<(?:SiteVigil|Tracking)\b/.test(stripped)) {
|
|
222
232
|
needsReview.push(relative(cwd, file))
|
|
223
233
|
}
|
|
224
234
|
}
|
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TrackerConfig } from './core.js';
|
|
2
|
-
export interface
|
|
2
|
+
export interface SiteVigilProps extends TrackerConfig {
|
|
3
3
|
}
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function SiteVigil({ siteId, endpoint, sessionKey, includeLeaveEvent, }: SiteVigilProps): null;
|
|
5
5
|
//# sourceMappingURL=react.d.ts.map
|
package/dist/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,WAAW,CAAA;AAE7D,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,WAAW,CAAA;AAE7D,MAAM,WAAW,cAAe,SAAQ,aAAa;CAAG;AAExD,wBAAgB,SAAS,CAAC,EACxB,MAAM,EACN,QAAQ,EACR,UAAU,EACV,iBAAiB,GAClB,EAAE,cAAc,QAiBhB"}
|
package/dist/react.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import { createTracker } from './core.js';
|
|
3
|
-
export function
|
|
3
|
+
export function SiteVigil({ siteId, endpoint, sessionKey, includeLeaveEvent, }) {
|
|
4
4
|
useEffect(() => {
|
|
5
5
|
const tracker = createTracker({
|
|
6
6
|
siteId,
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,aAAa,EAAsB,MAAM,WAAW,CAAA;AAI7D,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,aAAa,EAAsB,MAAM,WAAW,CAAA;AAI7D,MAAM,UAAU,SAAS,CAAC,EACxB,MAAM,EACN,QAAQ,EACR,UAAU,EACV,iBAAiB,GACF;IACf,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,aAAa,CAAC;YAC5B,MAAM;YACN,QAAQ;YACR,UAAU;YACV,iBAAiB;SAClB,CAAC,CAAA;QAEF,OAAO,CAAC,KAAK,EAAE,CAAA;QAEf,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,OAAO,EAAE,CAAA;QACnB,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAA;IAErD,OAAO,IAAI,CAAA;AACb,CAAC"}
|