@smileline/astro 0.1.0 → 0.2.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 CHANGED
@@ -48,7 +48,12 @@ never sent to browsers.
48
48
  Start a test in Smileline (Ads → A/B tests) by naming the page to test
49
49
  (version A) and another page of your site to show instead (version B).
50
50
  Visitors of A's URL then see A or B, half each, and keep seeing the same
51
- version. Results are judged on bookings.
51
+ version. You pick what decides the winner: bookings (the default), leads,
52
+ calls and WhatsApp taps, or a step both versions have.
53
+
54
+ Every visitor is counted, whatever they answer to a cookie banner:
55
+ Smileline counts them with an anonymous code made from their connection and
56
+ browser that changes every month, and nothing is stored on their device.
52
57
 
53
58
  Requirements:
54
59
 
@@ -63,8 +68,8 @@ Requirements:
63
68
  What the integration does on a tested page:
64
69
 
65
70
  - It never sets a cookie. A visitor whose browser has stored a Smileline
66
- visitor id is assigned from it; anyone else at random, and the script
67
- then stores an id that keeps them on the version they saw.
71
+ visitor id is assigned from it; anyone else from their address and
72
+ browser, so they keep seeing the same version while those stay the same.
68
73
  - It adds `<meta name="smileline-test">` to the page, which the script
69
74
  reports with the page view.
70
75
  - A canonical link or `og:url` on B that points at B is pointed at A, and
@@ -72,6 +77,34 @@ What the integration does on a tested page:
72
77
  - If B fails to render, the visitor gets A.
73
78
  - Once you pick a winner, everyone gets it, until you archive the test.
74
79
 
80
+ ## Steps
81
+
82
+ The script measures on its own when a visitor sees a form, starts filling
83
+ it in, sends it, or taps your phone number or WhatsApp. Name any other step
84
+ your page has — each question of a quiz, a "Book now" button — and the
85
+ test shows how far each version's visitors got:
86
+
87
+ ```html
88
+ <!-- counted when it's clicked -->
89
+ <button data-sl-step="Book now clicked">Book now</button>
90
+ ```
91
+
92
+ ```js
93
+ // or from your own code
94
+ window.sl?.("step", "What is your age?");
95
+ ```
96
+
97
+ A lead sent from a tested page counts for the version it was on. If your
98
+ form posts to your own server and you forward the lead to Smileline, add
99
+ the page's version to the `_sl` attribution you send:
100
+
101
+ ```js
102
+ const test = document
103
+ .querySelector('meta[name="smileline-test"]')
104
+ ?.getAttribute("content");
105
+ // _sl: JSON.stringify({ ..., ...(test ? { test } : {}) })
106
+ ```
107
+
75
108
  ## Without an adapter
76
109
 
77
110
  A fully static build still gets the script, loaded straight from
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { writeFileSync as e } from "node:fs";
2
- //#region src/index.ts
2
+ // src/index.ts
3
3
  var t = {
4
4
  eu: {
5
5
  api: "https://api-eu.smileline.io",
@@ -66,5 +66,4 @@ function a(n) {
66
66
  } }
67
67
  };
68
68
  }
69
- //#endregion
70
69
  export { a as default };
package/dist/runtime.d.ts CHANGED
@@ -15,12 +15,14 @@ export interface ProxyOptions extends RuntimeOptions {
15
15
  /** The widget origin of the practice's region (the script files). */
16
16
  widgetOrigin: string;
17
17
  }
18
- /** The part of Astro's APIContext the middleware uses. */
18
+ /** The part of Astro's APIContext the middleware uses. `clientAddress`
19
+ * throws where the adapter cannot tell. */
19
20
  export interface MiddlewareContext {
20
21
  request: Request;
21
22
  url: URL;
22
23
  isPrerendered: boolean;
23
24
  locals: object;
25
+ readonly clientAddress: string;
24
26
  rewrite(payload: string | URL | Request): Promise<Response>;
25
27
  }
26
28
  export type MiddlewareNext = (payload?: string | URL | Request) => Promise<Response>;
