@ciphera-net/pulse-nuxt 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +203 -0
- package/README.md +110 -0
- package/dist/module.d.ts +42 -0
- package/dist/module.js +98 -0
- package/dist/module.json +9 -0
- package/dist/pulse.d.ts +79 -0
- package/dist/pulse.js +132 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
203
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Pulse Analytics for Nuxt
|
|
2
|
+
|
|
3
|
+
Privacy-first analytics for a Nuxt site, in one module. No cookies, no personal
|
|
4
|
+
data, and the script it adds to your pages is under 3 KB.
|
|
5
|
+
|
|
6
|
+
[Pulse Analytics](https://pulse.ciphera.net) is built by [Ciphera](https://ciphera.net), a
|
|
7
|
+
company in Belgium, and hosted in Europe.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npx nuxi module add @ciphera-net/pulse-nuxt
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Or by hand:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -D @ciphera-net/pulse-nuxt
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// nuxt.config.ts
|
|
23
|
+
export default defineNuxtConfig({
|
|
24
|
+
modules: ["@ciphera-net/pulse-nuxt"],
|
|
25
|
+
pulse: { domain: "example.com" },
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
That is the whole setup. `domain` is the hostname your site is registered under
|
|
30
|
+
in Pulse — if a site-config module (`@nuxtjs/sitemap`, `@nuxtjs/robots`,
|
|
31
|
+
`@nuxtjs/seo`) already gives you a `site.url`, you can leave it out and the
|
|
32
|
+
module reads the hostname from there.
|
|
33
|
+
|
|
34
|
+
You need a Pulse Analytics account with a site registered for the same domain.
|
|
35
|
+
The free plan is enough to start.
|
|
36
|
+
|
|
37
|
+
## Options
|
|
38
|
+
|
|
39
|
+
| Option | Default | What it does |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| `domain` | from `site.url` | The domain your site is registered under in Pulse Analytics. Pass this when `site.url` is not the domain you track, for example on a preview deployment. |
|
|
42
|
+
| `apiUrl` | — | Route events through your own proxy origin. A bare origin (`https://example.com`), not a full URL: the tracker appends its own path. |
|
|
43
|
+
| `trackScroll` | `true` | Record scroll depth. |
|
|
44
|
+
| `trackOutbound` | `true` | Record outbound link clicks as `outbound_link` events. |
|
|
45
|
+
| `trackDownloads` | `true` | Record file download clicks as `file_download` events. |
|
|
46
|
+
| `companion` | `false` | Also record clicks, copies and form submits. A second, separate script — see below. `true` records all three; an object turns individual ones off. |
|
|
47
|
+
| `injectInDev` | `false` | Inject during `nuxt dev` too. Off by default — see below. |
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
pulse: {
|
|
51
|
+
domain: "example.com",
|
|
52
|
+
companion: { copy: false },
|
|
53
|
+
trackScroll: false,
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Three things worth knowing
|
|
58
|
+
|
|
59
|
+
**It does not run in `nuxt dev`.** The tracker has no localhost guard, so a dev
|
|
60
|
+
server would send real pageviews at your production dashboard. The module prints
|
|
61
|
+
a line saying it stayed out. Set `injectInDev: true` if you actually want it.
|
|
62
|
+
|
|
63
|
+
**The interaction capture is a second request on purpose.** The core script's
|
|
64
|
+
size is a published claim, and nothing gets folded into it to make a feature
|
|
65
|
+
look free. `companion: true` costs you a second, separate file.
|
|
66
|
+
|
|
67
|
+
**View-source shows the tag itself.** Unlike the Astro and Framer integrations,
|
|
68
|
+
this module adds a real `<script src>` to `app.head`, so the tag Nuxt renders is
|
|
69
|
+
byte-for-byte the one you would paste into a layout by hand, and no JavaScript
|
|
70
|
+
of ours reaches your bundle. It works with a strict Content-Security-Policy that
|
|
71
|
+
forbids inline script.
|
|
72
|
+
|
|
73
|
+
## Already using `@nuxt/scripts`?
|
|
74
|
+
|
|
75
|
+
Then you may not need this module. Pulse is a first-party entry in the
|
|
76
|
+
[Nuxt Scripts registry](https://scripts.nuxt.com) as `useScriptPulseAnalytics`,
|
|
77
|
+
which gives you loading triggers, consent gating and a typed `track()` you can
|
|
78
|
+
call from a component. The option names here (`domain`, `apiUrl`, `trackScroll`,
|
|
79
|
+
`trackOutbound`, `trackDownloads`) are deliberately the same, so moving either
|
|
80
|
+
way is a copy and paste.
|
|
81
|
+
|
|
82
|
+
Take this module when you want the tag and nothing else; take `@nuxt/scripts`
|
|
83
|
+
when you want the tag *and* a way to fire events from your components. Do not
|
|
84
|
+
install both — they would each add a tag, and the pageviews would double.
|
|
85
|
+
|
|
86
|
+
## What Pulse Analytics measures
|
|
87
|
+
|
|
88
|
+
Pageviews, referrers, countries, devices, time on page and scroll depth, plus
|
|
89
|
+
goals, funnels and campaigns. It sets no cookies and stores no personal data.
|
|
90
|
+
Visitors whose browser sends Do Not Track or Global Privacy Control are not
|
|
91
|
+
counted at all — so if you test in Brave or Firefox and see nothing, that is the
|
|
92
|
+
tracker behaving correctly. Safari is the easiest browser to verify an install in.
|
|
93
|
+
|
|
94
|
+
## Compatibility
|
|
95
|
+
|
|
96
|
+
Nuxt 3 and Nuxt 4. The range is measured, not asserted: `npm run verify` builds
|
|
97
|
+
a real Nuxt site on each major and reads the tag out of the emitted HTML.
|
|
98
|
+
Nuxt 2 is refused with an error — its head is Vue Meta and a different shape
|
|
99
|
+
entirely.
|
|
100
|
+
|
|
101
|
+
## Licence
|
|
102
|
+
|
|
103
|
+
Copyright 2026 Ciphera BV. Licensed under the Apache License, Version 2.0 —
|
|
104
|
+
the `LICENSE` file is the licence text verbatim, so the copyright line lives
|
|
105
|
+
here rather than inside it.
|
|
106
|
+
|
|
107
|
+
This package has **zero runtime dependencies**, asserted in CI.
|
|
108
|
+
|
|
109
|
+
Nuxt is a trademark of its owners; this is an independent module and is not
|
|
110
|
+
affiliated with or endorsed by the Nuxt project.
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Nuxt } from "@nuxt/schema";
|
|
2
|
+
import { type ModuleOptions } from "./pulse.js";
|
|
3
|
+
export type { ModuleOptions, CompanionOptions, ScriptDescriptor } from "./pulse.js";
|
|
4
|
+
export { SCRIPT_URL, COMPANION_URL, buildScripts, normalizeDomain, isValidDomain, hostnameFromSite, resolveCompanion, resolveDomain, } from "./pulse.js";
|
|
5
|
+
/**
|
|
6
|
+
* Pulse Analytics — privacy-first web analytics for Nuxt.
|
|
7
|
+
*
|
|
8
|
+
* export default defineNuxtConfig({
|
|
9
|
+
* modules: ["@ciphera-net/pulse-nuxt"],
|
|
10
|
+
* pulse: { domain: "example.com" },
|
|
11
|
+
* })
|
|
12
|
+
*
|
|
13
|
+
* 🔑 This is a plain module function rather than a `defineNuxtModule()` call,
|
|
14
|
+
* and that is a deliberate, measured choice — see RELEASING.md § "Why there is
|
|
15
|
+
* no @nuxt/kit dependency". The short version: everything this module does is
|
|
16
|
+
* push two objects into `nuxt.options.app.head.script`, `defineNuxtModule` is
|
|
17
|
+
* sugar around that, and taking `@nuxt/kit` costs a runtime dependency plus a
|
|
18
|
+
* version range that peers have already got wrong. The one thing the sugar
|
|
19
|
+
* would buy — the compatibility gate — is done explicitly below, because Nuxt
|
|
20
|
+
* does NOT read `.meta.compatibility` off a bare function module. That was
|
|
21
|
+
* proven with a control: a module declaring `nuxt: "^99.0.0"` built clean
|
|
22
|
+
* against Nuxt 4.5.2, silently.
|
|
23
|
+
*/
|
|
24
|
+
declare function pulseModule(inlineOptions: ModuleOptions | undefined, nuxt: Nuxt): void;
|
|
25
|
+
declare namespace pulseModule {
|
|
26
|
+
var meta: {
|
|
27
|
+
name: string;
|
|
28
|
+
configKey: string;
|
|
29
|
+
compatibility: {
|
|
30
|
+
nuxt: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export default pulseModule;
|
|
35
|
+
declare module "@nuxt/schema" {
|
|
36
|
+
interface NuxtConfig {
|
|
37
|
+
pulse?: ModuleOptions;
|
|
38
|
+
}
|
|
39
|
+
interface NuxtOptions {
|
|
40
|
+
pulse?: ModuleOptions;
|
|
41
|
+
}
|
|
42
|
+
}
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { buildScripts, resolveDomain } from "./pulse.js";
|
|
2
|
+
export { SCRIPT_URL, COMPANION_URL, buildScripts, normalizeDomain, isValidDomain, hostnameFromSite, resolveCompanion, resolveDomain, } from "./pulse.js";
|
|
3
|
+
const MODULE_NAME = "@ciphera-net/pulse-nuxt";
|
|
4
|
+
const CONFIG_KEY = "pulse";
|
|
5
|
+
/** The oldest Nuxt whose module contract and `app.head` this module is built
|
|
6
|
+
* for. Nuxt 2's head is Vue Meta with a different shape entirely, so this is
|
|
7
|
+
* a real boundary, not a courtesy. */
|
|
8
|
+
const MIN_MAJOR = 3;
|
|
9
|
+
/**
|
|
10
|
+
* Pulse Analytics — privacy-first web analytics for Nuxt.
|
|
11
|
+
*
|
|
12
|
+
* export default defineNuxtConfig({
|
|
13
|
+
* modules: ["@ciphera-net/pulse-nuxt"],
|
|
14
|
+
* pulse: { domain: "example.com" },
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* 🔑 This is a plain module function rather than a `defineNuxtModule()` call,
|
|
18
|
+
* and that is a deliberate, measured choice — see RELEASING.md § "Why there is
|
|
19
|
+
* no @nuxt/kit dependency". The short version: everything this module does is
|
|
20
|
+
* push two objects into `nuxt.options.app.head.script`, `defineNuxtModule` is
|
|
21
|
+
* sugar around that, and taking `@nuxt/kit` costs a runtime dependency plus a
|
|
22
|
+
* version range that peers have already got wrong. The one thing the sugar
|
|
23
|
+
* would buy — the compatibility gate — is done explicitly below, because Nuxt
|
|
24
|
+
* does NOT read `.meta.compatibility` off a bare function module. That was
|
|
25
|
+
* proven with a control: a module declaring `nuxt: "^99.0.0"` built clean
|
|
26
|
+
* against Nuxt 4.5.2, silently.
|
|
27
|
+
*/
|
|
28
|
+
function pulseModule(inlineOptions, nuxt) {
|
|
29
|
+
const options = {
|
|
30
|
+
...(nuxt.options[CONFIG_KEY] ?? {}),
|
|
31
|
+
...(inlineOptions ?? {}),
|
|
32
|
+
};
|
|
33
|
+
const major = nuxtMajor(nuxt);
|
|
34
|
+
if (major !== null && major < MIN_MAJOR) {
|
|
35
|
+
throw new Error(`[pulse] ${MODULE_NAME} requires Nuxt ${MIN_MAJOR} or newer; this project is running Nuxt ${major}.`);
|
|
36
|
+
}
|
|
37
|
+
// The tracker has no localhost guard, so a dev server would send real
|
|
38
|
+
// pageviews at the production dashboard. Opt in deliberately — and say so
|
|
39
|
+
// either way, because an analytics module that is quietly absent is the
|
|
40
|
+
// worst of the three outcomes.
|
|
41
|
+
if (nuxt.options.dev && !options.injectInDev) {
|
|
42
|
+
log("info", "not injected in dev (set `injectInDev: true` to override)");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// `site.url` is not a Nuxt core option. `nuxt-site-config` adds it, and
|
|
46
|
+
// @nuxtjs/sitemap, @nuxtjs/robots and @nuxtjs/seo all install that — so it
|
|
47
|
+
// is there often enough to be worth reading and never there reliably enough
|
|
48
|
+
// to depend on.
|
|
49
|
+
const siteUrl = nuxt.options.site?.url;
|
|
50
|
+
// Throws on an explicitly supplied domain that cannot be a hostname. A typo
|
|
51
|
+
// there is a silent no-data install, which is worth a build error.
|
|
52
|
+
const { domain, source } = resolveDomain(options, siteUrl);
|
|
53
|
+
const head = (nuxt.options.app.head ??= {});
|
|
54
|
+
const scripts = (head.script ??= []);
|
|
55
|
+
scripts.push(...buildScripts(domain, options));
|
|
56
|
+
if (source === "browser") {
|
|
57
|
+
log("warn", "no `pulse.domain` and no `site.url` — the tag will auto-detect the browser's hostname. Set `pulse: { domain: \"…\" }` if this site is served on more than one domain.");
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const from = source === "option" ? "the `domain` option" : "`site.url`";
|
|
61
|
+
const extra = options.companion ? ", with interaction capture" : "";
|
|
62
|
+
log("info", `tracking ${domain} (from ${from})${extra}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Nuxt's major version, or null when it cannot be read.
|
|
66
|
+
*
|
|
67
|
+
* `nuxt._version` is the full string (`"4.5.2"`, measured) and
|
|
68
|
+
* `nuxt.options._majorVersion` is the number. Both are private fields, which
|
|
69
|
+
* is why this returns null rather than guessing when neither is present: a
|
|
70
|
+
* module that refuses to load because it could not read a private field would
|
|
71
|
+
* be worse than one that loads and works. */
|
|
72
|
+
function nuxtMajor(nuxt) {
|
|
73
|
+
const full = nuxt._version;
|
|
74
|
+
if (typeof full === "string") {
|
|
75
|
+
const major = Number.parseInt(full.split(".")[0] ?? "", 10);
|
|
76
|
+
if (Number.isFinite(major))
|
|
77
|
+
return major;
|
|
78
|
+
}
|
|
79
|
+
const fromOptions = nuxt.options._majorVersion;
|
|
80
|
+
return typeof fromOptions === "number" ? fromOptions : null;
|
|
81
|
+
}
|
|
82
|
+
/** Nuxt's own logger lives in `@nuxt/kit`, which this module deliberately does
|
|
83
|
+
* not take, so these go to the console. They are the only output the module
|
|
84
|
+
* produces, and saying nothing at all would make "did it inject?" an
|
|
85
|
+
* unanswerable question. */
|
|
86
|
+
function log(level, message) {
|
|
87
|
+
const line = `[${CONFIG_KEY}] ${message}`;
|
|
88
|
+
if (level === "warn")
|
|
89
|
+
console.warn(line);
|
|
90
|
+
else
|
|
91
|
+
console.info(line);
|
|
92
|
+
}
|
|
93
|
+
pulseModule.meta = {
|
|
94
|
+
name: MODULE_NAME,
|
|
95
|
+
configKey: CONFIG_KEY,
|
|
96
|
+
compatibility: { nuxt: ">=3.0.0" },
|
|
97
|
+
};
|
|
98
|
+
export default pulseModule;
|
package/dist/module.json
ADDED
package/dist/pulse.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export declare const SCRIPT_URL = "https://js.ciphera.net/script.js";
|
|
2
|
+
export declare const COMPANION_URL = "https://js.ciphera.net/script.interactions.js";
|
|
3
|
+
/** Lower-case, drop a scheme, path, port and trailing dot. Keeps `www.` — the
|
|
4
|
+
* Pulse site may be registered either way and the user can override it. */
|
|
5
|
+
export declare function normalizeDomain(input: string): string;
|
|
6
|
+
export declare function isValidDomain(domain: string): boolean;
|
|
7
|
+
/** The hostname of a site URL, or null when it is unset or does not parse.
|
|
8
|
+
* Nuxt core has no `site` option; `nuxt-site-config` (which `@nuxtjs/sitemap`,
|
|
9
|
+
* `@nuxtjs/robots` and `@nuxtjs/seo` all install) adds `site.url`, and this is
|
|
10
|
+
* how we read it when it happens to be there. */
|
|
11
|
+
export declare function hostnameFromSite(site: string | URL | undefined | null): string | null;
|
|
12
|
+
/** Which interactions the companion script records. Every one defaults to on;
|
|
13
|
+
* the tracker reads them as `data-no-*` presence flags. */
|
|
14
|
+
export interface CompanionOptions {
|
|
15
|
+
/** Record clicks on buttons and links as `click` events. */
|
|
16
|
+
clicks?: boolean;
|
|
17
|
+
/** Record text copies as `copy` events. */
|
|
18
|
+
copy?: boolean;
|
|
19
|
+
/** Record form submits as `form_submit` events. */
|
|
20
|
+
forms?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface ModuleOptions {
|
|
23
|
+
/** The domain the site is registered under in Pulse. Defaults to the
|
|
24
|
+
* hostname of `site.url` when a site-config module provides one. With
|
|
25
|
+
* neither, the tag carries no `data-domain` and the tracker falls back to
|
|
26
|
+
* the browser's own hostname — correct for a single-domain site. */
|
|
27
|
+
domain?: string;
|
|
28
|
+
/** Route events through your own proxy origin. A bare origin
|
|
29
|
+
* (`https://example.com`), not a full URL: the tracker appends its own path. */
|
|
30
|
+
apiUrl?: string;
|
|
31
|
+
/** Record scroll depth. Default `true`. */
|
|
32
|
+
trackScroll?: boolean;
|
|
33
|
+
/** Record outbound link clicks as `outbound_link` events. Default `true`. */
|
|
34
|
+
trackOutbound?: boolean;
|
|
35
|
+
/** Record file download clicks as `file_download` events. Default `true`. */
|
|
36
|
+
trackDownloads?: boolean;
|
|
37
|
+
/** Also load the companion script, which records clicks, copies and form
|
|
38
|
+
* submits. A SECOND request on purpose: the core script's size is a
|
|
39
|
+
* published claim and nothing may be folded into it. `true` records all
|
|
40
|
+
* three; an object turns individual ones off. */
|
|
41
|
+
companion?: boolean | CompanionOptions;
|
|
42
|
+
/** Inject during `nuxt dev` as well. Off by default: the tracker has no
|
|
43
|
+
* localhost guard, so a dev server would send real pageviews at production. */
|
|
44
|
+
injectInDev?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export type DomainSource = "option" | "site" | "browser";
|
|
47
|
+
export interface Resolution {
|
|
48
|
+
domain: string | null;
|
|
49
|
+
source: DomainSource;
|
|
50
|
+
}
|
|
51
|
+
/** Resolve the domain, saying WHERE it came from so the caller can log it.
|
|
52
|
+
* Never throws for a missing domain — a null domain is a working install that
|
|
53
|
+
* auto-detects — but an explicitly supplied domain that cannot be a hostname
|
|
54
|
+
* is a typo, and a typo there is a silent no-data install, which is worth a
|
|
55
|
+
* build error. */
|
|
56
|
+
export declare function resolveDomain(options: ModuleOptions, site: string | URL | undefined | null): Resolution;
|
|
57
|
+
/** One entry of Nuxt's `app.head.script` array. Deliberately not imported from
|
|
58
|
+
* `@nuxt/schema` — this file must stay free of Nuxt so it can be tested
|
|
59
|
+
* without one, and the shape is a plain attribute bag either way. */
|
|
60
|
+
export type ScriptDescriptor = Record<string, string | boolean | undefined>;
|
|
61
|
+
/** Normalise `companion` into the three booleans the second script needs, or
|
|
62
|
+
* null when there is to be no second script. */
|
|
63
|
+
export declare function resolveCompanion(companion: ModuleOptions["companion"]): {
|
|
64
|
+
clicks: boolean;
|
|
65
|
+
copy: boolean;
|
|
66
|
+
forms: boolean;
|
|
67
|
+
} | null;
|
|
68
|
+
/** The script descriptors to append to `app.head.script`, in order.
|
|
69
|
+
*
|
|
70
|
+
* The core script is always first. The companion, when asked for, is a second
|
|
71
|
+
* entry and never carries `data-domain` — it reads `window.pulse`, which the
|
|
72
|
+
* core script owns.
|
|
73
|
+
*
|
|
74
|
+
* ⚠️ `defer` is a boolean here and Unhead renders it as a BARE `defer`
|
|
75
|
+
* attribute, which is what we want. It is spelled as a boolean rather than
|
|
76
|
+
* the string `'defer'` because the string would ship `defer="defer"` — valid
|
|
77
|
+
* HTML, a different byte-string, and one this project asserts against a real
|
|
78
|
+
* rendered page rather than trusting. */
|
|
79
|
+
export declare function buildScripts(domain: string | null, options?: ModuleOptions): ScriptDescriptor[];
|
package/dist/pulse.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Pure logic for the Pulse Nuxt module: which script tags to add to the head,
|
|
2
|
+
// and what domain to add them with. No Nuxt API in this file, so all of it is
|
|
3
|
+
// unit-tested — and the rendered-page harness in `scripts/verify-build.mjs`
|
|
4
|
+
// then proves what these descriptors actually become as bytes.
|
|
5
|
+
//
|
|
6
|
+
// 🔴 Nuxt is the one Pulse surface where the literal tag IS expressible.
|
|
7
|
+
// Astro's `injectScript` takes JavaScript and never HTML, so `pulse-astro`
|
|
8
|
+
// has to build the element in the DOM at runtime. Nuxt's head is a list of
|
|
9
|
+
// element descriptors that Unhead serialises, so this module contributes a
|
|
10
|
+
// real `<script src … defer data-domain …>` to the server-rendered HTML and
|
|
11
|
+
// ships no code of its own to the browser. Measured, not assumed — see
|
|
12
|
+
// RELEASING.md § "Compatibility is measured, not assumed".
|
|
13
|
+
//
|
|
14
|
+
// The option names deliberately match the `pulse-analytics` entry in
|
|
15
|
+
// `@nuxt/scripts` (`domain`, `apiUrl`, `trackScroll`, `trackOutbound`,
|
|
16
|
+
// `trackDownloads`). A Nuxt user can meet both, and two Pulse surfaces on one
|
|
17
|
+
// framework disagreeing about what an option is called is a support ticket
|
|
18
|
+
// waiting to happen.
|
|
19
|
+
export const SCRIPT_URL = "https://js.ciphera.net/script.js";
|
|
20
|
+
export const COMPANION_URL = "https://js.ciphera.net/script.interactions.js";
|
|
21
|
+
/** A registrable hostname: labels of letters, digits and hyphens, at least one
|
|
22
|
+
* dot, a letter-only TLD. Deliberately strict, and shared verbatim with
|
|
23
|
+
* `pulse-astro` so the two agree on what a domain is. */
|
|
24
|
+
const DOMAIN_RE = /^(?=.{1,253}$)(?!-)[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*\.[a-z]{2,63}$/;
|
|
25
|
+
/** Lower-case, drop a scheme, path, port and trailing dot. Keeps `www.` — the
|
|
26
|
+
* Pulse site may be registered either way and the user can override it. */
|
|
27
|
+
export function normalizeDomain(input) {
|
|
28
|
+
let s = input.trim().toLowerCase();
|
|
29
|
+
s = s.replace(/^[a-z][a-z0-9+.-]*:\/\//, "");
|
|
30
|
+
s = s.replace(/[/?#].*$/, "");
|
|
31
|
+
s = s.replace(/:.*$/, "");
|
|
32
|
+
s = s.replace(/\.$/, "");
|
|
33
|
+
return s;
|
|
34
|
+
}
|
|
35
|
+
export function isValidDomain(domain) {
|
|
36
|
+
return DOMAIN_RE.test(domain);
|
|
37
|
+
}
|
|
38
|
+
/** The hostname of a site URL, or null when it is unset or does not parse.
|
|
39
|
+
* Nuxt core has no `site` option; `nuxt-site-config` (which `@nuxtjs/sitemap`,
|
|
40
|
+
* `@nuxtjs/robots` and `@nuxtjs/seo` all install) adds `site.url`, and this is
|
|
41
|
+
* how we read it when it happens to be there. */
|
|
42
|
+
export function hostnameFromSite(site) {
|
|
43
|
+
if (!site)
|
|
44
|
+
return null;
|
|
45
|
+
try {
|
|
46
|
+
const host = new URL(String(site)).hostname.toLowerCase().replace(/\.$/, "");
|
|
47
|
+
return isValidDomain(host) ? host : null;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** Resolve the domain, saying WHERE it came from so the caller can log it.
|
|
54
|
+
* Never throws for a missing domain — a null domain is a working install that
|
|
55
|
+
* auto-detects — but an explicitly supplied domain that cannot be a hostname
|
|
56
|
+
* is a typo, and a typo there is a silent no-data install, which is worth a
|
|
57
|
+
* build error. */
|
|
58
|
+
export function resolveDomain(options, site) {
|
|
59
|
+
if (options.domain !== undefined) {
|
|
60
|
+
const d = normalizeDomain(options.domain);
|
|
61
|
+
if (!isValidDomain(d)) {
|
|
62
|
+
throw new Error(`[pulse] "${options.domain}" is not a valid domain. Pass the hostname your site is registered under in Pulse, e.g. pulse: { domain: "example.com" }.`);
|
|
63
|
+
}
|
|
64
|
+
return { domain: d, source: "option" };
|
|
65
|
+
}
|
|
66
|
+
const fromSite = hostnameFromSite(site);
|
|
67
|
+
if (fromSite)
|
|
68
|
+
return { domain: fromSite, source: "site" };
|
|
69
|
+
return { domain: null, source: "browser" };
|
|
70
|
+
}
|
|
71
|
+
/** 🔴 A presence flag must be `''` or absent, NEVER a boolean.
|
|
72
|
+
*
|
|
73
|
+
* Unhead normalises a `data-*` prop to a string before rendering, and its
|
|
74
|
+
* emptiness guard tests the boolean `false`, not the string `"false"`. So
|
|
75
|
+
* `'data-no-scroll': false` ships as `data-no-scroll="false"` — an attribute
|
|
76
|
+
* that is PRESENT. The tracker reads these with `hasAttribute()`, so a
|
|
77
|
+
* boolean `false` would switch the feature it names OFF: the exact inversion
|
|
78
|
+
* of what the option asked for. Measured on Unhead 3.4, and the reason this
|
|
79
|
+
* helper exists instead of a ternary at each call site. */
|
|
80
|
+
function flag(disabled) {
|
|
81
|
+
return disabled ? "" : undefined;
|
|
82
|
+
}
|
|
83
|
+
/** Normalise `companion` into the three booleans the second script needs, or
|
|
84
|
+
* null when there is to be no second script. */
|
|
85
|
+
export function resolveCompanion(companion) {
|
|
86
|
+
if (!companion)
|
|
87
|
+
return null;
|
|
88
|
+
if (companion === true)
|
|
89
|
+
return { clicks: true, copy: true, forms: true };
|
|
90
|
+
return {
|
|
91
|
+
clicks: companion.clicks !== false,
|
|
92
|
+
copy: companion.copy !== false,
|
|
93
|
+
forms: companion.forms !== false,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** The script descriptors to append to `app.head.script`, in order.
|
|
97
|
+
*
|
|
98
|
+
* The core script is always first. The companion, when asked for, is a second
|
|
99
|
+
* entry and never carries `data-domain` — it reads `window.pulse`, which the
|
|
100
|
+
* core script owns.
|
|
101
|
+
*
|
|
102
|
+
* ⚠️ `defer` is a boolean here and Unhead renders it as a BARE `defer`
|
|
103
|
+
* attribute, which is what we want. It is spelled as a boolean rather than
|
|
104
|
+
* the string `'defer'` because the string would ship `defer="defer"` — valid
|
|
105
|
+
* HTML, a different byte-string, and one this project asserts against a real
|
|
106
|
+
* rendered page rather than trusting. */
|
|
107
|
+
export function buildScripts(domain, options = {}) {
|
|
108
|
+
if (domain !== null && !isValidDomain(domain)) {
|
|
109
|
+
throw new Error(`[pulse] refusing to inject an invalid domain: ${domain}`);
|
|
110
|
+
}
|
|
111
|
+
const core = {
|
|
112
|
+
src: SCRIPT_URL,
|
|
113
|
+
defer: true,
|
|
114
|
+
"data-domain": domain ?? undefined,
|
|
115
|
+
"data-api": options.apiUrl ? String(options.apiUrl).replace(/\/+$/, "") : undefined,
|
|
116
|
+
"data-no-scroll": flag(options.trackScroll === false),
|
|
117
|
+
"data-no-outbound": flag(options.trackOutbound === false),
|
|
118
|
+
"data-no-downloads": flag(options.trackDownloads === false),
|
|
119
|
+
};
|
|
120
|
+
const scripts = [core];
|
|
121
|
+
const companion = resolveCompanion(options.companion);
|
|
122
|
+
if (companion) {
|
|
123
|
+
scripts.push({
|
|
124
|
+
src: COMPANION_URL,
|
|
125
|
+
defer: true,
|
|
126
|
+
"data-no-clicks": flag(!companion.clicks),
|
|
127
|
+
"data-no-copy": flag(!companion.copy),
|
|
128
|
+
"data-no-forms": flag(!companion.forms),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return scripts;
|
|
132
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ciphera-net/pulse-nuxt",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Add Pulse Analytics — privacy-first web analytics — to a Nuxt site with one module. No cookies, no personal data, under 3 KB.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"homepage": "https://pulse.ciphera.net",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/ciphera-net/pulse-nuxt.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": "https://github.com/ciphera-net/pulse-nuxt/issues",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"nuxt",
|
|
15
|
+
"nuxt-module",
|
|
16
|
+
"nuxt3",
|
|
17
|
+
"nuxt4",
|
|
18
|
+
"analytics",
|
|
19
|
+
"privacy",
|
|
20
|
+
"pulse",
|
|
21
|
+
"gdpr"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/module.d.ts",
|
|
26
|
+
"default": "./dist/module.js"
|
|
27
|
+
},
|
|
28
|
+
"./module.json": "./dist/module.json"
|
|
29
|
+
},
|
|
30
|
+
"main": "./dist/module.js",
|
|
31
|
+
"types": "./dist/module.d.ts",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc -p tsconfig.build.json && node scripts/emit-module-json.mjs",
|
|
39
|
+
"prepack": "npm run build",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"verify": "node scripts/verify-build.mjs"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"nuxt": "^3.0.0 || ^4.0.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@nuxt/schema": "^4.5.2",
|
|
49
|
+
"nuxt": "^4.5.2",
|
|
50
|
+
"playwright-core": "^1.63.0",
|
|
51
|
+
"typescript": "^5.9.2",
|
|
52
|
+
"vitest": "^4.0.18"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=20"
|
|
59
|
+
}
|
|
60
|
+
}
|