@pageflock/analytics 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 +163 -2
- package/dist/chunks/chunk-4ZAVKYVM.js +16 -0
- package/dist/chunks/chunk-7JF7P3VW.js +203 -0
- package/dist/index.js +8 -0
- package/dist/next.js +11 -0
- package/dist/react.js +11 -0
- package/dist/types/index.d.ts +36 -0
- package/dist/types/next.d.ts +12 -0
- package/dist/types/react.d.ts +6 -0
- package/dist/types/vue.d.ts +36 -0
- package/dist/vue.js +28 -0
- package/package.json +78 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Daniel Schmidt and Pageflock contributors
|
|
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,164 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @pageflock/analytics
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Add [Pageflock](https://github.com/thebuilder/pageflock) to a React, Next.js, Vue, SvelteKit, Astro or any bundled site with one component. Cookieless, no device storage, about 1.5 KB gzipped.
|
|
4
|
+
|
|
5
|
+
The script tag still works on its own (see [`@pageflock/tracker`](https://www.npmjs.com/package/@pageflock/tracker)). Use this package when you would rather configure Pageflock in code, hook into events with `beforeSend`, or call `track()` with types.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @pageflock/analytics
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
You need a site ID from the Pageflock dashboard and the URL of your ingest Worker's collect endpoint, `https://YOUR-PAGEFLOCK-INGEST/api/e`.
|
|
14
|
+
|
|
15
|
+
## Next.js
|
|
16
|
+
|
|
17
|
+
Add `<Analytics />` to the root layout, `app/layout.tsx`:
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { Analytics } from "@pageflock/analytics/next";
|
|
21
|
+
|
|
22
|
+
export default function RootLayout({
|
|
23
|
+
children,
|
|
24
|
+
}: {
|
|
25
|
+
children: React.ReactNode;
|
|
26
|
+
}) {
|
|
27
|
+
return (
|
|
28
|
+
<html lang="en">
|
|
29
|
+
<body>
|
|
30
|
+
{children}
|
|
31
|
+
<Analytics
|
|
32
|
+
site="SITE_ID"
|
|
33
|
+
endpoint="https://YOUR-PAGEFLOCK-INGEST/api/e"
|
|
34
|
+
/>
|
|
35
|
+
</body>
|
|
36
|
+
</html>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
With the Pages Router, put it in `pages/_app.tsx` instead. Client navigations are counted automatically.
|
|
42
|
+
|
|
43
|
+
## React
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import { Analytics } from "@pageflock/analytics/react";
|
|
47
|
+
|
|
48
|
+
export const App = () => (
|
|
49
|
+
<>
|
|
50
|
+
<Routes />
|
|
51
|
+
<Analytics site="SITE_ID" endpoint="https://YOUR-PAGEFLOCK-INGEST/api/e" />
|
|
52
|
+
</>
|
|
53
|
+
);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
This works with React Router, TanStack Router and any other router that uses the History API.
|
|
57
|
+
|
|
58
|
+
## Vue and Nuxt
|
|
59
|
+
|
|
60
|
+
In `App.vue`, or `app.vue` in Nuxt:
|
|
61
|
+
|
|
62
|
+
```vue
|
|
63
|
+
<script setup lang="ts">
|
|
64
|
+
import { Analytics } from "@pageflock/analytics/vue";
|
|
65
|
+
</script>
|
|
66
|
+
|
|
67
|
+
<template>
|
|
68
|
+
<Analytics site="SITE_ID" endpoint="https://YOUR-PAGEFLOCK-INGEST/api/e" />
|
|
69
|
+
<RouterView />
|
|
70
|
+
</template>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## SvelteKit
|
|
74
|
+
|
|
75
|
+
`inject()` does nothing on the server, so it can run straight from the root layout, `src/routes/+layout.svelte`:
|
|
76
|
+
|
|
77
|
+
```svelte
|
|
78
|
+
<script lang="ts">
|
|
79
|
+
import { inject } from "@pageflock/analytics";
|
|
80
|
+
import { dev } from "$app/environment";
|
|
81
|
+
|
|
82
|
+
inject({ site: "SITE_ID", endpoint: "https://YOUR-PAGEFLOCK-INGEST/api/e", debug: dev });
|
|
83
|
+
|
|
84
|
+
let { children } = $props();
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
{@render children()}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Astro
|
|
91
|
+
|
|
92
|
+
Astro bundles `<script>` tags, so add this to your base layout:
|
|
93
|
+
|
|
94
|
+
```astro
|
|
95
|
+
<script>
|
|
96
|
+
import { inject } from "@pageflock/analytics";
|
|
97
|
+
|
|
98
|
+
inject({ site: "SITE_ID", endpoint: "https://YOUR-PAGEFLOCK-INGEST/api/e" });
|
|
99
|
+
</script>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Anything else
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { inject } from "@pageflock/analytics";
|
|
106
|
+
|
|
107
|
+
inject({ site: "SITE_ID", endpoint: "https://YOUR-PAGEFLOCK-INGEST/api/e" });
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Custom events
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
import { track } from "@pageflock/analytics";
|
|
114
|
+
|
|
115
|
+
track("Signup", { plan: "pro", seats: 3 });
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Property values are strings, numbers or booleans. `track()` can be called before `<Analytics />` mounts: events wait in a queue and are sent once tracking starts. It also works when Pageflock was installed with the script tag instead, and it does nothing during server rendering.
|
|
119
|
+
|
|
120
|
+
No-code events work too: `<button data-track="Signup" data-track-plan="pro">`.
|
|
121
|
+
|
|
122
|
+
## Options
|
|
123
|
+
|
|
124
|
+
`<Analytics />` takes these props, and `inject()` takes them as an object.
|
|
125
|
+
|
|
126
|
+
| Option | Type | Default | What it does |
|
|
127
|
+
| --- | --- | --- | --- |
|
|
128
|
+
| `site` | `string` | required | The site ID from the Pageflock dashboard. |
|
|
129
|
+
| `endpoint` | `string` | required | The collect endpoint, `https://YOUR-PAGEFLOCK-INGEST/api/e`. |
|
|
130
|
+
| `autoEvents` | `boolean` | `false` | Also track outbound link clicks, file downloads and 404 pages, like `s.auto.js`. |
|
|
131
|
+
| `hashRouting` | `boolean` | `false` | Count `#hash` changes as page views, for hash-routed apps. |
|
|
132
|
+
| `beforeSend` | `(event: AnalyticsEvent) => AnalyticsEvent \| null` | none | Change an event before it is sent, or return `null` to drop it. |
|
|
133
|
+
| `debug` | `boolean` | `false` | Log every event to the console, including on localhost. |
|
|
134
|
+
|
|
135
|
+
`site`, `endpoint`, `autoEvents` and `hashRouting` are read when tracking starts. `beforeSend` and `debug` can change on later renders.
|
|
136
|
+
|
|
137
|
+
### beforeSend
|
|
138
|
+
|
|
139
|
+
Every event, page views included, passes through `beforeSend` as `{ name, url, props }`. Page views are named `pageview`, and time on page is sent as `engagement`.
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
<Analytics
|
|
143
|
+
site="SITE_ID"
|
|
144
|
+
endpoint="https://YOUR-PAGEFLOCK-INGEST/api/e"
|
|
145
|
+
beforeSend={(event) => {
|
|
146
|
+
if (new URL(event.url).pathname.startsWith("/admin")) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
const url = new URL(event.url);
|
|
150
|
+
url.searchParams.delete("token");
|
|
151
|
+
return { ...event, url: url.href };
|
|
152
|
+
}}
|
|
153
|
+
/>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Development and privacy
|
|
157
|
+
|
|
158
|
+
Like the script, the package sends nothing on `localhost`, from `file:` pages or in automated browsers, and it waits until a prerendered page is shown. Turn on `debug` to see what would be sent. It uses no cookies, no `localStorage` or `sessionStorage`, and no fingerprinting APIs.
|
|
159
|
+
|
|
160
|
+
Each entry bundles the tracker core, so the package has no runtime dependencies. React and Vue are optional peer dependencies.
|
|
161
|
+
|
|
162
|
+
## Licence
|
|
163
|
+
|
|
164
|
+
MIT, unlike the rest of the Pageflock repository, so it can ship in any site.
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// ../tracker/dist/index.js
|
|
2
|
+
var DOWNLOAD = /\.(?:pdf|zip|dmg|exe|msi|pkg|csv|xlsx?|docx?|pptx?|mp3|mp4|mov|gz|tgz|rar|7z|epub|apk)$/iu;
|
|
3
|
+
var NOT_FOUND = /\b404\b|not found/iu;
|
|
4
|
+
var linkEvent = (url) => {
|
|
5
|
+
if (DOWNLOAD.test(url.pathname)) {
|
|
6
|
+
return "File Download";
|
|
7
|
+
}
|
|
8
|
+
return url.host !== location.host && url.protocol.startsWith("http") ? "Outbound Link: Click" : void 0;
|
|
9
|
+
};
|
|
10
|
+
var installAutoEvents = (tracker) => {
|
|
11
|
+
document.addEventListener("click", (event) => {
|
|
12
|
+
const link = event.target?.closest?.(
|
|
13
|
+
"a[href]"
|
|
14
|
+
);
|
|
15
|
+
if (!link) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const url = new URL(link.href, location.href);
|
|
19
|
+
const name = linkEvent(url);
|
|
20
|
+
if (name) {
|
|
21
|
+
tracker.track(name, { url: url.href });
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
if (document.querySelector("[data-pageflock-404]") || NOT_FOUND.test(document.title)) {
|
|
25
|
+
tracker.track("404", { path: location.pathname });
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var isLocal = (host) => /^(?:localhost|127\.|\[::1\]$)/u.test(host) || location.protocol === "file:";
|
|
29
|
+
var PROP_PREFIX = "track";
|
|
30
|
+
var isTrackProp = ([key]) => key.length > PROP_PREFIX.length && key.startsWith(PROP_PREFIX);
|
|
31
|
+
var propName = (key) => key.charAt(PROP_PREFIX.length).toLowerCase() + key.slice(PROP_PREFIX.length + 1);
|
|
32
|
+
var trackProps = (dataset) => Object.fromEntries(
|
|
33
|
+
Object.entries(dataset).filter(isTrackProp).map(([key, value]) => [propName(key), value ?? ""])
|
|
34
|
+
);
|
|
35
|
+
var createTracker = (options) => {
|
|
36
|
+
const { site, endpoint, hashRouting } = options;
|
|
37
|
+
const disabled = isLocal(location.hostname) || navigator.webdriver;
|
|
38
|
+
let lastUrl;
|
|
39
|
+
let visibleSince = Date.now();
|
|
40
|
+
let engaged = 0;
|
|
41
|
+
const send = (eventName, eventProps, extra) => {
|
|
42
|
+
let name = eventName;
|
|
43
|
+
let url = lastUrl ?? location.href;
|
|
44
|
+
let props = eventProps;
|
|
45
|
+
if (options.beforeSend) {
|
|
46
|
+
const event = options.beforeSend({ name, url, props });
|
|
47
|
+
if (!event) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
({ name, url, props } = event);
|
|
51
|
+
}
|
|
52
|
+
if (disabled) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const body = JSON.stringify({
|
|
56
|
+
s: site,
|
|
57
|
+
n: name,
|
|
58
|
+
u: url,
|
|
59
|
+
r: document.referrer || void 0,
|
|
60
|
+
w: innerWidth,
|
|
61
|
+
p: props,
|
|
62
|
+
...extra
|
|
63
|
+
});
|
|
64
|
+
fetch(endpoint, { method: "POST", body, keepalive: true }).catch(
|
|
65
|
+
() => navigator.sendBeacon(endpoint, body)
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
const flushEngagement = () => {
|
|
69
|
+
if (document.visibilityState === "visible") {
|
|
70
|
+
engaged += Date.now() - visibleSince;
|
|
71
|
+
}
|
|
72
|
+
visibleSince = Date.now();
|
|
73
|
+
if (lastUrl && engaged > 0) {
|
|
74
|
+
send("engagement", void 0, { e: engaged });
|
|
75
|
+
}
|
|
76
|
+
engaged = 0;
|
|
77
|
+
};
|
|
78
|
+
const pageview = () => {
|
|
79
|
+
const url = hashRouting ? location.href : location.href.split("#")[0];
|
|
80
|
+
if (url === lastUrl) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (lastUrl) {
|
|
84
|
+
flushEngagement();
|
|
85
|
+
}
|
|
86
|
+
lastUrl = url;
|
|
87
|
+
send("pageview");
|
|
88
|
+
};
|
|
89
|
+
const originalPushState = history.pushState;
|
|
90
|
+
history.pushState = function pushState(...args) {
|
|
91
|
+
originalPushState.apply(this, args);
|
|
92
|
+
pageview();
|
|
93
|
+
};
|
|
94
|
+
addEventListener("popstate", pageview);
|
|
95
|
+
if (hashRouting) {
|
|
96
|
+
addEventListener("hashchange", pageview);
|
|
97
|
+
}
|
|
98
|
+
document.addEventListener("visibilitychange", () => {
|
|
99
|
+
if (document.visibilityState === "visible") {
|
|
100
|
+
visibleSince = Date.now();
|
|
101
|
+
} else {
|
|
102
|
+
engaged += Date.now() - visibleSince;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
addEventListener("pagehide", flushEngagement);
|
|
106
|
+
document.addEventListener("click", (event) => {
|
|
107
|
+
const element = event.target?.closest?.(
|
|
108
|
+
"[data-track]"
|
|
109
|
+
);
|
|
110
|
+
if (!element) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
send(element.dataset.track ?? "", trackProps(element.dataset));
|
|
114
|
+
});
|
|
115
|
+
return { track: (name, props) => send(name, props), pageview };
|
|
116
|
+
};
|
|
117
|
+
var init = ({ autoEvents, ...options }) => {
|
|
118
|
+
const tracker = createTracker(options);
|
|
119
|
+
tracker.pageview();
|
|
120
|
+
if (autoEvents) {
|
|
121
|
+
installAutoEvents(tracker);
|
|
122
|
+
}
|
|
123
|
+
return tracker;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// src/index.ts
|
|
127
|
+
var LOG_PREFIX = "[pageflock]";
|
|
128
|
+
var pageflockGlobal = () => globalThis;
|
|
129
|
+
var inBrowser = () => typeof window !== "undefined";
|
|
130
|
+
var current;
|
|
131
|
+
var log = (message, event) => {
|
|
132
|
+
console.info(`${LOG_PREFIX} ${message}`, event);
|
|
133
|
+
};
|
|
134
|
+
var beforeSend = (event) => {
|
|
135
|
+
const result = current?.beforeSend ? current.beforeSend(event) : event;
|
|
136
|
+
if (current?.debug) {
|
|
137
|
+
log(result ? event.name : `${event.name} (dropped)`, result ?? event);
|
|
138
|
+
}
|
|
139
|
+
return result;
|
|
140
|
+
};
|
|
141
|
+
var start = (options) => {
|
|
142
|
+
const global = pageflockGlobal();
|
|
143
|
+
const queued = global.pageflock?.q ?? [];
|
|
144
|
+
const tracker = init({
|
|
145
|
+
site: options.site,
|
|
146
|
+
endpoint: options.endpoint,
|
|
147
|
+
autoEvents: options.autoEvents,
|
|
148
|
+
hashRouting: options.hashRouting,
|
|
149
|
+
beforeSend
|
|
150
|
+
});
|
|
151
|
+
global.pageflock = { track: tracker.track };
|
|
152
|
+
for (const [name, props] of queued) {
|
|
153
|
+
tracker.track(name, props);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
var inject = (options) => {
|
|
157
|
+
if (!inBrowser()) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const global = pageflockGlobal();
|
|
161
|
+
const running = Boolean(global.pageflock?.track);
|
|
162
|
+
if (running && !current && options.debug) {
|
|
163
|
+
console.info(`${LOG_PREFIX} the script tag is already tracking this page`);
|
|
164
|
+
}
|
|
165
|
+
if (running) {
|
|
166
|
+
current && (current = options);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
current = options;
|
|
170
|
+
const queued = global.pageflock?.q ?? [];
|
|
171
|
+
global.pageflock = {
|
|
172
|
+
q: queued,
|
|
173
|
+
track: (name, props) => {
|
|
174
|
+
queued.push([name, props]);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
if (document.prerendering) {
|
|
178
|
+
document.addEventListener("prerenderingchange", () => start(options), {
|
|
179
|
+
once: true
|
|
180
|
+
});
|
|
181
|
+
} else {
|
|
182
|
+
start(options);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
var track = (name, props) => {
|
|
186
|
+
var _a;
|
|
187
|
+
if (!inBrowser()) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const global = pageflockGlobal();
|
|
191
|
+
if (global.pageflock?.track) {
|
|
192
|
+
global.pageflock.track(name, props);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
global.pageflock ?? (global.pageflock = {});
|
|
196
|
+
(_a = global.pageflock).q ?? (_a.q = []);
|
|
197
|
+
global.pageflock.q.push([name, props]);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export {
|
|
201
|
+
inject,
|
|
202
|
+
track
|
|
203
|
+
};
|
package/dist/index.js
ADDED
package/dist/next.js
ADDED
package/dist/react.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Custom event properties. Values are flat: strings, numbers or booleans. */
|
|
2
|
+
export type Props = Record<string, string | number | boolean>;
|
|
3
|
+
/** What `beforeSend` receives. `name` is `pageview` for page views. */
|
|
4
|
+
export interface AnalyticsEvent {
|
|
5
|
+
name: string;
|
|
6
|
+
url: string;
|
|
7
|
+
props?: Props;
|
|
8
|
+
}
|
|
9
|
+
export interface AnalyticsOptions {
|
|
10
|
+
/** The site ID from the Pageflock dashboard. */
|
|
11
|
+
site: string;
|
|
12
|
+
/** Full URL of the collect endpoint, for example https://pageflock.example.com/api/e. */
|
|
13
|
+
endpoint: string;
|
|
14
|
+
/** Also track outbound link clicks, file downloads and 404 pages. */
|
|
15
|
+
autoEvents?: boolean;
|
|
16
|
+
/** Count changes of `location.hash` as page views. */
|
|
17
|
+
hashRouting?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Called before every event is sent. Return the event, changed or not, or
|
|
20
|
+
* return null to drop it. Use it to strip tokens from URLs or skip pages.
|
|
21
|
+
*/
|
|
22
|
+
beforeSend?: (event: AnalyticsEvent) => AnalyticsEvent | null;
|
|
23
|
+
/** Log every event to the console, including on localhost where nothing is sent. */
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Starts tracking and records the first page view. Safe to call more than
|
|
28
|
+
* once: later calls only update `beforeSend` and `debug`. Does nothing on the
|
|
29
|
+
* server, or when the Pageflock script tag is already on the page.
|
|
30
|
+
*/
|
|
31
|
+
export declare const inject: (options: AnalyticsOptions) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Records a custom event. Before tracking starts, events are queued and sent
|
|
34
|
+
* once it does. Does nothing on the server.
|
|
35
|
+
*/
|
|
36
|
+
export declare const track: (name: string, props?: Props) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js entry, for the App Router and the Pages Router. Add it to the root
|
|
3
|
+
* layout (`app/layout.tsx`) or `pages/_app.tsx`:
|
|
4
|
+
*
|
|
5
|
+
* import { Analytics } from "@pageflock/analytics/next";
|
|
6
|
+
* <Analytics site="SITE_ID" endpoint="https://pageflock.example.com/api/e" />
|
|
7
|
+
*
|
|
8
|
+
* Client navigations go through `history.pushState`, which the tracker
|
|
9
|
+
* already follows, so no router hooks are needed.
|
|
10
|
+
*/
|
|
11
|
+
export { Analytics, track } from "./react";
|
|
12
|
+
export type { AnalyticsEvent, AnalyticsProps, Props } from "./react";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AnalyticsOptions } from "./index";
|
|
2
|
+
export type { AnalyticsEvent, Props } from "./index";
|
|
3
|
+
export { track } from "./index";
|
|
4
|
+
export type AnalyticsProps = AnalyticsOptions;
|
|
5
|
+
/** Starts Pageflock after the first render. Renders nothing. */
|
|
6
|
+
export declare const Analytics: (props: AnalyticsProps) => null;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { PropType } from "vue";
|
|
2
|
+
import type { AnalyticsOptions } from "./index";
|
|
3
|
+
export type { AnalyticsEvent, Props } from "./index";
|
|
4
|
+
export { track } from "./index";
|
|
5
|
+
/** Starts Pageflock when mounted. Renders nothing. */
|
|
6
|
+
export declare const Analytics: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
7
|
+
site: {
|
|
8
|
+
type: StringConstructor;
|
|
9
|
+
required: true;
|
|
10
|
+
};
|
|
11
|
+
endpoint: {
|
|
12
|
+
type: StringConstructor;
|
|
13
|
+
required: true;
|
|
14
|
+
};
|
|
15
|
+
autoEvents: BooleanConstructor;
|
|
16
|
+
hashRouting: BooleanConstructor;
|
|
17
|
+
debug: BooleanConstructor;
|
|
18
|
+
beforeSend: PropType<AnalyticsOptions["beforeSend"]>;
|
|
19
|
+
}>, () => null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
20
|
+
site: {
|
|
21
|
+
type: StringConstructor;
|
|
22
|
+
required: true;
|
|
23
|
+
};
|
|
24
|
+
endpoint: {
|
|
25
|
+
type: StringConstructor;
|
|
26
|
+
required: true;
|
|
27
|
+
};
|
|
28
|
+
autoEvents: BooleanConstructor;
|
|
29
|
+
hashRouting: BooleanConstructor;
|
|
30
|
+
debug: BooleanConstructor;
|
|
31
|
+
beforeSend: PropType<AnalyticsOptions["beforeSend"]>;
|
|
32
|
+
}>> & Readonly<{}>, {
|
|
33
|
+
autoEvents: boolean;
|
|
34
|
+
hashRouting: boolean;
|
|
35
|
+
debug: boolean;
|
|
36
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
package/dist/vue.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
inject,
|
|
3
|
+
track
|
|
4
|
+
} from "./chunks/chunk-7JF7P3VW.js";
|
|
5
|
+
|
|
6
|
+
// src/vue.ts
|
|
7
|
+
import { defineComponent, onMounted } from "vue";
|
|
8
|
+
var Analytics = defineComponent({
|
|
9
|
+
name: "PageflockAnalytics",
|
|
10
|
+
props: {
|
|
11
|
+
site: { type: String, required: true },
|
|
12
|
+
endpoint: { type: String, required: true },
|
|
13
|
+
autoEvents: Boolean,
|
|
14
|
+
hashRouting: Boolean,
|
|
15
|
+
debug: Boolean,
|
|
16
|
+
beforeSend: Function
|
|
17
|
+
},
|
|
18
|
+
setup(props) {
|
|
19
|
+
onMounted(() => {
|
|
20
|
+
inject({ ...props });
|
|
21
|
+
});
|
|
22
|
+
return () => null;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
export {
|
|
26
|
+
Analytics,
|
|
27
|
+
track
|
|
28
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,81 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pageflock/analytics",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Pageflock analytics for React, Next.js, Vue and any bundled site: cookieless, under 2 KB.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"analytics",
|
|
7
|
+
"cookieless",
|
|
8
|
+
"nextjs",
|
|
9
|
+
"privacy",
|
|
10
|
+
"react",
|
|
11
|
+
"vue",
|
|
12
|
+
"web-analytics"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/thebuilder/pageflock/tree/main/packages/analytics#readme",
|
|
15
|
+
"bugs": "https://github.com/thebuilder/pageflock/issues",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/thebuilder/pageflock.git",
|
|
20
|
+
"directory": "packages/analytics"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"type": "module",
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/types/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./react": {
|
|
35
|
+
"types": "./dist/types/react.d.ts",
|
|
36
|
+
"default": "./dist/react.js"
|
|
37
|
+
},
|
|
38
|
+
"./next": {
|
|
39
|
+
"types": "./dist/types/next.d.ts",
|
|
40
|
+
"default": "./dist/next.js"
|
|
41
|
+
},
|
|
42
|
+
"./vue": {
|
|
43
|
+
"types": "./dist/types/vue.d.ts",
|
|
44
|
+
"default": "./dist/vue.js"
|
|
45
|
+
},
|
|
46
|
+
"./package.json": "./package.json"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/node": "^22.20.5",
|
|
53
|
+
"@types/react": "19.3.0",
|
|
54
|
+
"@types/react-dom": "19.3.0",
|
|
55
|
+
"esbuild": "0.28.2",
|
|
56
|
+
"happy-dom": "21.0.4",
|
|
57
|
+
"react": "19.3.1",
|
|
58
|
+
"react-dom": "19.3.1",
|
|
59
|
+
"typescript": "7.0.2",
|
|
60
|
+
"vitest": "5.1.0",
|
|
61
|
+
"vue": "3.5.45",
|
|
62
|
+
"@pageflock/tracker": "0.1.0"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"react": ">=18",
|
|
66
|
+
"vue": ">=3.3"
|
|
67
|
+
},
|
|
68
|
+
"peerDependenciesMeta": {
|
|
69
|
+
"react": {
|
|
70
|
+
"optional": true
|
|
71
|
+
},
|
|
72
|
+
"vue": {
|
|
73
|
+
"optional": true
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"scripts": {
|
|
77
|
+
"build": "node scripts/build.ts && tsc -p tsconfig.build.json",
|
|
78
|
+
"check-types": "tsc --noEmit",
|
|
79
|
+
"test": "vitest run"
|
|
80
|
+
}
|
|
6
81
|
}
|