@nextanalytica/tag 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/README.md +49 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -127,6 +127,54 @@ Each event is `order` (with `value`, `currency`, `ref`) or `custom` (with `name`
127
127
  `user_id` is your own user id, the same one you pass to `identify`. Up to 50 events a request. They belong to no visit:
128
128
  your agent sees them as events, and as conversions under the channel "Server".
129
129
 
130
+ ## Returning visitors in Safari: `@nextanalytica/tag/server`
131
+
132
+ After a visitor's yes, the tag keeps one id for them, `na_id`, in a cookie on your site's own domain, so `www.` and
133
+ `app.` are one visitor. Safari keeps a cookie that a script writes for 7 days at most, so a visitor who comes back
134
+ after two weeks counts as new. A cookie your own server sets keeps its full time: `renew` renews `na_id` on every page
135
+ your server sends, for 13 months. It only renews an id the tag already made after consent, never sets one of its own,
136
+ and marks it with `na_s`, so the tag leaves the cookie to your server.
137
+
138
+ Next.js, `middleware.ts`:
139
+
140
+ ```ts
141
+ import { NextResponse, type NextRequest } from "next/server";
142
+ import { renew } from "@nextanalytica/tag/server";
143
+
144
+ export function middleware(req: NextRequest) {
145
+ const res = NextResponse.next();
146
+ renew(req, res.headers);
147
+ return res;
148
+ }
149
+ ```
150
+
151
+ SvelteKit, `src/hooks.server.ts`:
152
+
153
+ ```ts
154
+ import { renew } from "@nextanalytica/tag/server";
155
+
156
+ export const handle = async ({ event, resolve }) => {
157
+ const res = await resolve(event);
158
+ renew(event.request, res.headers);
159
+ return res;
160
+ };
161
+ ```
162
+
163
+ Any other server: `renewCookies(cookieHeader, host)` returns the `Set-Cookie` values to add to a page's response.
164
+
165
+ ```js
166
+ import { renewCookies } from "@nextanalytica/tag/server";
167
+
168
+ app.use((req, res, next) => {
169
+ if (req.accepts("html")) res.append("Set-Cookie", renewCookies(req.headers.cookie, req.headers.host));
170
+ next();
171
+ });
172
+ ```
173
+
174
+ `renew` acts on pages only, not on images, scripts or API calls. Pass `{ secure: false }` only for plain `http://`
175
+ on your own machine. The cookie must come from the server that answers for your site's address: Safari still keeps a
176
+ cookie for 7 days when it comes from a server at another company's address.
177
+
130
178
  ## Content Security Policy
131
179
 
132
180
  The tag loads its scripts from `https://t.nextanalytica.app` and sends events back to the same host, so a site with a
@@ -151,4 +199,5 @@ Every component and `init` take the same options:
151
199
  | `cookieless: true` | Count without asking for consent, and keep nothing on the device |
152
200
  | `vitals: "all"` | Measure Web Vitals on every page view instead of a sample |
153
201
  | `search: ["q"]` | The URL parameters that hold your site search's query |
202
+ | `domains: ["pay.example"]` | Your other domains in this project: after consent, a link to one of them carries the visitor (two minutes) |
154
203
  | `api_host` | Where `t.js` is served from, if not `https://t.nextanalytica.app` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextanalytica/tag",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "The nextanalytica tag for JavaScript apps: one component per framework, the same t.js underneath.",
5
5
  "license": "MIT",
6
6
  "type": "module",