@vskstudio/takt-astro 0.6.1 → 0.7.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 +66 -14
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# @vskstudio/takt-astro
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
> 📚 **Documentation** — [taktlytics.com/docs/wrappers/astro](https://taktlytics.com/docs/wrappers/astro)
|
|
5
|
+
|
|
3
6
|
Astro integration for [Takt](https://github.com/vskstudio/takt-core), privacy-friendly analytics. It injects a tiny browser runtime that boots Takt, fires the initial pageview, and tracks client-side navigations — including [Astro View Transitions](https://docs.astro.build/en/guides/view-transitions/).
|
|
4
7
|
|
|
5
8
|
## Install
|
|
@@ -8,9 +11,11 @@ Astro integration for [Takt](https://github.com/vskstudio/takt-core), privacy-fr
|
|
|
8
11
|
pnpm add @vskstudio/takt-astro @vskstudio/takt-core
|
|
9
12
|
```
|
|
10
13
|
|
|
14
|
+
Both are peer dependencies: `astro` (`>=4`) and `@vskstudio/takt-core` (`>=0.9.0`).
|
|
15
|
+
|
|
11
16
|
## Usage
|
|
12
17
|
|
|
13
|
-
Pick **one** of the two paths below — not both. Both boot core's default instance,
|
|
18
|
+
Pick **one** of the two paths below — not both. Both boot core's default instance, guarded by a shared `window.__takt` flag: installing both does not double-count (the second boot is skipped), but it ships the runtime twice for nothing.
|
|
14
19
|
|
|
15
20
|
### Integration (recommended)
|
|
16
21
|
|
|
@@ -44,21 +49,22 @@ Both the integration and the component accept the same options, with one excepti
|
|
|
44
49
|
| Option | Type | Default | Description |
|
|
45
50
|
| --- | --- | --- | --- |
|
|
46
51
|
| `domain` | `string` | `location.hostname` | Site identifier sent with every event. |
|
|
47
|
-
| `endpoint` | `string` |
|
|
52
|
+
| `endpoint` | `string` | `https://taktlytics.com/api/event` | Ingestion endpoint. Pass `/api/event` for a same-origin first-party proxy. |
|
|
48
53
|
| `scriptOrigin` | `string` | – | First-party origin to derive the endpoint from (`{origin}/api/event`) — your Takt domain or a custom domain to dodge ad-blockers (endpoint wins over it). |
|
|
49
54
|
| `outbound` | `boolean` | `false` | Auto-track outbound link clicks. |
|
|
50
|
-
| `files` | `boolean` | `false` | Auto-track file downloads. |
|
|
55
|
+
| `files` | `boolean` | `false` | Auto-track file downloads, using core's default extension list (this integration does not expose an extension override). |
|
|
51
56
|
| `track404` | `boolean` | `false` | Report a `404` event when the page is an error page (`[data-takt-404]` / `<meta name="takt:404">` marker, or a 404 HTTP status). |
|
|
52
57
|
| `spa` | `boolean` | `true` | Track client-side navigations. |
|
|
53
58
|
| `respectDnt` | `boolean` | `true` | Suppress events when Do Not Track is on. |
|
|
54
59
|
| `excludeLocalhost` | `boolean` | `true` | Suppress events on localhost / private IPs. |
|
|
55
60
|
| `enabled` | `boolean` | `true` | Master kill switch — set `false` to suppress every event. |
|
|
56
61
|
| `sampleRate` | `number` | `1` | Fraction of visitors to track, `0`–`1`. |
|
|
57
|
-
| `trackQuery` | `boolean` | `false` |
|
|
58
|
-
| `queryParams` | `string[]` | – |
|
|
62
|
+
| `trackQuery` | `boolean` | `false` | Keep the full query string and hash instead of stripping them. Wins over `queryParams`. |
|
|
63
|
+
| `queryParams` | `string[]` | – | Allowlist of query params to keep, applied only when `trackQuery` is off. |
|
|
59
64
|
| `exclude` | `string[]` | – | Path prefixes never tracked, e.g. `['/app', '/account']` (segment-bounded, checked at send time). |
|
|
60
|
-
| `scrubUrl` | `(url: string) => string` | – | **Integration only.** Rewrite each URL before it is sent (e.g. strip a fragment or PII
|
|
61
|
-
| `tagged` | `boolean` | `false` | Auto-track
|
|
65
|
+
| `scrubUrl` | `(url: string) => string` | – | **Integration only.** Rewrite each URL before it is sent (page, referrer, and the `url` prop of outbound-link and file-download events), e.g. to strip a fragment or PII. See the note below. |
|
|
66
|
+
| `tagged` | `boolean` | `false` | Auto-track clicks on `[data-takt-event]` elements; `data-takt-prop-*` attributes become event props. |
|
|
67
|
+
| `debug` | `boolean` | `false` | Log each payload to the browser console before sending. |
|
|
62
68
|
|
|
63
69
|
> **`scrubUrl` note.** Unlike the other options, `scrubUrl` is a **function**, so it
|
|
64
70
|
> is supported **only via the integration**, not the `<Takt />` component. The
|
|
@@ -77,12 +83,36 @@ Astro's client router runs several history operations per navigation (scroll-res
|
|
|
77
83
|
|
|
78
84
|
## Custom events
|
|
79
85
|
|
|
80
|
-
|
|
86
|
+
`track`, `pageview`, `optOut`, `optIn` and `isOptedOut` are re-exported from core for convenience. `track` and `pageview` act on core's default instance, which only exists in the browser once the injected runtime has booted, so call them from a client-side `<script>`, not from `.astro` frontmatter (where they are silent no-ops):
|
|
81
87
|
|
|
82
|
-
```
|
|
83
|
-
|
|
88
|
+
```astro
|
|
89
|
+
<button id="signup">Sign up</button>
|
|
90
|
+
<script>
|
|
91
|
+
import { track } from '@vskstudio/takt-astro'
|
|
92
|
+
document.getElementById('signup')?.addEventListener('click', () => {
|
|
93
|
+
track('Signup', { props: { plan: 'pro' }, revenue: { amount: '9.00', currency: 'USD' } })
|
|
94
|
+
})
|
|
95
|
+
</script>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Consent
|
|
99
|
+
|
|
100
|
+
`optOut`, `optIn` and `isOptedOut` do not wait for the runtime to boot: they read and write the stored choice directly. A consent banner can therefore run before the injected runtime, and the instance it boots later honours the choice. Call them from a client-side `<script>`, since the choice lives in the browser.
|
|
84
101
|
|
|
85
|
-
|
|
102
|
+
```astro
|
|
103
|
+
<button id="analytics-toggle"></button>
|
|
104
|
+
<script>
|
|
105
|
+
import { isOptedOut, optIn, optOut } from '@vskstudio/takt-astro'
|
|
106
|
+
const button = document.getElementById('analytics-toggle')
|
|
107
|
+
const render = () => {
|
|
108
|
+
if (button) button.textContent = isOptedOut() ? 'Enable analytics' : 'Disable analytics'
|
|
109
|
+
}
|
|
110
|
+
button?.addEventListener('click', () => {
|
|
111
|
+
isOptedOut() ? optIn() : optOut()
|
|
112
|
+
render()
|
|
113
|
+
})
|
|
114
|
+
render()
|
|
115
|
+
</script>
|
|
86
116
|
```
|
|
87
117
|
|
|
88
118
|
## Widgets
|
|
@@ -98,19 +128,41 @@ import Embed from '@vskstudio/takt-astro/Embed.astro'
|
|
|
98
128
|
<Embed domain="example.com" theme="dark" />
|
|
99
129
|
```
|
|
100
130
|
|
|
101
|
-
`Badge` renders an `<img>` (props: `domain
|
|
131
|
+
`Badge` renders an `<img>` (props: `domain` — required —, `variant` `a` | `b` | `d`, `glyph` `unplug` | `dash` | `off` | `eyeoff`, `lang` `fr` | `en`, `host`). Its `alt` defaults to `"takt"` and can be overridden; `loading="lazy"` and `decoding="async"` are applied after your attributes and cannot.
|
|
132
|
+
|
|
133
|
+
`Embed` renders an `<iframe>` (props: `domain` — required —, `theme` `light` | `dark` | `auto`, `lang`, `host`, plus `width` = `404`, `height` = `264`, `title` = `"takt"`); the iframe is sandboxed (`allow-scripts allow-same-origin`) and ships a fixed `referrerpolicy="strict-origin-when-cross-origin"`, a `loading="lazy"` and a zero border — all applied after your attributes, so a consumer cannot weaken them. Extra attributes pass through to the underlying element, but the built `src` is locked and cannot be overridden. The optional `host` must be an absolute `http(s)` URL — core validates it and throws on anything else (e.g. a `javascript:` URL), and reduces it to its origin (dropping path/query). Omitting `host` falls back to the hosted Takt origin (`https://taktlytics.com`), not to the current origin.
|
|
102
134
|
|
|
103
135
|
## Public stats
|
|
104
136
|
|
|
105
137
|
`createStats` (re-exported from core) reads public analytics:
|
|
106
138
|
|
|
139
|
+
Every method takes the domain first and the params second — the domain is optional once `createStats` is bound to one:
|
|
140
|
+
|
|
107
141
|
```js
|
|
108
|
-
import { createStats } from '@vskstudio/takt-astro'
|
|
142
|
+
import { createStats, PublicApiError } from '@vskstudio/takt-astro'
|
|
109
143
|
|
|
110
144
|
const stats = createStats({ domain: 'example.com' })
|
|
111
|
-
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
const summary = await stats.summary(undefined, { period: '7d' })
|
|
148
|
+
const rows = await stats.breakdown('page', undefined, { period: '7d' })
|
|
149
|
+
const live = await stats.realtime()
|
|
150
|
+
} catch (err) {
|
|
151
|
+
if (err instanceof PublicApiError) console.error(err.status, err.message)
|
|
152
|
+
}
|
|
112
153
|
```
|
|
113
154
|
|
|
155
|
+
## Public exports
|
|
156
|
+
|
|
157
|
+
From `@vskstudio/takt-astro`:
|
|
158
|
+
|
|
159
|
+
- `default` / `takt` — the integration factory (same function under both names)
|
|
160
|
+
- `resolveOptions`, `assertNoScrubUrl`, `buildRuntime` — the internals the `.astro` components build on, exported so you can drive the runtime yourself
|
|
161
|
+
- Re-exported from core: `track`, `pageview`, `optOut`, `optIn`, `isOptedOut`, `createStats`, `PublicApiError`, `badgeUrl`, `embedUrl`
|
|
162
|
+
- Types: `TaktOptions`, plus `InitOptions`, `TrackOptions`, `BadgeOptions`, `EmbedOptions`, `BadgeVariant`, `BadgeGlyph`, `EmbedTheme`, `WidgetLang`, `StatsClient`, `StatsClientOptions`, `StatsParams`, `StatsPeriod`, `StatsDimension`, `StatsMetrics`, `StatsSummary`, `StatsPoint`, `StatsTimeseries`, `StatsBreakdownRow`, `StatsBreakdown`, `StatsRealtime` re-exported from core
|
|
163
|
+
|
|
164
|
+
Component subpaths: `@vskstudio/takt-astro/Takt.astro`, `/Badge.astro`, `/Embed.astro`.
|
|
165
|
+
|
|
114
166
|
## License
|
|
115
167
|
|
|
116
168
|
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AstroIntegration } from 'astro';
|
|
2
2
|
import { InitOptions } from '@vskstudio/takt-core';
|
|
3
|
-
export { BadgeGlyph, BadgeOptions, BadgeVariant, EmbedOptions, EmbedTheme, InitOptions, PublicApiError, StatsBreakdown, StatsBreakdownRow, StatsClient, StatsClientOptions, StatsDimension, StatsMetrics, StatsParams, StatsPeriod, StatsPoint, StatsRealtime, StatsSummary, StatsTimeseries, TrackOptions, WidgetLang, badgeUrl, createStats, embedUrl, optIn, optOut, pageview, track } from '@vskstudio/takt-core';
|
|
3
|
+
export { BadgeGlyph, BadgeOptions, BadgeVariant, EmbedOptions, EmbedTheme, InitOptions, PublicApiError, StatsBreakdown, StatsBreakdownRow, StatsClient, StatsClientOptions, StatsDimension, StatsMetrics, StatsParams, StatsPeriod, StatsPoint, StatsRealtime, StatsSummary, StatsTimeseries, TrackOptions, WidgetLang, badgeUrl, createStats, embedUrl, isOptedOut, optIn, optOut, pageview, track } from '@vskstudio/takt-core';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Options for the Takt integration and `<Takt />` component. Mirrors core's
|
|
@@ -54,6 +54,7 @@ interface TaktOptions {
|
|
|
54
54
|
scrubUrl?: (url: string) => string;
|
|
55
55
|
/** Auto-track elements marked with `data-takt-event`. */
|
|
56
56
|
tagged?: boolean;
|
|
57
|
+
debug?: boolean;
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
59
60
|
* Guard the `<Takt />` component path against `scrubUrl`. The component
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,8 @@ function resolveOptions(options = {}) {
|
|
|
22
22
|
trackQuery: options.trackQuery,
|
|
23
23
|
queryParams: options.queryParams,
|
|
24
24
|
exclude: options.exclude,
|
|
25
|
-
tagged: options.tagged
|
|
25
|
+
tagged: options.tagged,
|
|
26
|
+
debug: options.debug
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -65,7 +66,7 @@ function takt(options = {}) {
|
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
// src/index.ts
|
|
68
|
-
import { track, pageview, optOut, optIn } from "@vskstudio/takt-core";
|
|
69
|
+
import { track, pageview, optOut, optIn, isOptedOut } from "@vskstudio/takt-core";
|
|
69
70
|
import { createStats, PublicApiError, badgeUrl, embedUrl } from "@vskstudio/takt-core";
|
|
70
71
|
export {
|
|
71
72
|
PublicApiError,
|
|
@@ -75,6 +76,7 @@ export {
|
|
|
75
76
|
createStats,
|
|
76
77
|
takt as default,
|
|
77
78
|
embedUrl,
|
|
79
|
+
isOptedOut,
|
|
78
80
|
optIn,
|
|
79
81
|
optOut,
|
|
80
82
|
pageview,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vskstudio/takt-astro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Astro integration for Takt privacy-friendly analytics",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "VSK Studio",
|
|
@@ -56,14 +56,14 @@
|
|
|
56
56
|
"release": "pnpm build && changeset publish"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@vskstudio/takt-core": ">=0.
|
|
59
|
+
"@vskstudio/takt-core": ">=0.9.0",
|
|
60
60
|
"astro": ">=4"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@changesets/cli": "^2.31.0",
|
|
64
64
|
"@playwright/test": "^1.50.0",
|
|
65
65
|
"@size-limit/preset-small-lib": "^11.1.6",
|
|
66
|
-
"@vskstudio/takt-core": "^0.
|
|
66
|
+
"@vskstudio/takt-core": "^0.9.0",
|
|
67
67
|
"astro": "^5.0.0",
|
|
68
68
|
"eslint": "^9.0.0",
|
|
69
69
|
"size-limit": "^11.1.6",
|