@viakite/sdk 0.0.0-stage → 0.5.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 +272 -2
- package/dist/a.js +1 -0
- package/dist/api.d.ts +26 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/public/client.d.ts +19 -0
- package/dist/public/live.d.ts +17 -0
- package/dist/public/types.d.ts +77 -0
- package/dist/react/Analytics.d.ts +12 -0
- package/dist/react/Chart.d.ts +28 -0
- package/dist/react/Compare.d.ts +15 -0
- package/dist/react/DateRangePicker.d.ts +28 -0
- package/dist/react/LiveVisitors.d.ts +17 -0
- package/dist/react/TopList.d.ts +33 -0
- package/dist/react/ViakiteProvider.d.ts +35 -0
- package/dist/react/VisitorCount.d.ts +19 -0
- package/dist/react/format.d.ts +16 -0
- package/dist/react/index.cjs +2 -0
- package/dist/react/index.d.ts +20 -0
- package/dist/react/index.js +2 -0
- package/dist/react/useReport.d.ts +28 -0
- package/dist/svelte/Analytics.svelte +16 -0
- package/dist/svelte/index.d.ts +10 -0
- package/dist/svelte/index.js +6 -0
- package/dist/types.d.ts +44 -0
- package/dist/vue/Analytics.d.ts +67 -0
- package/dist/vue/index.cjs +1 -0
- package/dist/vue/index.d.ts +1 -0
- package/dist/vue/index.js +1 -0
- package/package.json +81 -4
package/README.md
CHANGED
|
@@ -1,3 +1,273 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @viakite/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Viakite Analytics for the browser: page views, custom events, revenue, engaged time and scroll depth. No cookies, nothing stored on the visitor's device, no consent banner needed.
|
|
4
|
+
|
|
5
|
+
## Script tag
|
|
6
|
+
|
|
7
|
+
Add one line to every page, in the `<head>`:
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<script defer src="https://us.api.vk.viabio.me/v1/a.js" data-project="pk_live_us_…"></script>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The key carries your region; events go to `https://<region>.e.<domain>/v1/events`, `<domain>` being the one the SDK was built for (`vk.viabio.me` today).
|
|
14
|
+
|
|
15
|
+
### Attributes
|
|
16
|
+
|
|
17
|
+
| Attribute | Default | Does |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| `data-project` | required | Your project's public key, `pk_live_…` or `pk_test_…` |
|
|
20
|
+
| `data-api` | your region's address | Send events to another address, such as your own proxy. A path (`/va/e`) is read from the script's own address |
|
|
21
|
+
| `data-title` | off | Send the page title. Off by default because titles can hold personal data |
|
|
22
|
+
| `data-hash` | off | Count hash routes (`/#/about`) as pages |
|
|
23
|
+
| `data-params` | none | Extra query parameters to keep, comma-separated (`data-params="plan,coupon"`) |
|
|
24
|
+
| `data-outbound` | on | Track clicks on links to other sites as `Outbound link`. Turn off with `data-outbound="false"` |
|
|
25
|
+
| `data-downloads` | on | Track clicks on file links as `File download`. Turn off with `data-downloads="false"` |
|
|
26
|
+
| `data-download-ext` | see below | The file extensions that count as downloads, replacing the default list (`data-download-ext="pdf,zip,apk"`) |
|
|
27
|
+
| `data-404` | off | Put it on your not-found page: the view counts as a broken page |
|
|
28
|
+
| `data-debug` | off | Log every event and warning in the browser console, and send nothing |
|
|
29
|
+
| `data-localhost` | off | Track on `localhost`, `127.0.0.1` and `file://` |
|
|
30
|
+
|
|
31
|
+
Flags are on when present (`data-title`) and off when absent or `"false"`.
|
|
32
|
+
|
|
33
|
+
Default download extensions: `pdf`, `zip`, `rar`, `7z`, `dmg`, `apk`, `exe`, `msi`, `doc`, `docx`, `xls`, `xlsx`, `pptx`, `csv`, `mp4`, `mov`, `mp3`.
|
|
34
|
+
|
|
35
|
+
### Calling it from your code
|
|
36
|
+
|
|
37
|
+
The script sets `window.viakite`:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
viakite.track("Signup", { plan: "pro", source: "pricing" });
|
|
41
|
+
viakite.track("Purchase", { revenue: 499, currency: "INR", product: "Pro yearly" });
|
|
42
|
+
viakite.identify("user_8231", { plan: "pro", company: "Acme" });
|
|
43
|
+
viakite.reset(); // on sign-out
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
To call it before the script has loaded (it is `defer`), add this stub above the script tag. Calls wait in its queue and run as soon as the script loads:
|
|
47
|
+
|
|
48
|
+
```html
|
|
49
|
+
<script>
|
|
50
|
+
window.viakite = window.viakite || function () { (window.viakite.q = window.viakite.q || []).push(arguments) };
|
|
51
|
+
</script>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
With the stub, use the function form until the script has loaded: `viakite("track", "Signup", { plan: "pro" })`. After it loads, both forms work.
|
|
55
|
+
|
|
56
|
+
## npm
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
npm install @viakite/sdk
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import { init, track, identify, reset } from "@viakite/sdk";
|
|
64
|
+
|
|
65
|
+
init({ project: "pk_live_us_…" });
|
|
66
|
+
track("Signup", { plan: "pro" });
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
It is safe to import in server-side rendering: on the server (no `window`) every function does nothing.
|
|
70
|
+
|
|
71
|
+
### API
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
init(options: Options): void
|
|
75
|
+
track(name: string, props?: Props): void
|
|
76
|
+
identify(userId: string, traits?: Props): void
|
|
77
|
+
reset(): void
|
|
78
|
+
pageview(options?: { notFound?: boolean }): void
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
- **`init`** starts tracking: it sends the page view and follows page changes in single-page apps, engaged time, scroll depth and clicks. Call it once; a second call does nothing (with a warning in debug mode). Calls to `track`, `identify`, `reset` and `pageview` made before `init` are kept and sent once `init` runs.
|
|
82
|
+
- **`track`** sends a custom event.
|
|
83
|
+
- **`identify`** ties this tab's next events to your own user id and sends the traits. The id stays in memory only, for this tab.
|
|
84
|
+
- **`reset`** forgets the identified user in this tab. Call it on sign-out.
|
|
85
|
+
- **`pageview`** sends a page view by hand, for apps that set `autoPageviews: false` and follow their own router.
|
|
86
|
+
|
|
87
|
+
None of them ever throws. A missing or wrong key turns tracking off, with a warning in debug mode.
|
|
88
|
+
|
|
89
|
+
### Options
|
|
90
|
+
|
|
91
|
+
The options match the script's attributes:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
interface Options {
|
|
95
|
+
project: string; // data-project
|
|
96
|
+
api?: string; // data-api
|
|
97
|
+
title?: boolean; // data-title
|
|
98
|
+
hash?: boolean; // data-hash
|
|
99
|
+
params?: string[] | string; // data-params
|
|
100
|
+
outbound?: boolean; // data-outbound, default true
|
|
101
|
+
downloads?: boolean; // data-downloads, default true
|
|
102
|
+
downloadExtensions?: string[] | string; // data-download-ext
|
|
103
|
+
notFound?: boolean; // data-404
|
|
104
|
+
debug?: boolean; // data-debug
|
|
105
|
+
localhost?: boolean; // data-localhost
|
|
106
|
+
autoPageviews?: boolean; // npm only, default true
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`Options`, `Props`, `PropValue` and `PageviewOptions` are exported as types.
|
|
111
|
+
|
|
112
|
+
## Components for React, Next.js, Vue and Svelte
|
|
113
|
+
|
|
114
|
+
`<Analytics />` calls `init` once, in the browser, and renders nothing. Add it once, at the root of your app. Its props are the options above (`project`, `api`, `title`, `hash`, `params`, `outbound`, `downloads`, `downloadExtensions`, `notFound`, `debug`, `localhost`, `autoPageviews`). Page changes are followed through the browser's history, which every router below uses: one page view per new path, none when only the query changes. Call `track`, `identify` and `reset` from `@viakite/sdk` anywhere; calls made before the component has mounted are kept and sent once it does.
|
|
115
|
+
|
|
116
|
+
React, Vue and Svelte are optional peer dependencies: install only the one you use.
|
|
117
|
+
|
|
118
|
+
### Next.js (App Router)
|
|
119
|
+
|
|
120
|
+
In `app/layout.tsx`. The component is a client component, so a server layout can render it:
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
import { Analytics } from "@viakite/sdk/react";
|
|
124
|
+
|
|
125
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
126
|
+
return (
|
|
127
|
+
<html lang="en">
|
|
128
|
+
<body>
|
|
129
|
+
{children}
|
|
130
|
+
<Analytics project="pk_live_us_…" />
|
|
131
|
+
</body>
|
|
132
|
+
</html>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Next.js (Pages Router)
|
|
138
|
+
|
|
139
|
+
In `pages/_app.tsx`:
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
import type { AppProps } from "next/app";
|
|
143
|
+
import { Analytics } from "@viakite/sdk/react";
|
|
144
|
+
|
|
145
|
+
export default function App({ Component, pageProps }: AppProps) {
|
|
146
|
+
return (
|
|
147
|
+
<>
|
|
148
|
+
<Component {...pageProps} />
|
|
149
|
+
<Analytics project="pk_live_us_…" />
|
|
150
|
+
</>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### React (Vite, Create React App, React Router)
|
|
156
|
+
|
|
157
|
+
At the top of your app:
|
|
158
|
+
|
|
159
|
+
```tsx
|
|
160
|
+
import { Analytics } from "@viakite/sdk/react";
|
|
161
|
+
|
|
162
|
+
export function App() {
|
|
163
|
+
return (
|
|
164
|
+
<>
|
|
165
|
+
<Analytics project="pk_live_us_…" />
|
|
166
|
+
{/* your routes */}
|
|
167
|
+
</>
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Vue 3 and Nuxt
|
|
173
|
+
|
|
174
|
+
In `App.vue` (Vue) or `app.vue` (Nuxt). It starts on mount, so server rendering is safe:
|
|
175
|
+
|
|
176
|
+
```vue
|
|
177
|
+
<script setup lang="ts">
|
|
178
|
+
import { Analytics } from "@viakite/sdk/vue";
|
|
179
|
+
</script>
|
|
180
|
+
|
|
181
|
+
<template>
|
|
182
|
+
<Analytics project="pk_live_us_…" />
|
|
183
|
+
<RouterView />
|
|
184
|
+
</template>
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
In Nuxt, use `<NuxtPage />` in place of `<RouterView />`.
|
|
188
|
+
|
|
189
|
+
### Svelte 5 and SvelteKit
|
|
190
|
+
|
|
191
|
+
In `src/routes/+layout.svelte` (SvelteKit) or `App.svelte`:
|
|
192
|
+
|
|
193
|
+
```svelte
|
|
194
|
+
<script>
|
|
195
|
+
import Analytics from "@viakite/sdk/svelte";
|
|
196
|
+
let { children } = $props();
|
|
197
|
+
</script>
|
|
198
|
+
|
|
199
|
+
<Analytics project="pk_live_us_…" />
|
|
200
|
+
{@render children()}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
The named import works too: `import { Analytics } from "@viakite/sdk/svelte"`. The component ships as Svelte source and is compiled by your app's Svelte 5.
|
|
204
|
+
|
|
205
|
+
### Options as props
|
|
206
|
+
|
|
207
|
+
```tsx
|
|
208
|
+
<Analytics project="pk_live_us_…" title hash debug />
|
|
209
|
+
<Analytics project="pk_live_us_…" api="/va/e" params={["plan", "coupon"]} outbound={false} />
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
While developing on `localhost`, add `localhost` to send events, or `debug` to see them in the console without sending.
|
|
213
|
+
|
|
214
|
+
### Show your stats on your site (React)
|
|
215
|
+
|
|
216
|
+
Display components read a share token (`st_…`, made in Analytics → Sharing), never a secret key:
|
|
217
|
+
|
|
218
|
+
```tsx
|
|
219
|
+
import { Chart, Compare, DateRangePicker, LiveVisitors, TopPages, ViakiteProvider, VisitorCount } from "@viakite/sdk/react";
|
|
220
|
+
|
|
221
|
+
<ViakiteProvider share="st_…">
|
|
222
|
+
<DateRangePicker /> <Compare />
|
|
223
|
+
<VisitorCount /> visitors, <LiveVisitors /> online now
|
|
224
|
+
<Chart metric="visitors" />
|
|
225
|
+
<TopPages limit={5} />
|
|
226
|
+
</ViakiteProvider>;
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
They come unstyled: each has a `vk-*` class and a `data-state` (`loading`, `ready`, `error`).
|
|
230
|
+
|
|
231
|
+
## Events without code
|
|
232
|
+
|
|
233
|
+
A class on any element sends an event when it is clicked:
|
|
234
|
+
|
|
235
|
+
```html
|
|
236
|
+
<button class="viakite-event-name=Signup viakite-event-plan=pro">Sign up</button>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
`viakite-event-name=…` names the event; every other `viakite-event-<key>=<value>` class becomes a property. Write a space as `+`: `viakite-event-name=Sign+up`.
|
|
240
|
+
|
|
241
|
+
## Limits
|
|
242
|
+
|
|
243
|
+
| | Limit |
|
|
244
|
+
|---|---|
|
|
245
|
+
| Event name | 1 to 120 characters |
|
|
246
|
+
| Properties | Up to 20 per event, flat: text up to 255 characters, a number, true/false or null. No objects or lists; flatten them (`address_city`) |
|
|
247
|
+
| Property names | 1 to 40 characters: letters, digits, `_`, `-`, `.` |
|
|
248
|
+
| Revenue | `revenue` (a number) and `currency` (an ISO code such as `INR` or `USD`); they don't count against the 20 |
|
|
249
|
+
| User id | Up to 120 characters, your own id. An id that looks like an e-mail address or phone number is dropped |
|
|
250
|
+
| Traits | The same limits as properties |
|
|
251
|
+
|
|
252
|
+
Values over a limit are cut, never rejected; anything that can't be sent is dropped. In debug mode each cut or drop is a warning in the console.
|
|
253
|
+
|
|
254
|
+
## What is sent, and what isn't
|
|
255
|
+
|
|
256
|
+
- Page URLs keep only these query parameters: `utm_source`, `utm_medium`, `utm_campaign`, `utm_term`, `utm_content`, `ref`, `gclid`, `fbclid`, `msclkid`, `li_fat_id`, `q`, `query`, `search`, `s`, and the ones you add with `params`. The fragment is dropped unless hash mode is on.
|
|
257
|
+
- The referrer is sent without its query and fragment, and only when it is another site.
|
|
258
|
+
- No cookies, no identifiers stored on the device, no IP address in the body.
|
|
259
|
+
- Page views and custom events are sent at once. Engaged time and scroll depth are sent when the page is hidden or left, with `navigator.sendBeacon`. A failed send is retried after 1, 5 and 15 seconds, and waits for the network when offline; the queue lives in memory only.
|
|
260
|
+
|
|
261
|
+
## Single-page apps
|
|
262
|
+
|
|
263
|
+
The SDK follows `history.pushState`, `history.replaceState` and `popstate`. A new page view is sent only when the path changes (or the hash route, in hash mode); a change to the query alone, such as a filter or sort, is not a new page view.
|
|
264
|
+
|
|
265
|
+
## Privacy
|
|
266
|
+
|
|
267
|
+
Nothing is sent when:
|
|
268
|
+
|
|
269
|
+
- the browser is automated (`navigator.webdriver`);
|
|
270
|
+
- the site is on `localhost`, `127.0.0.1` or `file://`, unless `localhost` is on;
|
|
271
|
+
- you excluded your own visits in this browser: run `localStorage.setItem("viakite_ignore", "true")` in your site's console (and `localStorage.removeItem("viakite_ignore")` to count them again).
|
|
272
|
+
|
|
273
|
+
When your project respects Do Not Track and Global Privacy Control, events from visitors who set them are dropped as they arrive and never stored.
|
package/dist/a.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{var E="utm_source,utm_medium,utm_campaign,utm_term,utm_content,ref,gclid,fbclid,msclkid,li_fat_id,q,query,search,s".split(",");function P(t){return t.split("?")[0]}function A(t,e,o){let n=new URL(t);return n.search=""+new URLSearchParams([...n.searchParams].filter(([c])=>e.includes(c))),n.hash=o?P(n.hash):"",n.href}function _(t){let e=t?new URL(t):location;return e.hostname==location.hostname?"":e.origin+e.pathname}function v(t){return location.pathname+(t?P(location.hash):"")}function w(t){return(""+(t||"")).match(/[^\s,]+/g)||[]}var Y=w("pdf,zip,rar,7z,dmg,apk,exe,msi,doc,docx,xls,xlsx,pptx,csv,mp4,mov,mp3"),L=(t,e)=>t==null?!!e:t!==!1&&t!="false";function O(t){let e=(""+(t.project||"")).trim(),o=/^pk_(live|test)_([a-z]{2})_[a-z\d]+$/.exec(e),n=w(t.downloadExtensions),c={key:o?e:"",endpoint:t.api||"https://"+(o&&o[2])+".e.vk.viabio.me/v1/events",params:E.concat(w(t.params)),extensions:n.length?n:Y},s=c,i=t;return"title hash notFound debug localhost".split(" ").forEach(r=>s[r]=L(i[r])),"outbound downloads autoPageviews".split(" ").forEach(r=>s[r]=L(i[r],!0)),c}function S(t){return(e,o)=>t&&console.log("[viakite] "+e,o??"")}var C="viakite_ignore";function R(t){let e=!1;try{e=localStorage.getItem(C)=="true"}catch{}let o=/^(localhost|127\.[\d.]+|\[::1\])$|\.localhost$/.test(location.hostname)||location.protocol=="file:";return navigator.webdriver?"webdriver":e?C:o&&!t?"localhost":""}function m(t){return(...e)=>{try{t(...e)}catch{}}}function h(t,e,o,n){let c=Array.from(t);return c.length>e&&n(o+" cut to "+e),c.slice(0,e).join("")}function M(t,e){return h((""+(t||"")).trim(),120,"name",e)}function $(t){return/[\w.%+-]+@[\w.-]+\.[a-z]{2,}/i.test(t)||/\d{7}/.test(t.replace(/[\s().-]/g,""))}function D(t,e){let o=(""+(t||"")).trim(),n=$(o);return n&&e("user id looks personal; dropped"),n?"":h(o,120,"user id",e)}function k(t,e){let o={},n=t&&typeof t=="object"?t:{},c=0;for(let s in n){let i=n[s],r=typeof i,l=s=="revenue",a=l||s=="currency";(a?l?r=="number":/^[a-z]{3}$/i.test(i):/^[\w.-]+$/.test(s)&&(i===null||/^(nu|st|bo)/.test(r))&&c++<20)?a?o[s]=l?i:i.toUpperCase():o[h(s,40,s,e)]=r=="string"?h(i,255,s,e):i:i!==void 0&&e(s+": dropped")}return o}var K=[1e3,5e3,15e3];function I(t,e,o){let n=[],c=r=>(r.sent=Date.now(),fetch(t,{method:"POST",body:JSON.stringify(r),keepalive:!0})),s=(r,l)=>navigator.onLine?c(r).then(a=>a.status>499||a.status==429?i(r,l,a.status):a.ok||e("refused: "+a.status),a=>i(r,l,a)):n.push(r),i=(r,l,a)=>l<3?setTimeout(()=>s(r,l+1),K[l]):e("not sent: "+a);return addEventListener("online",()=>n.splice(0).forEach(r=>s(r,0))),(r,l)=>{o?e("send",r):l?(r.sent=Date.now(),navigator.sendBeacon&&navigator.sendBeacon(t,JSON.stringify(r))||c(r).catch(()=>0)):s(r,0)}}var B="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function N(){let t=Date.now(),e=crypto.getRandomValues(new Uint8Array(16)),o="";for(let n=0;n<26;n++)o+=B[n<10?Math.floor(t/2**(45-5*n))%32:e[n-10]%32];return o}function T(t,e){let o=m(n=>{let c=n.target,s=c.closest('[class*="viakite-event-name="]'),i=c.closest("a[href]"),r={};if(n.button>1||(s&&(s.getAttribute("class").replace(/viakite-event-([\w.-]+)=(\S+)/g,(d,u,p)=>r[u]=p.replace(/\+/g," ")),e(r.name,{...r,name:void 0})),!i||!/^http/.test(i.protocol)))return;let l={url:i.origin+i.pathname},a=/\.(\w+)$/.exec(i.pathname);t.downloads&&a&&t.extensions.includes(a[1].toLowerCase())?e("File download",l):t.outbound&&i.hostname!=location.hostname&&e("Outbound link",l)});addEventListener("click",o,!0),addEventListener("auxclick",o,!0)}function U(t){let e=0,o=0,n=0,c=0,s=0,i=0,r=()=>{let a=(scrollY+innerHeight)/document.documentElement.scrollHeight*100||0;n=Math.max(n,a>98?100:a-a%25)},l=()=>{let a=Date.now(),d=[].some.call(document.querySelectorAll("video,audio"),u=>!u.paused);if(!document.hidden&&(a-s<3e4||d)){let u=Math.min(a-i,18e5-e);e+=u,o+=u}i=a};return setInterval(l,1e3),"mousemove mousedown keydown touchstart scroll".split(" ").forEach(a=>addEventListener(a,d=>{s=Date.now(),d.type=="scroll"&&r()},!0)),addEventListener("visibilitychange",()=>document.hidden?t():s=i=Date.now(),!0),addEventListener("pagehide",t),a=>{if(a){e=o=n=c=0,s=i=Date.now();return}l(),o>999&&r();let d=n>c?n:0;if(o<1e3&&d<25)return;let u={engaged_ms:o,scroll:d};return o=0,c=n,u}}function X(t){["pushState","replaceState"].forEach(e=>{let o=history[e];history[e]=function(...n){o.apply(this,n),t()}}),addEventListener("popstate",t)}function V(t,e){let o=I(t.endpoint,e,t.debug),n="",c,s="",i=(p,g,f)=>{let y={type:p,id:N(),project:t.key,url:A(location.href,t.params,t.hash),ts:Date.now()};return n&&(y.user_id=n),o(Object.assign(y,g),f),y},r=m(()=>{let p=c&&l();c&&p&&i("engagement",{url:c.url,pageview_id:c.id,...p},!0)}),l=U(r),a=p=>{r(),l(!0),s=v(t.hash),c=i("pageview",{referrer:c?"":_(document.referrer),title:t.title?document.title:void 0,screen:[screen.width,screen.height],language:navigator.language,not_found:p&&p.notFound||!c&&t.notFound||void 0})},d=(p,g)=>{let f=M(p,e);f?i("event",{name:f,props:k(g,e)}):e("no event name")},u=(p,g)=>{let f=D(p,e);f&&i("identify",{user_id:n=f,traits:k(g,e)})};return T(t,d),t.autoPageviews&&(X(m(()=>v(t.hash)!=s&&a())),a()),{track:d,identify:u,reset:()=>n="",pageview:a}}var H=!1,x;var b=t=>m((...e)=>{x&&x[t](...e)}),F=m(t=>{if(typeof document>"u")return;let e=O(t||{}),o=S(e.debug);if(H)return o("init twice");if(H=!0,!e.key)return o("bad key: "+(t&&t.project));let n=R(e.localhost);n&&!e.debug||(n&&o("off: "+n),x=V(e,o))}),W=b("track"),j=b("identify"),G=b("reset");function q(t){let e=t?t.dataset:{};return{...e,api:e.api&&new URL(e.api,t&&t.src||location.href).href,downloadExtensions:e.downloadExt,notFound:e[404]}}var z={track:W,identify:j,reset:G};try{let t=window,e=t.viakite&&t.viakite.q||[],o=((n,...c)=>{let s=z[n];s&&s(...c)});Object.assign(o,z),t.viakite=o,F(q(document.currentScript)),[].forEach.call(e,n=>o(...n))}catch{}})();
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Options, PageviewOptions, Props } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* init starts Viakite Analytics on this page: it sends the page view and
|
|
4
|
+
* follows page changes, engagement and clicks. A second call does nothing.
|
|
5
|
+
* On the server (no window) it does nothing, so it is safe to import in SSR.
|
|
6
|
+
* It never throws: a missing or wrong key turns the SDK off, with a warning
|
|
7
|
+
* in debug mode.
|
|
8
|
+
*/
|
|
9
|
+
export declare const init: (options: Options) => void;
|
|
10
|
+
/**
|
|
11
|
+
* track sends a custom event: a name of 1 to 120 characters and up to 20
|
|
12
|
+
* flat properties. `revenue` and `currency` in the properties record a sale.
|
|
13
|
+
*/
|
|
14
|
+
export declare const track: (name: string, props?: Props) => void;
|
|
15
|
+
/**
|
|
16
|
+
* identify ties this tab's next events to your own user id (up to 120
|
|
17
|
+
* characters, never an e-mail address or phone number), with optional traits.
|
|
18
|
+
*/
|
|
19
|
+
export declare const identify: (userId: string, traits?: Props) => void;
|
|
20
|
+
/** reset forgets the identified user in this tab; call it on sign-out. */
|
|
21
|
+
export declare const reset: () => void;
|
|
22
|
+
/**
|
|
23
|
+
* pageview sends a page view by hand, for apps that turn autoPageviews off
|
|
24
|
+
* and follow their own router.
|
|
25
|
+
*/
|
|
26
|
+
export declare const pageview: (options?: PageviewOptions) => void;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var x=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var J=(e,t)=>{for(var o in t)x(e,o,{get:t[o],enumerable:!0})},Q=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of B(t))!q.call(e,s)&&s!==o&&x(e,s,{get:()=>t[s],enumerable:!(n=K(t,s))||n.enumerable});return e};var Z=e=>Q(x({},"__esModule",{value:!0}),e);var re={};J(re,{identify:()=>z,init:()=>G,pageview:()=>$,reset:()=>Y,track:()=>j});module.exports=Z(re);var _="utm_source,utm_medium,utm_campaign,utm_term,utm_content,ref,gclid,fbclid,msclkid,li_fat_id,q,query,search,s".split(",");function C(e){return e.split("?")[0]}function L(e,t,o){let n=new URL(e);return n.search=""+new URLSearchParams([...n.searchParams].filter(([s])=>t.includes(s))),n.hash=o?C(n.hash):"",n.href}function R(e){let t=e?new URL(e):location;return t.hostname==location.hostname?"":t.origin+t.pathname}function k(e){return location.pathname+(e?C(location.hash):"")}function b(e){return(""+(e||"")).match(/[^\s,]+/g)||[]}var ee=b("pdf,zip,rar,7z,dmg,apk,exe,msi,doc,docx,xls,xlsx,pptx,csv,mp4,mov,mp3"),O=(e,t)=>e==null?!!t:e!==!1&&e!="false";function S(e){let t=(""+(e.project||"")).trim(),o=/^pk_(live|test)_([a-z]{2})_[a-z\d]+$/.exec(t),n=b(e.downloadExtensions),s={key:o?t:"",endpoint:e.api||"https://"+(o&&o[2])+".e.vk.viabio.me/v1/events",params:_.concat(b(e.params)),extensions:n.length?n:ee},c=s,i=e;return"title hash notFound debug localhost".split(" ").forEach(r=>c[r]=O(i[r])),"outbound downloads autoPageviews".split(" ").forEach(r=>c[r]=O(i[r],!0)),s}function M(e){return(t,o)=>e&&console.log("[viakite] "+t,o??"")}var D="viakite_ignore";function I(e){let t=!1;try{t=localStorage.getItem(D)=="true"}catch{}let o=/^(localhost|127\.[\d.]+|\[::1\])$|\.localhost$/.test(location.hostname)||location.protocol=="file:";return navigator.webdriver?"webdriver":t?D:o&&!e?"localhost":""}function g(e){return(...t)=>{try{e(...t)}catch{}}}function h(e,t,o,n){let s=Array.from(e);return s.length>t&&n(o+" cut to "+t),s.slice(0,t).join("")}function N(e,t){return h((""+(e||"")).trim(),120,"name",t)}function te(e){return/[\w.%+-]+@[\w.-]+\.[a-z]{2,}/i.test(e)||/\d{7}/.test(e.replace(/[\s().-]/g,""))}function X(e,t){let o=(""+(e||"")).trim(),n=te(o);return n&&t("user id looks personal; dropped"),n?"":h(o,120,"user id",t)}function P(e,t){let o={},n=e&&typeof e=="object"?e:{},s=0;for(let c in n){let i=n[c],r=typeof i,l=c=="revenue",a=l||c=="currency";(a?l?r=="number":/^[a-z]{3}$/i.test(i):/^[\w.-]+$/.test(c)&&(i===null||/^(nu|st|bo)/.test(r))&&s++<20)?a?o[c]=l?i:i.toUpperCase():o[h(c,40,c,t)]=r=="string"?h(i,255,c,t):i:i!==void 0&&t(c+": dropped")}return o}var ne=[1e3,5e3,15e3];function U(e,t,o){let n=[],s=r=>(r.sent=Date.now(),fetch(e,{method:"POST",body:JSON.stringify(r),keepalive:!0})),c=(r,l)=>navigator.onLine?s(r).then(a=>a.status>499||a.status==429?i(r,l,a.status):a.ok||t("refused: "+a.status),a=>i(r,l,a)):n.push(r),i=(r,l,a)=>l<3?setTimeout(()=>c(r,l+1),ne[l]):t("not sent: "+a);return addEventListener("online",()=>n.splice(0).forEach(r=>c(r,0))),(r,l)=>{o?t("send",r):l?(r.sent=Date.now(),navigator.sendBeacon&&navigator.sendBeacon(e,JSON.stringify(r))||s(r).catch(()=>0)):c(r,0)}}var oe="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function T(){let e=Date.now(),t=crypto.getRandomValues(new Uint8Array(16)),o="";for(let n=0;n<26;n++)o+=oe[n<10?Math.floor(e/2**(45-5*n))%32:t[n-10]%32];return o}function V(e,t){let o=g(n=>{let s=n.target,c=s.closest('[class*="viakite-event-name="]'),i=s.closest("a[href]"),r={};if(n.button>1||(c&&(c.getAttribute("class").replace(/viakite-event-([\w.-]+)=(\S+)/g,(d,u,p)=>r[u]=p.replace(/\+/g," ")),t(r.name,{...r,name:void 0})),!i||!/^http/.test(i.protocol)))return;let l={url:i.origin+i.pathname},a=/\.(\w+)$/.exec(i.pathname);e.downloads&&a&&e.extensions.includes(a[1].toLowerCase())?t("File download",l):e.outbound&&i.hostname!=location.hostname&&t("Outbound link",l)});addEventListener("click",o,!0),addEventListener("auxclick",o,!0)}function F(e){let t=0,o=0,n=0,s=0,c=0,i=0,r=()=>{let a=(scrollY+innerHeight)/document.documentElement.scrollHeight*100||0;n=Math.max(n,a>98?100:a-a%25)},l=()=>{let a=Date.now(),d=[].some.call(document.querySelectorAll("video,audio"),u=>!u.paused);if(!document.hidden&&(a-c<3e4||d)){let u=Math.min(a-i,18e5-t);t+=u,o+=u}i=a};return setInterval(l,1e3),"mousemove mousedown keydown touchstart scroll".split(" ").forEach(a=>addEventListener(a,d=>{c=Date.now(),d.type=="scroll"&&r()},!0)),addEventListener("visibilitychange",()=>document.hidden?e():c=i=Date.now(),!0),addEventListener("pagehide",e),a=>{if(a){t=o=n=s=0,c=i=Date.now();return}l(),o>999&&r();let d=n>s?n:0;if(o<1e3&&d<25)return;let u={engaged_ms:o,scroll:d};return o=0,s=n,u}}function H(e){["pushState","replaceState"].forEach(t=>{let o=history[t];history[t]=function(...n){o.apply(this,n),e()}}),addEventListener("popstate",e)}function W(e,t){let o=U(e.endpoint,t,e.debug),n="",s,c="",i=(p,f,m)=>{let w={type:p,id:T(),project:e.key,url:L(location.href,e.params,e.hash),ts:Date.now()};return n&&(w.user_id=n),o(Object.assign(w,f),m),w},r=g(()=>{let p=s&&l();s&&p&&i("engagement",{url:s.url,pageview_id:s.id,...p},!0)}),l=F(r),a=p=>{r(),l(!0),c=k(e.hash),s=i("pageview",{referrer:s?"":R(document.referrer),title:e.title?document.title:void 0,screen:[screen.width,screen.height],language:navigator.language,not_found:p&&p.notFound||!s&&e.notFound||void 0})},d=(p,f)=>{let m=N(p,t);m?i("event",{name:m,props:P(f,t)}):t("no event name")},u=(p,f)=>{let m=X(p,t);m&&i("identify",{user_id:n=m,traits:P(f,t)})};return V(e,d),e.autoPageviews&&(H(g(()=>k(e.hash)!=c&&a())),a()),{track:d,identify:u,reset:()=>n="",pageview:a}}var E=!1,v,A=[],y=e=>g((...t)=>{v?v[e](...t):!E&&A.length<100&&A.push([e,t])}),G=g(e=>{if(typeof document>"u")return;let t=S(e||{}),o=M(t.debug);if(E)return o("init twice");if(E=!0,!t.key)return o("bad key: "+(e&&e.project));let n=I(t.localhost);n&&!t.debug||(n&&o("off: "+n),v=W(t,o),A.forEach(([s,c])=>v[s](...c)))}),j=y("track"),z=y("identify"),Y=y("reset"),$=y("pageview");
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var A="utm_source,utm_medium,utm_campaign,utm_term,utm_content,ref,gclid,fbclid,msclkid,li_fat_id,q,query,search,s".split(",");function _(e){return e.split("?")[0]}function C(e,t,o){let n=new URL(e);return n.search=""+new URLSearchParams([...n.searchParams].filter(([a])=>t.includes(a))),n.hash=o?_(n.hash):"",n.href}function L(e){let t=e?new URL(e):location;return t.hostname==location.hostname?"":t.origin+t.pathname}function x(e){return location.pathname+(e?_(location.hash):"")}function k(e){return(""+(e||"")).match(/[^\s,]+/g)||[]}var W=k("pdf,zip,rar,7z,dmg,apk,exe,msi,doc,docx,xls,xlsx,pptx,csv,mp4,mov,mp3"),R=(e,t)=>e==null?!!t:e!==!1&&e!="false";function O(e){let t=(""+(e.project||"")).trim(),o=/^pk_(live|test)_([a-z]{2})_[a-z\d]+$/.exec(t),n=k(e.downloadExtensions),a={key:o?t:"",endpoint:e.api||"https://"+(o&&o[2])+".e.vk.viabio.me/v1/events",params:A.concat(k(e.params)),extensions:n.length?n:W},c=a,s=e;return"title hash notFound debug localhost".split(" ").forEach(r=>c[r]=R(s[r])),"outbound downloads autoPageviews".split(" ").forEach(r=>c[r]=R(s[r],!0)),a}function S(e){return(t,o)=>e&&console.log("[viakite] "+t,o??"")}var M="viakite_ignore";function D(e){let t=!1;try{t=localStorage.getItem(M)=="true"}catch{}let o=/^(localhost|127\.[\d.]+|\[::1\])$|\.localhost$/.test(location.hostname)||location.protocol=="file:";return navigator.webdriver?"webdriver":t?M:o&&!e?"localhost":""}function g(e){return(...t)=>{try{e(...t)}catch{}}}function h(e,t,o,n){let a=Array.from(e);return a.length>t&&n(o+" cut to "+t),a.slice(0,t).join("")}function I(e,t){return h((""+(e||"")).trim(),120,"name",t)}function G(e){return/[\w.%+-]+@[\w.-]+\.[a-z]{2,}/i.test(e)||/\d{7}/.test(e.replace(/[\s().-]/g,""))}function N(e,t){let o=(""+(e||"")).trim(),n=G(o);return n&&t("user id looks personal; dropped"),n?"":h(o,120,"user id",t)}function b(e,t){let o={},n=e&&typeof e=="object"?e:{},a=0;for(let c in n){let s=n[c],r=typeof s,l=c=="revenue",i=l||c=="currency";(i?l?r=="number":/^[a-z]{3}$/i.test(s):/^[\w.-]+$/.test(c)&&(s===null||/^(nu|st|bo)/.test(r))&&a++<20)?i?o[c]=l?s:s.toUpperCase():o[h(c,40,c,t)]=r=="string"?h(s,255,c,t):s:s!==void 0&&t(c+": dropped")}return o}var j=[1e3,5e3,15e3];function X(e,t,o){let n=[],a=r=>(r.sent=Date.now(),fetch(e,{method:"POST",body:JSON.stringify(r),keepalive:!0})),c=(r,l)=>navigator.onLine?a(r).then(i=>i.status>499||i.status==429?s(r,l,i.status):i.ok||t("refused: "+i.status),i=>s(r,l,i)):n.push(r),s=(r,l,i)=>l<3?setTimeout(()=>c(r,l+1),j[l]):t("not sent: "+i);return addEventListener("online",()=>n.splice(0).forEach(r=>c(r,0))),(r,l)=>{o?t("send",r):l?(r.sent=Date.now(),navigator.sendBeacon&&navigator.sendBeacon(e,JSON.stringify(r))||a(r).catch(()=>0)):c(r,0)}}var z="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function U(){let e=Date.now(),t=crypto.getRandomValues(new Uint8Array(16)),o="";for(let n=0;n<26;n++)o+=z[n<10?Math.floor(e/2**(45-5*n))%32:t[n-10]%32];return o}function T(e,t){let o=g(n=>{let a=n.target,c=a.closest('[class*="viakite-event-name="]'),s=a.closest("a[href]"),r={};if(n.button>1||(c&&(c.getAttribute("class").replace(/viakite-event-([\w.-]+)=(\S+)/g,(d,u,p)=>r[u]=p.replace(/\+/g," ")),t(r.name,{...r,name:void 0})),!s||!/^http/.test(s.protocol)))return;let l={url:s.origin+s.pathname},i=/\.(\w+)$/.exec(s.pathname);e.downloads&&i&&e.extensions.includes(i[1].toLowerCase())?t("File download",l):e.outbound&&s.hostname!=location.hostname&&t("Outbound link",l)});addEventListener("click",o,!0),addEventListener("auxclick",o,!0)}function V(e){let t=0,o=0,n=0,a=0,c=0,s=0,r=()=>{let i=(scrollY+innerHeight)/document.documentElement.scrollHeight*100||0;n=Math.max(n,i>98?100:i-i%25)},l=()=>{let i=Date.now(),d=[].some.call(document.querySelectorAll("video,audio"),u=>!u.paused);if(!document.hidden&&(i-c<3e4||d)){let u=Math.min(i-s,18e5-t);t+=u,o+=u}s=i};return setInterval(l,1e3),"mousemove mousedown keydown touchstart scroll".split(" ").forEach(i=>addEventListener(i,d=>{c=Date.now(),d.type=="scroll"&&r()},!0)),addEventListener("visibilitychange",()=>document.hidden?e():c=s=Date.now(),!0),addEventListener("pagehide",e),i=>{if(i){t=o=n=a=0,c=s=Date.now();return}l(),o>999&&r();let d=n>a?n:0;if(o<1e3&&d<25)return;let u={engaged_ms:o,scroll:d};return o=0,a=n,u}}function F(e){["pushState","replaceState"].forEach(t=>{let o=history[t];history[t]=function(...n){o.apply(this,n),e()}}),addEventListener("popstate",e)}function H(e,t){let o=X(e.endpoint,t,e.debug),n="",a,c="",s=(p,f,m)=>{let w={type:p,id:U(),project:e.key,url:C(location.href,e.params,e.hash),ts:Date.now()};return n&&(w.user_id=n),o(Object.assign(w,f),m),w},r=g(()=>{let p=a&&l();a&&p&&s("engagement",{url:a.url,pageview_id:a.id,...p},!0)}),l=V(r),i=p=>{r(),l(!0),c=x(e.hash),a=s("pageview",{referrer:a?"":L(document.referrer),title:e.title?document.title:void 0,screen:[screen.width,screen.height],language:navigator.language,not_found:p&&p.notFound||!a&&e.notFound||void 0})},d=(p,f)=>{let m=I(p,t);m?s("event",{name:m,props:b(f,t)}):t("no event name")},u=(p,f)=>{let m=N(p,t);m&&s("identify",{user_id:n=m,traits:b(f,t)})};return T(e,d),e.autoPageviews&&(F(g(()=>x(e.hash)!=c&&i())),i()),{track:d,identify:u,reset:()=>n="",pageview:i}}var P=!1,v,E=[],y=e=>g((...t)=>{v?v[e](...t):!P&&E.length<100&&E.push([e,t])}),Y=g(e=>{if(typeof document>"u")return;let t=O(e||{}),o=S(t.debug);if(P)return o("init twice");if(P=!0,!t.key)return o("bad key: "+(e&&e.project));let n=D(t.localhost);n&&!t.debug||(n&&o("off: "+n),v=H(t,o),E.forEach(([a,c])=>v[a](...c)))}),$=y("track"),K=y("identify"),B=y("reset"),q=y("pageview");export{K as identify,Y as init,q as pageview,B as reset,$ as track};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Query, Report, ShareOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* PublicError is an error answer of the public API: its HTTP status and
|
|
4
|
+
* code, such as 403 `not_shared`, 403 `stats_paused` or 410 `share_expired`.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PublicError extends Error {
|
|
7
|
+
readonly status: number;
|
|
8
|
+
readonly code: string;
|
|
9
|
+
constructor(status: number, code: string, message: string);
|
|
10
|
+
}
|
|
11
|
+
/** apiBase is the public API's address: `api`, else `https://<region>.api.<DOMAIN>`. */
|
|
12
|
+
export declare function apiBase(o: ShareOptions): string;
|
|
13
|
+
/** liveUrl is the share's public live socket (G2): `live`, else `wss://<region>.live.<DOMAIN>`. */
|
|
14
|
+
export declare function liveUrl(o: ShareOptions): string;
|
|
15
|
+
/**
|
|
16
|
+
* publicQuery runs a report through the public query (H10): no cookie, from
|
|
17
|
+
* any site, limited to what the share allows. Answers may be a minute old.
|
|
18
|
+
*/
|
|
19
|
+
export declare function publicQuery(o: ShareOptions, q: Query, signal?: AbortSignal): Promise<Report>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Realtime, ShareOptions } from "./types";
|
|
2
|
+
/** LiveStatus is the socket's state: connecting, open, or down and waiting to retry. */
|
|
3
|
+
export type LiveStatus = "connecting" | "open" | "retrying";
|
|
4
|
+
/** LiveHandlers receive the `realtime` pushes and the socket's state. */
|
|
5
|
+
export interface LiveHandlers {
|
|
6
|
+
onRealtime: (rt: Realtime) => void;
|
|
7
|
+
onStatus?: (s: LiveStatus) => void;
|
|
8
|
+
}
|
|
9
|
+
/** The longest wait between two tries, in milliseconds. */
|
|
10
|
+
export declare const MAX_RETRY_MS = 30000;
|
|
11
|
+
/**
|
|
12
|
+
* openLive follows a share's `realtime` stream over the public live socket
|
|
13
|
+
* (G2), which pushes every 2 seconds. It asks only for `realtime`, and
|
|
14
|
+
* reconnects after a drop, waiting 1 s and then twice as long each time, up
|
|
15
|
+
* to 30 s. It returns the function that closes it for good.
|
|
16
|
+
*/
|
|
17
|
+
export declare function openLive(o: ShareOptions, h: LiveHandlers): () => void;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** Where a share's data is read from. */
|
|
2
|
+
export interface ShareOptions {
|
|
3
|
+
/** A share token (`st_…`), or a public page's id, subdomain or verified custom domain. */
|
|
4
|
+
share: string;
|
|
5
|
+
/** The data region, `in` by default: the share's project lives there. */
|
|
6
|
+
region?: string;
|
|
7
|
+
/** The public API's address instead of `https://<region>.api.<domain>` (a proxy, or a local API). */
|
|
8
|
+
api?: string;
|
|
9
|
+
/** The live socket's address instead of `wss://<region>.live.<domain>`. */
|
|
10
|
+
live?: string;
|
|
11
|
+
}
|
|
12
|
+
/** A date preset of query.DateRange. */
|
|
13
|
+
export type DatePreset = "today" | "yesterday" | "7d" | "30d" | "90d" | "this_month" | "last_month" | "this_year" | "all";
|
|
14
|
+
/** query.DateRange: a preset, or `from` and `to` (dates, `to` included, or RFC 3339 times). */
|
|
15
|
+
export interface DateRange {
|
|
16
|
+
preset?: DatePreset;
|
|
17
|
+
from?: string;
|
|
18
|
+
to?: string;
|
|
19
|
+
}
|
|
20
|
+
/** query.DateRange as a comparison. */
|
|
21
|
+
export interface CompareRange {
|
|
22
|
+
preset?: "previous_period" | "previous_year";
|
|
23
|
+
from?: string;
|
|
24
|
+
to?: string;
|
|
25
|
+
}
|
|
26
|
+
/** A filter operator of query.Filter. */
|
|
27
|
+
export type FilterOperator = "is" | "is_not" | "contains" | "not_contains" | "starts_with" | "regex";
|
|
28
|
+
/** query.Filter: a dimension matching any of its values, or `or`, a list of such filters. */
|
|
29
|
+
export interface Filter {
|
|
30
|
+
dimension?: string;
|
|
31
|
+
operator?: FilterOperator;
|
|
32
|
+
values?: string[];
|
|
33
|
+
or?: Filter[];
|
|
34
|
+
}
|
|
35
|
+
/** A time step; `auto` picks it from the range's length. */
|
|
36
|
+
export type Granularity = "hour" | "day" | "week" | "month" | "auto";
|
|
37
|
+
/** query.Query, the body of the public query. */
|
|
38
|
+
export interface Query {
|
|
39
|
+
measures: string[];
|
|
40
|
+
breakdown?: string[];
|
|
41
|
+
filters?: Filter[];
|
|
42
|
+
date_range: DateRange;
|
|
43
|
+
granularity?: Granularity;
|
|
44
|
+
compare?: CompareRange;
|
|
45
|
+
limit?: number;
|
|
46
|
+
}
|
|
47
|
+
/** One result row: `time` with a time step, each breakdown dimension and each measure by name. */
|
|
48
|
+
export type ReportRow = Record<string, string | number>;
|
|
49
|
+
/** A resolved range [from, to) in UTC. */
|
|
50
|
+
export interface ResolvedRange {
|
|
51
|
+
from: string;
|
|
52
|
+
to: string;
|
|
53
|
+
}
|
|
54
|
+
/** reports.Report, the answer to one query. */
|
|
55
|
+
export interface Report {
|
|
56
|
+
data: ReportRow[];
|
|
57
|
+
compare?: ReportRow[];
|
|
58
|
+
date_range: ResolvedRange;
|
|
59
|
+
compare_range?: ResolvedRange;
|
|
60
|
+
granularity?: "hour" | "day" | "week" | "month";
|
|
61
|
+
}
|
|
62
|
+
/** A value and its visitors. */
|
|
63
|
+
export interface DimensionValue {
|
|
64
|
+
value: string;
|
|
65
|
+
visitors: number;
|
|
66
|
+
}
|
|
67
|
+
/** reports.Realtime, the `realtime` stream's data. */
|
|
68
|
+
export interface Realtime {
|
|
69
|
+
online_now: number;
|
|
70
|
+
visitors_per_minute: {
|
|
71
|
+
minute: string;
|
|
72
|
+
visitors: number;
|
|
73
|
+
}[];
|
|
74
|
+
pages: DimensionValue[];
|
|
75
|
+
countries: DimensionValue[];
|
|
76
|
+
at: string;
|
|
77
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Options } from "../index";
|
|
2
|
+
/** Props of <Analytics />: the same options as `init` and the script tag's attributes. */
|
|
3
|
+
export type AnalyticsProps = Options;
|
|
4
|
+
/**
|
|
5
|
+
* Analytics starts Viakite Analytics once, in the browser, and renders
|
|
6
|
+
* nothing. Put it once in the root layout (Next.js App Router), in
|
|
7
|
+
* `pages/_app.tsx` (Pages Router) or at the top of the app (React). It is a
|
|
8
|
+
* client component, so server layouts can render it. Page changes in a
|
|
9
|
+
* single-page app are followed through the browser's history, which every
|
|
10
|
+
* React router uses.
|
|
11
|
+
*/
|
|
12
|
+
export declare function Analytics(props: AnalyticsProps): null;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ReportRow, ResolvedRange } from "../public/types";
|
|
2
|
+
/** Props of <Chart />. */
|
|
3
|
+
export interface ChartProps {
|
|
4
|
+
/** The measure over time, `visitors` by default. */
|
|
5
|
+
metric?: string;
|
|
6
|
+
/** The time step; picked from the range's length by default. */
|
|
7
|
+
granularity?: "hour" | "day" | "week" | "month" | "auto";
|
|
8
|
+
/** The drawing's width and height in SVG units; it stretches to its box. */
|
|
9
|
+
width?: number;
|
|
10
|
+
height?: number;
|
|
11
|
+
/** The chart's name for screen readers. */
|
|
12
|
+
label?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* points places each row of a series on the drawing: across by its time
|
|
17
|
+
* within the range (so missing steps leave a gap in time, not a squeeze) and
|
|
18
|
+
* up by its value against the highest value shown.
|
|
19
|
+
*/
|
|
20
|
+
export declare function points(rows: ReportRow[], range: ResolvedRange, metric: string, max: number, w: number, h: number): string;
|
|
21
|
+
/**
|
|
22
|
+
* Chart draws a measure over time for the provider's range as an SVG line,
|
|
23
|
+
* with the period before as a second line when <Compare /> is on. It has no
|
|
24
|
+
* colours of its own: the line is `currentColor`, and the classes
|
|
25
|
+
* `vk-chart`, `vk-chart-line` and `vk-chart-compare` are there to style it.
|
|
26
|
+
* The share must allow the Overview report.
|
|
27
|
+
*/
|
|
28
|
+
export declare function Chart({ metric, granularity, width, height, label, className }: ChartProps): import("react").ReactSVGElement;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Props of <Compare />. */
|
|
2
|
+
export interface CompareProps {
|
|
3
|
+
/** The checkbox's text, "Compare to previous period" by default. */
|
|
4
|
+
label?: string;
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Compare is a checkbox (`<label class="vk-compare">`) that turns the
|
|
9
|
+
* comparison with the period before on and off for every component in the
|
|
10
|
+
* same <ViakiteProvider>: <VisitorCount /> adds the change, <Chart /> a
|
|
11
|
+
* second line.
|
|
12
|
+
*/
|
|
13
|
+
export declare function Compare({ label, className }: CompareProps): import("react").DetailedReactHTMLElement<{
|
|
14
|
+
className: string;
|
|
15
|
+
}, HTMLElement>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DatePreset } from "../public/types";
|
|
2
|
+
/** The presets the picker offers by default. */
|
|
3
|
+
export declare const DEFAULT_PRESETS: DatePreset[];
|
|
4
|
+
/** The English names of the presets. */
|
|
5
|
+
export declare const PRESET_LABELS: Record<DatePreset, string>;
|
|
6
|
+
/** Props of <DateRangePicker />. */
|
|
7
|
+
export interface DateRangePickerProps {
|
|
8
|
+
/** The presets to offer, in order. */
|
|
9
|
+
presets?: DatePreset[];
|
|
10
|
+
/** Names for the presets, such as another language's. */
|
|
11
|
+
labels?: Partial<Record<DatePreset, string>>;
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* DateRangePicker is a `<select class="vk-range">` of date presets that sets
|
|
16
|
+
* the range of every component in the same <ViakiteProvider>. Days are the
|
|
17
|
+
* project's days, in its time zone.
|
|
18
|
+
*/
|
|
19
|
+
export declare function DateRangePicker({ presets, labels, className }: DateRangePickerProps): import("react").ReactElement<{
|
|
20
|
+
className: string;
|
|
21
|
+
value: string;
|
|
22
|
+
"aria-label": string;
|
|
23
|
+
onChange: (e: {
|
|
24
|
+
target: {
|
|
25
|
+
value: string;
|
|
26
|
+
};
|
|
27
|
+
}) => void;
|
|
28
|
+
}, string | import("react").JSXElementConstructor<any>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Props of <LiveVisitors />. */
|
|
2
|
+
export interface LiveVisitorsProps {
|
|
3
|
+
locale?: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* LiveVisitors shows how many people are on the site now (visitors with any
|
|
8
|
+
* event in the last 5 minutes), updated every 2 seconds over the public
|
|
9
|
+
* live socket. The share must allow the Realtime report and have no
|
|
10
|
+
* password. It renders `<span class="vk-live">` with `data-state`:
|
|
11
|
+
* `loading` until the first number, then `ready`, or `retrying` while the
|
|
12
|
+
* socket reconnects (the last number stays).
|
|
13
|
+
*/
|
|
14
|
+
export declare function LiveVisitors({ locale, className }: LiveVisitorsProps): import("react").DetailedReactHTMLElement<{
|
|
15
|
+
className: string;
|
|
16
|
+
"data-state": string;
|
|
17
|
+
}, HTMLElement>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Props of <TopList /> and of the lists built on it. */
|
|
2
|
+
export interface TopListProps {
|
|
3
|
+
/** The dimension to rank, such as `page`, `source` or `country`; the share must allow it. */
|
|
4
|
+
dimension: string;
|
|
5
|
+
/** The measure to rank by, `visitors` by default. */
|
|
6
|
+
metric?: string;
|
|
7
|
+
/** How many rows, 10 by default (up to 10,000). */
|
|
8
|
+
limit?: number;
|
|
9
|
+
/** What a row with no value says, "(none)" by default. */
|
|
10
|
+
emptyLabel?: string;
|
|
11
|
+
locale?: string;
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* TopList ranks a dimension's values for the provider's range, highest
|
|
16
|
+
* first. It renders `<ol class="vk-top">`; each `<li>` holds the value
|
|
17
|
+
* (`.vk-top-label`) and its number (`.vk-top-value`), and sets `--vk-share`
|
|
18
|
+
* to its number against the first row's (0 to 1), for drawing bars in CSS.
|
|
19
|
+
*/
|
|
20
|
+
export declare function TopList(props: TopListProps): import("react").DetailedReactHTMLElement<{
|
|
21
|
+
className: string;
|
|
22
|
+
"data-state": "error" | "loading" | "ready";
|
|
23
|
+
"data-error": string | undefined;
|
|
24
|
+
"data-dimension": string;
|
|
25
|
+
}, HTMLElement>;
|
|
26
|
+
/** Props of the ready-made lists: a <TopList /> with its dimension set. */
|
|
27
|
+
export type ReadyListProps = Omit<TopListProps, "dimension">;
|
|
28
|
+
/** TopPages ranks pages by path (the `page` dimension); the share must allow the Pages report. */
|
|
29
|
+
export declare function TopPages(props: ReadyListProps): import("react").FunctionComponentElement<TopListProps>;
|
|
30
|
+
/** TopSources ranks where visitors came from (the `source` dimension); the share must allow the Sources report. */
|
|
31
|
+
export declare function TopSources(props: ReadyListProps): import("react").FunctionComponentElement<TopListProps>;
|
|
32
|
+
/** Countries ranks visitors' countries (the `country` dimension, ISO codes); the share must allow the Locations report. */
|
|
33
|
+
export declare function Countries(props: ReadyListProps): import("react").FunctionComponentElement<TopListProps>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { DateRange, Filter, Report, ShareOptions } from "../public/types";
|
|
3
|
+
/** Props of <ViakiteProvider />. */
|
|
4
|
+
export interface ViakiteProviderProps extends ShareOptions {
|
|
5
|
+
/** The range shown first, the last 30 days by default. <DateRangePicker /> changes it. */
|
|
6
|
+
dateRange?: DateRange;
|
|
7
|
+
/** Whether to compare with the period before at first. <Compare /> changes it. */
|
|
8
|
+
compare?: boolean;
|
|
9
|
+
/** Filters every component inside applies; only dimensions the share allows. */
|
|
10
|
+
filters?: Filter[];
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
/** ViakiteContext is what the components inside a provider share. */
|
|
14
|
+
export interface ViakiteContext {
|
|
15
|
+
share: ShareOptions;
|
|
16
|
+
range: DateRange;
|
|
17
|
+
setRange: (r: DateRange) => void;
|
|
18
|
+
compare: boolean;
|
|
19
|
+
setCompare: (on: boolean) => void;
|
|
20
|
+
filters: Filter[];
|
|
21
|
+
/** The answers already asked for, by share and query, kept 60 s: components asking the same question share one request. */
|
|
22
|
+
cache: Map<string, {
|
|
23
|
+
at: number;
|
|
24
|
+
report: Promise<Report>;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* ViakiteProvider holds the share every Viakite component inside it reads
|
|
29
|
+
* (a share token, `st_…`, or a public page) and the date range and
|
|
30
|
+
* comparison they all show, so <DateRangePicker /> and <Compare /> change
|
|
31
|
+
* every component at once.
|
|
32
|
+
*/
|
|
33
|
+
export declare function ViakiteProvider(props: ViakiteProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<ViakiteContext | null>>;
|
|
34
|
+
/** useViakite is the provider's context; it throws outside a <ViakiteProvider>. */
|
|
35
|
+
export declare function useViakite(): ViakiteContext;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Props of <VisitorCount />. */
|
|
2
|
+
export interface VisitorCountProps {
|
|
3
|
+
/** The measure to count, `visitors` by default: `visits`, `pageviews`, … */
|
|
4
|
+
metric?: string;
|
|
5
|
+
/** The locale numbers are written in; the browser's by default. */
|
|
6
|
+
locale?: string;
|
|
7
|
+
className?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* VisitorCount shows one total for the provider's range: unique visitors by
|
|
11
|
+
* default. With <Compare /> on, it adds the change against the period
|
|
12
|
+
* before. It renders `<span class="vk-count">` with `data-state` (`loading`,
|
|
13
|
+
* `ready`, `error`) and, on an error, `data-error` (the API's code).
|
|
14
|
+
*/
|
|
15
|
+
export declare function VisitorCount({ metric, locale, className }: VisitorCountProps): import("react").DetailedReactHTMLElement<{
|
|
16
|
+
className: string;
|
|
17
|
+
"data-state": "error" | "loading" | "ready";
|
|
18
|
+
"data-error": string | undefined;
|
|
19
|
+
}, HTMLElement>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** formatNumber writes a number for people, in the given locale or the browser's. */
|
|
2
|
+
export declare function formatNumber(n: number, locale?: string): string;
|
|
3
|
+
/** Trend says which way a number moved against the period before. */
|
|
4
|
+
export type Trend = "up" | "down" | "flat";
|
|
5
|
+
/**
|
|
6
|
+
* change is how much a number moved against the period before, as a whole
|
|
7
|
+
* percent ("+12%"), with its trend; null when there was nothing before.
|
|
8
|
+
*/
|
|
9
|
+
export declare function change(now: number, before: number): {
|
|
10
|
+
text: string;
|
|
11
|
+
trend: Trend;
|
|
12
|
+
} | null;
|
|
13
|
+
/** num reads a measure from a report row: 0 when it is missing. */
|
|
14
|
+
export declare function num(row: Record<string, string | number> | undefined, key: string): number;
|
|
15
|
+
/** cx joins class names, skipping empty ones. */
|
|
16
|
+
export declare function cx(...names: (string | undefined | false)[]): string;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";var w=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var ee=Object.prototype.hasOwnProperty;var te=(e,t)=>{for(var r in t)w(e,r,{get:t[r],enumerable:!0})},re=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Z(t))!ee.call(e,n)&&n!==r&&w(e,n,{get:()=>t[n],enumerable:!(o=K(t,n))||o.enumerable});return e};var oe=e=>re(w({},"__esModule",{value:!0}),e);var fe={};te(fe,{Analytics:()=>_,Chart:()=>H,Compare:()=>G,Countries:()=>X,DateRangePicker:()=>z,LiveVisitors:()=>B,PublicError:()=>R,TopList:()=>b,TopPages:()=>$,TopSources:()=>Y,ViakiteProvider:()=>M,VisitorCount:()=>U,useReport:()=>h,useViakite:()=>d});module.exports=oe(fe);var T=require("react"),O=require("../index.cjs");function _(e){return(0,T.useEffect)(()=>{(0,O.init)(e)},[]),null}var m=require("react"),A=(0,m.createContext)(null);function M(e){let{share:t,region:r,api:o,live:n,children:s}=e,[a,i]=(0,m.useState)(e.dateRange||{preset:"30d"}),[p,c]=(0,m.useState)(!!e.compare),u=(0,m.useRef)(new Map).current,l=JSON.stringify(e.filters||[]),g=(0,m.useMemo)(()=>({share:{share:t,region:r,api:o,live:n},range:a,setRange:i,compare:p,setCompare:c,filters:JSON.parse(l),cache:u}),[t,r,o,n,a,p,l,u]);return(0,m.createElement)(A.Provider,{value:g},s)}function d(){let e=(0,m.useContext)(A);if(!e)throw new Error("Viakite components must be inside a <ViakiteProvider>");return e}var C=require("react");var R=class extends Error{constructor(t,r,o){super(o),this.name="PublicError",this.status=t,this.code=r}},Q=e=>e.region||"us",F=e=>e.replace(/\/+$/,"");function ne(e){return F(e.api||"https://"+Q(e)+".api.vk.viabio.me")}function J(e){return F(e.live||"wss://"+Q(e)+".live.vk.viabio.me")+"/v1/live/public/"+encodeURIComponent(e.share)}async function q(e,t,r){let o=await fetch(ne(e)+"/v1/public/"+encodeURIComponent(e.share)+"/query",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),credentials:"omit",signal:r}),n=await o.json().catch(()=>null);if(!o.ok){let s=n?.error;throw new R(o.status,s?.code||"http_"+o.status,s?.message||o.statusText)}return n}var se=6e4;function ae(e,t){let r={...t,date_range:e.range};return e.filters.length&&(r.filters=e.filters),e.compare&&(r.compare={preset:"previous_period"}),r}function ie(e,t){let r=JSON.stringify([e.share,t]),o=Date.now(),n=e.cache.get(r);if(n&&o-n.at<se)return n.report;let s=q(e.share,t);return e.cache.set(r,{at:o,report:s}),s.catch(()=>e.cache.delete(r)),s}var pe=e=>e instanceof R?e:new R(0,"network_error",e instanceof Error?e.message:String(e));function h(e){let t=d(),r=ae(t,e),o=JSON.stringify([t.share,r]),[n,s]=(0,C.useState)({state:"loading"});return(0,C.useEffect)(()=>{let a=!0;return ie(t,r).then(i=>a&&s({state:"ready",report:i}),i=>a&&s({state:"error",error:pe(i)})),()=>{a=!1}},[o]),n}var k=require("react");function P(e,t){return new Intl.NumberFormat(t,{maximumFractionDigits:e<10?1:0}).format(e)}function I(e,t){if(!t)return null;let r=Math.round((e-t)/t*100),o=r>0?"up":r<0?"down":"flat";return{text:(r>0?"+":"")+r+"%",trend:o}}function y(e,t){let r=e?e[t]:void 0;return typeof r=="number"?r:Number(r)||0}function f(...e){return e.filter(Boolean).join(" ")}function U({metric:e="visitors",locale:t,className:r}){let o=h({measures:[e]}),n={className:f("vk-count",r),"data-state":o.state,"data-error":o.error?.code};if(o.state!=="ready")return(0,k.createElement)("span",n);let s=y(o.report.data[0],e),a=o.report.compare?I(s,y(o.report.compare[0],e)):null;return(0,k.createElement)("span",n,(0,k.createElement)("span",{className:"vk-value"},P(s,t)),a&&(0,k.createElement)("span",{className:"vk-change","data-trend":a.trend},a.text))}var v=require("react");var ce=3e4;function j(e,t){let r=null,o,n=1e3,s=!1,a=()=>{t.onStatus?.("connecting");let i=new WebSocket(J(e));r=i,i.onopen=()=>{n=1e3,t.onStatus?.("open"),i.send(JSON.stringify({type:"subscribe",streams:["realtime"]}))},i.onmessage=p=>{try{let c=JSON.parse(String(p.data));c.stream==="realtime"&&c.data&&t.onRealtime(c.data)}catch{}},i.onclose=()=>{s||(t.onStatus?.("retrying"),o=setTimeout(a,n),n=Math.min(n*2,ce))}};return a(),()=>{s=!0,clearTimeout(o),r?.close()}}function B({locale:e,className:t}){let{share:r}=d(),[o,n]=(0,v.useState)(null),[s,a]=(0,v.useState)("connecting"),{share:i,region:p,api:c,live:u}=r;(0,v.useEffect)(()=>{if(!(typeof WebSocket>"u"))return j({share:i,region:p,api:c,live:u},{onRealtime:g=>n(g.online_now),onStatus:a})},[i,p,c,u]);let l=s==="retrying"?"retrying":o===null?"loading":"ready";return(0,v.createElement)("span",{className:f("vk-live",t),"data-state":l},o===null?null:P(o,e))}var L=require("react");var W=2;function me(e,t,r,o,n,s){let a=Date.parse(t.from),i=Date.parse(t.to)-a||1;return e.map(p=>{let c=(Date.parse(String(p.time))-a)/i*n,u=s-W-(o?y(p,r)/o*(s-2*W):0);return c.toFixed(1)+","+u.toFixed(1)}).join(" ")}function H({metric:e="visitors",granularity:t="auto",width:r=600,height:o=160,label:n,className:s}){let a=h({measures:[e],granularity:t}),i={className:f("vk-chart",s),"data-state":a.state,"data-error":a.error?.code,viewBox:`0 0 ${r} ${o}`,preserveAspectRatio:"none",role:"img","aria-label":n||e+" over time"};if(a.state!=="ready")return(0,L.createElement)("svg",i);let p=a.report,c=p.data.concat(p.compare||[]),u=Math.max(...c.map(g=>y(g,e)),0),l=(g,S,V,D)=>(0,L.createElement)("polyline",{className:V,points:me(g,S,e,u,r,o),fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeDasharray:D?"4 3":void 0,vectorEffect:"non-scaling-stroke"});return(0,L.createElement)("svg",i,p.compare&&p.compare_range&&l(p.compare,p.compare_range,"vk-chart-compare",!0),l(p.data,p.date_range,"vk-chart-line",!1))}var x=require("react");function b(e){let{dimension:t,metric:r="visitors",limit:o=10,emptyLabel:n="(none)",locale:s,className:a}=e,i=h({measures:[r],breakdown:[t],limit:o}),p={className:f("vk-top",a),"data-state":i.state,"data-error":i.error?.code,"data-dimension":t};if(i.state!=="ready")return(0,x.createElement)("ol",p);let c=i.report.data,u=Math.max(...c.map(l=>y(l,r)),0);return(0,x.createElement)("ol",p,c.map((l,g)=>{let S=y(l,r),V=String(l[t]??"")||n,D={"--vk-share":u?S/u:0};return(0,x.createElement)("li",{key:g,style:D},(0,x.createElement)("span",{className:"vk-top-label"},V),(0,x.createElement)("span",{className:"vk-top-value"},P(S,s)))}))}function $(e){return(0,x.createElement)(b,{...e,dimension:"page"})}function Y(e){return(0,x.createElement)(b,{...e,dimension:"source"})}function X(e){return(0,x.createElement)(b,{...e,dimension:"country"})}var N=require("react");var ue=["today","7d","30d","90d","this_month","last_month","this_year"],le={today:"Today",yesterday:"Yesterday","7d":"Last 7 days","30d":"Last 30 days","90d":"Last 90 days",this_month:"This month",last_month:"Last month",this_year:"This year",all:"All time"};function z({presets:e=ue,labels:t,className:r}){let{range:o,setRange:n}=d();return(0,N.createElement)("select",{className:f("vk-range",r),value:o.preset||"","aria-label":"Date range",onChange:s=>n({preset:s.target.value})},!o.preset&&(0,N.createElement)("option",{value:"",disabled:!0},"Custom"),e.map(s=>(0,N.createElement)("option",{key:s,value:s},t?.[s]||le[s])))}var E=require("react");function G({label:e="Compare to previous period",className:t}){let{compare:r,setCompare:o}=d();return(0,E.createElement)("label",{className:f("vk-compare",t)},(0,E.createElement)("input",{type:"checkbox",checked:r,onChange:n=>o(n.target.checked)})," "+e)}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { Analytics } from "./Analytics";
|
|
2
|
+
export type { AnalyticsProps } from "./Analytics";
|
|
3
|
+
export { ViakiteProvider, useViakite } from "./ViakiteProvider";
|
|
4
|
+
export type { ViakiteProviderProps, ViakiteContext } from "./ViakiteProvider";
|
|
5
|
+
export { useReport } from "./useReport";
|
|
6
|
+
export type { ReportRequest, ReportState } from "./useReport";
|
|
7
|
+
export { VisitorCount } from "./VisitorCount";
|
|
8
|
+
export type { VisitorCountProps } from "./VisitorCount";
|
|
9
|
+
export { LiveVisitors } from "./LiveVisitors";
|
|
10
|
+
export type { LiveVisitorsProps } from "./LiveVisitors";
|
|
11
|
+
export { Chart } from "./Chart";
|
|
12
|
+
export type { ChartProps } from "./Chart";
|
|
13
|
+
export { TopList, TopPages, TopSources, Countries } from "./TopList";
|
|
14
|
+
export type { TopListProps, ReadyListProps } from "./TopList";
|
|
15
|
+
export { DateRangePicker } from "./DateRangePicker";
|
|
16
|
+
export type { DateRangePickerProps } from "./DateRangePicker";
|
|
17
|
+
export { Compare } from "./Compare";
|
|
18
|
+
export type { CompareProps } from "./Compare";
|
|
19
|
+
export { PublicError } from "../public/client";
|
|
20
|
+
export type { DateRange, DatePreset, Filter, Query, Report, ReportRow, Realtime } from "../public/types";
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import{useEffect as F}from"react";import{init as J}from"../index.js";function q(e){return F(()=>{J(e)},[]),null}import{createContext as I,createElement as U,useContext as j,useMemo as B,useRef as W,useState as N}from"react";var V=I(null);function H(e){let{share:t,region:r,api:o,live:s,children:n}=e,[a,i]=N(e.dateRange||{preset:"30d"}),[p,c]=N(!!e.compare),m=W(new Map).current,u=JSON.stringify(e.filters||[]),f=B(()=>({share:{share:t,region:r,api:o,live:s},range:a,setRange:i,compare:p,setCompare:c,filters:JSON.parse(u),cache:m}),[t,r,o,s,a,p,u,m]);return U(V.Provider,{value:f},n)}function d(){let e=j(V);if(!e)throw new Error("Viakite components must be inside a <ViakiteProvider>");return e}import{useEffect as Y,useState as X}from"react";var x=class extends Error{constructor(t,r,o){super(o),this.name="PublicError",this.status=t,this.code=r}},D=e=>e.region||"us",w=e=>e.replace(/\/+$/,"");function $(e){return w(e.api||"https://"+D(e)+".api.vk.viabio.me")}function E(e){return w(e.live||"wss://"+D(e)+".live.vk.viabio.me")+"/v1/live/public/"+encodeURIComponent(e.share)}async function T(e,t,r){let o=await fetch($(e)+"/v1/public/"+encodeURIComponent(e.share)+"/query",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),credentials:"omit",signal:r}),s=await o.json().catch(()=>null);if(!o.ok){let n=s?.error;throw new x(o.status,n?.code||"http_"+o.status,n?.message||o.statusText)}return s}var z=6e4;function G(e,t){let r={...t,date_range:e.range};return e.filters.length&&(r.filters=e.filters),e.compare&&(r.compare={preset:"previous_period"}),r}function K(e,t){let r=JSON.stringify([e.share,t]),o=Date.now(),s=e.cache.get(r);if(s&&o-s.at<z)return s.report;let n=T(e.share,t);return e.cache.set(r,{at:o,report:n}),n.catch(()=>e.cache.delete(r)),n}var Z=e=>e instanceof x?e:new x(0,"network_error",e instanceof Error?e.message:String(e));function R(e){let t=d(),r=G(t,e),o=JSON.stringify([t.share,r]),[s,n]=X({state:"loading"});return Y(()=>{let a=!0;return K(t,r).then(i=>a&&n({state:"ready",report:i}),i=>a&&n({state:"error",error:Z(i)})),()=>{a=!1}},[o]),s}import{createElement as P}from"react";function h(e,t){return new Intl.NumberFormat(t,{maximumFractionDigits:e<10?1:0}).format(e)}function O(e,t){if(!t)return null;let r=Math.round((e-t)/t*100),o=r>0?"up":r<0?"down":"flat";return{text:(r>0?"+":"")+r+"%",trend:o}}function g(e,t){let r=e?e[t]:void 0;return typeof r=="number"?r:Number(r)||0}function l(...e){return e.filter(Boolean).join(" ")}function ee({metric:e="visitors",locale:t,className:r}){let o=R({measures:[e]}),s={className:l("vk-count",r),"data-state":o.state,"data-error":o.error?.code};if(o.state!=="ready")return P("span",s);let n=g(o.report.data[0],e),a=o.report.compare?O(n,g(o.report.compare[0],e)):null;return P("span",s,P("span",{className:"vk-value"},h(n,t)),a&&P("span",{className:"vk-change","data-trend":a.trend},a.text))}import{createElement as re,useEffect as oe,useState as A}from"react";var te=3e4;function _(e,t){let r=null,o,s=1e3,n=!1,a=()=>{t.onStatus?.("connecting");let i=new WebSocket(E(e));r=i,i.onopen=()=>{s=1e3,t.onStatus?.("open"),i.send(JSON.stringify({type:"subscribe",streams:["realtime"]}))},i.onmessage=p=>{try{let c=JSON.parse(String(p.data));c.stream==="realtime"&&c.data&&t.onRealtime(c.data)}catch{}},i.onclose=()=>{n||(t.onStatus?.("retrying"),o=setTimeout(a,s),s=Math.min(s*2,te))}};return a(),()=>{n=!0,clearTimeout(o),r?.close()}}function ne({locale:e,className:t}){let{share:r}=d(),[o,s]=A(null),[n,a]=A("connecting"),{share:i,region:p,api:c,live:m}=r;oe(()=>{if(!(typeof WebSocket>"u"))return _({share:i,region:p,api:c,live:m},{onRealtime:f=>s(f.online_now),onStatus:a})},[i,p,c,m]);let u=n==="retrying"?"retrying":o===null?"loading":"ready";return re("span",{className:l("vk-live",t),"data-state":u},o===null?null:h(o,e))}import{createElement as C}from"react";var M=2;function se(e,t,r,o,s,n){let a=Date.parse(t.from),i=Date.parse(t.to)-a||1;return e.map(p=>{let c=(Date.parse(String(p.time))-a)/i*s,m=n-M-(o?g(p,r)/o*(n-2*M):0);return c.toFixed(1)+","+m.toFixed(1)}).join(" ")}function ae({metric:e="visitors",granularity:t="auto",width:r=600,height:o=160,label:s,className:n}){let a=R({measures:[e],granularity:t}),i={className:l("vk-chart",n),"data-state":a.state,"data-error":a.error?.code,viewBox:`0 0 ${r} ${o}`,preserveAspectRatio:"none",role:"img","aria-label":s||e+" over time"};if(a.state!=="ready")return C("svg",i);let p=a.report,c=p.data.concat(p.compare||[]),m=Math.max(...c.map(f=>g(f,e)),0),u=(f,v,b,S)=>C("polyline",{className:b,points:se(f,v,e,m,r,o),fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeDasharray:S?"4 3":void 0,vectorEffect:"non-scaling-stroke"});return C("svg",i,p.compare&&p.compare_range&&u(p.compare,p.compare_range,"vk-chart-compare",!0),u(p.data,p.date_range,"vk-chart-line",!1))}import{createElement as y}from"react";function k(e){let{dimension:t,metric:r="visitors",limit:o=10,emptyLabel:s="(none)",locale:n,className:a}=e,i=R({measures:[r],breakdown:[t],limit:o}),p={className:l("vk-top",a),"data-state":i.state,"data-error":i.error?.code,"data-dimension":t};if(i.state!=="ready")return y("ol",p);let c=i.report.data,m=Math.max(...c.map(u=>g(u,r)),0);return y("ol",p,c.map((u,f)=>{let v=g(u,r),b=String(u[t]??"")||s,S={"--vk-share":m?v/m:0};return y("li",{key:f,style:S},y("span",{className:"vk-top-label"},b),y("span",{className:"vk-top-value"},h(v,n)))}))}function ie(e){return y(k,{...e,dimension:"page"})}function pe(e){return y(k,{...e,dimension:"source"})}function ce(e){return y(k,{...e,dimension:"country"})}import{createElement as L}from"react";var me=["today","7d","30d","90d","this_month","last_month","this_year"],ue={today:"Today",yesterday:"Yesterday","7d":"Last 7 days","30d":"Last 30 days","90d":"Last 90 days",this_month:"This month",last_month:"Last month",this_year:"This year",all:"All time"};function le({presets:e=me,labels:t,className:r}){let{range:o,setRange:s}=d();return L("select",{className:l("vk-range",r),value:o.preset||"","aria-label":"Date range",onChange:n=>s({preset:n.target.value})},!o.preset&&L("option",{value:"",disabled:!0},"Custom"),e.map(n=>L("option",{key:n,value:n},t?.[n]||ue[n])))}import{createElement as Q}from"react";function fe({label:e="Compare to previous period",className:t}){let{compare:r,setCompare:o}=d();return Q("label",{className:l("vk-compare",t)},Q("input",{type:"checkbox",checked:r,onChange:s=>o(s.target.checked)})," "+e)}export{q as Analytics,ae as Chart,fe as Compare,ce as Countries,le as DateRangePicker,ne as LiveVisitors,x as PublicError,k as TopList,ie as TopPages,pe as TopSources,H as ViakiteProvider,ee as VisitorCount,R as useReport,d as useViakite};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PublicError } from "../public/client";
|
|
2
|
+
import type { Query, Report } from "../public/types";
|
|
3
|
+
import type { ViakiteContext } from "./ViakiteProvider";
|
|
4
|
+
/** What a component asks for; the provider adds the range, comparison and filters. */
|
|
5
|
+
export type ReportRequest = Omit<Query, "date_range" | "compare" | "filters">;
|
|
6
|
+
/** ReportState is a report as it loads: loading, ready with the report, or an error with its code. */
|
|
7
|
+
export type ReportState = {
|
|
8
|
+
state: "loading";
|
|
9
|
+
report?: undefined;
|
|
10
|
+
error?: undefined;
|
|
11
|
+
} | {
|
|
12
|
+
state: "ready";
|
|
13
|
+
report: Report;
|
|
14
|
+
error?: undefined;
|
|
15
|
+
} | {
|
|
16
|
+
state: "error";
|
|
17
|
+
report?: undefined;
|
|
18
|
+
error: PublicError;
|
|
19
|
+
};
|
|
20
|
+
/** How long an answer is reused: the public query keeps its answers 60 s too. */
|
|
21
|
+
export declare const CACHE_MS = 60000;
|
|
22
|
+
/** fullQuery adds the provider's range, comparison and filters to a request. */
|
|
23
|
+
export declare function fullQuery(ctx: ViakiteContext, req: ReportRequest): Query;
|
|
24
|
+
/**
|
|
25
|
+
* useReport runs a report for the provider's share through the public
|
|
26
|
+
* query, in the browser. The last report stays while a new range loads.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useReport(req: ReportRequest): ReportState;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Starts Viakite Analytics once, in the browser, and renders nothing. Put it
|
|
3
|
+
once in the root +layout.svelte (SvelteKit) or App.svelte. Its props are the
|
|
4
|
+
options of `init`. Page changes are followed through the browser's history,
|
|
5
|
+
which SvelteKit's router uses.
|
|
6
|
+
-->
|
|
7
|
+
<script>
|
|
8
|
+
import { onMount } from "svelte";
|
|
9
|
+
import { init } from "../index.js";
|
|
10
|
+
|
|
11
|
+
let props = $props();
|
|
12
|
+
|
|
13
|
+
onMount(() => {
|
|
14
|
+
init({ ...props });
|
|
15
|
+
});
|
|
16
|
+
</script>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Component } from "svelte";
|
|
2
|
+
|
|
3
|
+
import type { Options } from "../index";
|
|
4
|
+
|
|
5
|
+
/** Props of <Analytics />: the same options as `init` and the script tag's attributes. */
|
|
6
|
+
export type AnalyticsProps = Options;
|
|
7
|
+
|
|
8
|
+
/** Analytics starts Viakite Analytics once, in the browser, and renders nothing. */
|
|
9
|
+
export declare const Analytics: Component<AnalyticsProps>;
|
|
10
|
+
export default Analytics;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** A property value: text (up to 255 characters), a number, true/false or null. */
|
|
2
|
+
export type PropValue = string | number | boolean | null | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* Properties of a custom event, or traits of an identified user: up to 20,
|
|
5
|
+
* flat (no objects or lists), keys of 1 to 40 letters, digits, `_`, `-` or `.`.
|
|
6
|
+
* `revenue` (a number) and `currency` (an ISO code such as `INR`) are reserved
|
|
7
|
+
* and don't count against the 20.
|
|
8
|
+
*/
|
|
9
|
+
export type Props = Record<string, PropValue>;
|
|
10
|
+
/** Options for `init`. Each one matches an attribute of the script tag. */
|
|
11
|
+
export interface Options {
|
|
12
|
+
/** The project's public key, `pk_live_<region>_…` or `pk_test_<region>_…` (`data-project`). */
|
|
13
|
+
project: string;
|
|
14
|
+
/** Send events to this address instead of the region's (`data-api`), for a proxy or local work. */
|
|
15
|
+
api?: string;
|
|
16
|
+
/** Send the page title (`data-title`). Off by default: titles can hold personal data. */
|
|
17
|
+
title?: boolean;
|
|
18
|
+
/** Count hash changes (`/#/about`) as page views (`data-hash`). Off by default. */
|
|
19
|
+
hash?: boolean;
|
|
20
|
+
/** Extra query parameters to keep in page URLs (`data-params`, comma-separated). */
|
|
21
|
+
params?: string[] | string;
|
|
22
|
+
/** Track clicks on links to other sites as `Outbound link` (`data-outbound`). On by default. */
|
|
23
|
+
outbound?: boolean;
|
|
24
|
+
/** Track clicks on file links as `File download` (`data-downloads`). On by default. */
|
|
25
|
+
downloads?: boolean;
|
|
26
|
+
/** File extensions that count as downloads; replaces the default list (`data-download-ext`). */
|
|
27
|
+
downloadExtensions?: string[] | string;
|
|
28
|
+
/** This page is the not-found page: its view counts as a broken page (`data-404`). */
|
|
29
|
+
notFound?: boolean;
|
|
30
|
+
/** Log every event and warning in the console, and send nothing (`data-debug`). */
|
|
31
|
+
debug?: boolean;
|
|
32
|
+
/** Track on `localhost`, `127.0.0.1` and `file://` (`data-localhost`). Off by default. */
|
|
33
|
+
localhost?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Send a page view on `init` and on every path change in a single-page app.
|
|
36
|
+
* On by default; turn it off to call `pageview()` yourself, from a router.
|
|
37
|
+
*/
|
|
38
|
+
autoPageviews?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/** Options for a page view sent by hand. */
|
|
41
|
+
export interface PageviewOptions {
|
|
42
|
+
/** The page is a not-found page: the view counts as a broken page. */
|
|
43
|
+
notFound?: boolean;
|
|
44
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { PropType } from "vue";
|
|
2
|
+
/**
|
|
3
|
+
* Analytics starts Viakite Analytics once, in the browser, and renders
|
|
4
|
+
* nothing. Put it once in `App.vue` (Vue) or `app.vue` (Nuxt). It runs only
|
|
5
|
+
* on mount, so server rendering is safe. Page changes are followed through
|
|
6
|
+
* the browser's history, which Vue Router and Nuxt use.
|
|
7
|
+
*/
|
|
8
|
+
export declare const Analytics: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
9
|
+
project: {
|
|
10
|
+
type: StringConstructor;
|
|
11
|
+
required: true;
|
|
12
|
+
};
|
|
13
|
+
api: StringConstructor;
|
|
14
|
+
title: BooleanConstructor;
|
|
15
|
+
hash: BooleanConstructor;
|
|
16
|
+
params: PropType<string | string[]>;
|
|
17
|
+
outbound: {
|
|
18
|
+
readonly type: BooleanConstructor;
|
|
19
|
+
readonly default: undefined;
|
|
20
|
+
};
|
|
21
|
+
downloads: {
|
|
22
|
+
readonly type: BooleanConstructor;
|
|
23
|
+
readonly default: undefined;
|
|
24
|
+
};
|
|
25
|
+
downloadExtensions: PropType<string | string[]>;
|
|
26
|
+
notFound: BooleanConstructor;
|
|
27
|
+
debug: BooleanConstructor;
|
|
28
|
+
localhost: BooleanConstructor;
|
|
29
|
+
autoPageviews: {
|
|
30
|
+
readonly type: BooleanConstructor;
|
|
31
|
+
readonly default: undefined;
|
|
32
|
+
};
|
|
33
|
+
}>, () => null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
34
|
+
project: {
|
|
35
|
+
type: StringConstructor;
|
|
36
|
+
required: true;
|
|
37
|
+
};
|
|
38
|
+
api: StringConstructor;
|
|
39
|
+
title: BooleanConstructor;
|
|
40
|
+
hash: BooleanConstructor;
|
|
41
|
+
params: PropType<string | string[]>;
|
|
42
|
+
outbound: {
|
|
43
|
+
readonly type: BooleanConstructor;
|
|
44
|
+
readonly default: undefined;
|
|
45
|
+
};
|
|
46
|
+
downloads: {
|
|
47
|
+
readonly type: BooleanConstructor;
|
|
48
|
+
readonly default: undefined;
|
|
49
|
+
};
|
|
50
|
+
downloadExtensions: PropType<string | string[]>;
|
|
51
|
+
notFound: BooleanConstructor;
|
|
52
|
+
debug: BooleanConstructor;
|
|
53
|
+
localhost: BooleanConstructor;
|
|
54
|
+
autoPageviews: {
|
|
55
|
+
readonly type: BooleanConstructor;
|
|
56
|
+
readonly default: undefined;
|
|
57
|
+
};
|
|
58
|
+
}>> & Readonly<{}>, {
|
|
59
|
+
localhost: boolean;
|
|
60
|
+
title: boolean;
|
|
61
|
+
hash: boolean;
|
|
62
|
+
outbound: boolean;
|
|
63
|
+
downloads: boolean;
|
|
64
|
+
notFound: boolean;
|
|
65
|
+
debug: boolean;
|
|
66
|
+
autoPageviews: boolean;
|
|
67
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var s=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var m=(t,o)=>{for(var n in o)s(t,n,{get:o[n],enumerable:!0})},y=(t,o,n,e)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of c(o))!f.call(t,i)&&i!==n&&s(t,i,{get:()=>o[i],enumerable:!(e=u(o,i))||e.enumerable});return t};var g=t=>y(s({},"__esModule",{value:!0}),t);var B={};m(B,{Analytics:()=>d});module.exports=g(B);var r=require("vue"),l=require("../index.cjs"),a={type:Boolean,default:void 0},p=[String,Array],d=(0,r.defineComponent)({name:"ViakiteAnalytics",props:{project:{type:String,required:!0},api:String,title:Boolean,hash:Boolean,params:p,outbound:a,downloads:a,downloadExtensions:p,notFound:Boolean,debug:Boolean,localhost:Boolean,autoPageviews:a},setup(t){return(0,r.onMounted)(()=>{let o={project:t.project};for(let[n,e]of Object.entries(t))e!==void 0&&Object.assign(o,{[n]:e});(0,l.init)(o)}),()=>null}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Analytics } from "./Analytics";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{defineComponent as s,onMounted as a}from"vue";import{init as p}from"../index.js";var o={type:Boolean,default:void 0},i=[String,Array],l=s({name:"ViakiteAnalytics",props:{project:{type:String,required:!0},api:String,title:Boolean,hash:Boolean,params:i,outbound:o,downloads:o,downloadExtensions:i,notFound:Boolean,debug:Boolean,localhost:Boolean,autoPageviews:o},setup(t){return a(()=>{let n={project:t.project};for(let[r,e]of Object.entries(t))e!==void 0&&Object.assign(n,{[r]:e});p(n)}),()=>null}});export{l as Analytics};
|
package/package.json
CHANGED
|
@@ -1,6 +1,83 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viakite/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Viakite Analytics for the browser: page views, custom events, engaged time and scroll, without cookies.",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./react": {
|
|
17
|
+
"types": "./dist/react/index.d.ts",
|
|
18
|
+
"import": "./dist/react/index.js",
|
|
19
|
+
"require": "./dist/react/index.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./vue": {
|
|
22
|
+
"types": "./dist/vue/index.d.ts",
|
|
23
|
+
"import": "./dist/vue/index.js",
|
|
24
|
+
"require": "./dist/vue/index.cjs"
|
|
25
|
+
},
|
|
26
|
+
"./svelte": {
|
|
27
|
+
"types": "./dist/svelte/index.d.ts",
|
|
28
|
+
"svelte": "./dist/svelte/index.js",
|
|
29
|
+
"default": "./dist/svelte/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./a.js": "./dist/a.js",
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist"
|
|
36
|
+
],
|
|
37
|
+
"sideEffects": [
|
|
38
|
+
"./dist/a.js"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "node scripts/build.mjs",
|
|
42
|
+
"size": "node scripts/size.mjs",
|
|
43
|
+
"lint": "eslint .",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"e2e": "playwright test --config e2e/playwright.config.ts"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"react": ">=18",
|
|
50
|
+
"svelte": ">=5",
|
|
51
|
+
"vue": ">=3.3"
|
|
52
|
+
},
|
|
53
|
+
"peerDependenciesMeta": {
|
|
54
|
+
"react": {
|
|
55
|
+
"optional": true
|
|
56
|
+
},
|
|
57
|
+
"svelte": {
|
|
58
|
+
"optional": true
|
|
59
|
+
},
|
|
60
|
+
"vue": {
|
|
61
|
+
"optional": true
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@playwright/test": "1.65.1",
|
|
66
|
+
"@types/node": "26.6.6",
|
|
67
|
+
"@types/react": "19.3.0",
|
|
68
|
+
"@types/react-dom": "19.3.0",
|
|
69
|
+
"esbuild": "0.28.2",
|
|
70
|
+
"eslint": "10.15.0",
|
|
71
|
+
"jsdom": "31.0.1",
|
|
72
|
+
"react": "19.3.1",
|
|
73
|
+
"react-dom": "19.3.1",
|
|
74
|
+
"svelte": "5.58.0",
|
|
75
|
+
"typescript": "6.0.3",
|
|
76
|
+
"typescript-eslint": "8.73.0",
|
|
77
|
+
"vitest": "5.1.1",
|
|
78
|
+
"vue": "3.5.46"
|
|
79
|
+
},
|
|
80
|
+
"publishConfig": {
|
|
81
|
+
"access": "public"
|
|
82
|
+
}
|
|
83
|
+
}
|