package/dist/runtime.js CHANGED
@@ -13,8 +13,7 @@ function n(n, r) {
13
13
  function r(e, t) {
14
14
  return `${e}:${t}`;
15
15
  }
16
- //#endregion
17
- //#region ../tracking-core/src/envelope.ts
16
+ // ../tracking-core/src/envelope.ts
18
17
  function i(e) {
19
18
  let t = {};
20
19
  for (let n of e.split(";")) {
@@ -30,9 +29,8 @@ function i(e) {
30
29
  }
31
30
  return t;
32
31
  }
33
- //#endregion
34
- //#region ../tracking-core/src/state.ts
35
- var a = "X-Smileline-Server-Key", o = "X-Smileline-Proxy", s = 6e4, c = 256 * 1024, l = [
32
+ // ../tracking-core/src/state.ts
33
+ var a = "X-Smileline-Server-Key", o = "X-Smileline-Proxy", s = 6e4, c = 262144, l = [
36
34
  "CDN-Cache-Control",
37
35
  "Cloudflare-CDN-Cache-Control",
38
36
  "Vercel-CDN-Cache-Control",
@@ -51,9 +49,11 @@ function p(e, t) {
51
49
  function m() {
52
50
  return (crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(1))[0] ?? 0) & 1 ? "b" : "a";
53
51
  }
54
- function h(e, t) {
55
- let r = i(t.headers.get("cookie") ?? "")._sl_vid;
56
- return r ? n(r, e) : m();
52
+ function h(e, t, r) {
53
+ let a = i(t.headers.get("cookie") ?? "")._sl_vid;
54
+ if (a) return n(a, e);
55
+ let o = t.headers.get("user-agent");
56
+ return r !== null && o ? n(`anon:${r}|${o}`, e) : m();
57
57
  }
58
58
  function g(e) {
59
59
  let t = Reflect.get(e, "cfContext");
@@ -209,11 +209,8 @@ function j(e, t, n) {
209
209
  function M(e) {
210
210
  let t = e.now ?? Date.now, n = `${e.apiOrigin}/site/${encodeURIComponent(e.siteKey)}/server-config`, i = [], o = -Infinity, c = -Infinity, d = async () => {
211
211
  let r = e.serverKey();
212
- if (!r) {
213
- i = [], o = t();
214
- return;
215
- }
216
- try {
212
+ if (!r) i = [], o = t();
213
+ else try {
217
214
  let s = await (e.fetch ?? fetch)(n, {
218
215
  headers: {
219
216
  [a]: r,
@@ -273,7 +270,7 @@ function M(e) {
273
270
  return t.append("X-Robots-Tag", "noindex"), j(e, t, e.body);
274
271
  }
275
272
  let l = c.status === "running";
276
- if ((l ? h(c.id, i) : c.winner) !== "b") {
273
+ if ((l ? h(c.id, i, U(t)) : c.winner) !== "b") {
277
274
  let e = await n();
278
275
  return l ? _(e, c, r(c.id, "a"), a) : e;
279
276
  }
@@ -293,11 +290,11 @@ var N = /* @__PURE__ */ new Set([
293
290
  "sl-tracking.js",
294
291
  "sl-insights.js"
295
292
  ]), P = /* @__PURE__ */ new Map([
296
- ["forms", 64 * 1024],
297
- ["dni", 64 * 1024],
298
- ["events", 32 * 1024],
299
- ["recording", 16 * 1024 * 1024]
300
- ]), F = 256 * 1024, I = 10747904, L = 25e3, R = [
293
+ ["forms", 65536],
294
+ ["dni", 65536],
295
+ ["events", 32768],
296
+ ["recording", 16777216]
297
+ ]), F = 262144, I = 10747904, L = 25e3, R = [
301
298
  "content-type",
302
299
  "accept",
303
300
  "origin",
@@ -402,5 +399,4 @@ function G(e) {
402
399
  });
403
400
  };
404
401
  }
405
- //#endregion
406
402
  export { M as createMiddleware, G as createProxy };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smileline/astro",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Smileline for Astro sites: the tracking script served from your own domain, and A/B page tests split on the server.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -23,7 +23,7 @@
23
23
  }
24
24
  },
25
25
  "peerDependencies": {
26
- "astro": "^7.0.0"
26
+ "astro": "^6.0.0 || ^7.0.0"
27
27
  },
28
28
  "types": "./dist/index.d.ts"
29
29
  }