@huloglobal/vendure-plugin-visitor-analytics 0.8.2 → 0.8.3

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/CHANGELOG.md CHANGED
@@ -5,6 +5,32 @@ documented here. The format follows
5
5
  [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project
6
6
  adheres to [semantic versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.8.2] — 2026-07-04
9
+
10
+ ### Documentation
11
+ - README rewritten to cover every 0.8.x feature: the drop-in
12
+ `/ees/hulo.js` storefront helper, cart-abandonment configuration
13
+ and lifecycle, recommendation endpoints, search analytics,
14
+ journey drawer buffs. Includes a walkthrough of the
15
+ storefront-side `/cart/restore` route customers implement to
16
+ consume recovery links.
17
+ - Endpoints table split into Public (browser-safe, CORS-permissive)
18
+ vs Admin, with every 0.8.0-introduced endpoint marked inline.
19
+ - No runtime changes — bumped to ship the new README with the npm
20
+ tarball.
21
+
22
+ ## [0.8.1] — 2026-07-04
23
+
24
+ ### Added
25
+ - `/ees/hulo.js` — the plugin now serves a drop-in typed storefront
26
+ helper at this path. One `<script src>` tag and every event API
27
+ (`hulo.cartSnapshot`, `hulo.productView`, `hulo.search`,
28
+ `hulo.checkoutCompleted`, `hulo.restoreCart`) is available on
29
+ `window.hulo`. Handles batching, `sendBeacon` on unload, and
30
+ installs auto rage-click + dead-click detectors. Served with a
31
+ 10-minute browser TTL + 24-hour stale-while-revalidate and
32
+ permissive CORS so it works cross-origin from any storefront.
33
+
8
34
  ## [0.8.0] — 2026-07-04
9
35
 
10
36
  ### Added
@@ -230,6 +256,8 @@ adheres to [semantic versioning](https://semver.org/spec/v2.0.0.html).
230
256
  - Licence verification via `@huloglobal/vendure-licence-sdk` with
231
257
  revocation polling.
232
258
 
259
+ [0.8.2]: https://github.com/exceeded/vendure-plugin-visitor-analytics/releases/tag/v0.8.2
260
+ [0.8.1]: https://github.com/exceeded/vendure-plugin-visitor-analytics/releases/tag/v0.8.1
233
261
  [0.8.0]: https://github.com/exceeded/vendure-plugin-visitor-analytics/releases/tag/v0.8.0
234
262
  [0.7.0]: https://github.com/exceeded/vendure-plugin-visitor-analytics/releases/tag/v0.7.0
235
263
  [0.6.0]: https://github.com/exceeded/vendure-plugin-visitor-analytics/releases/tag/v0.6.0
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { VisitorEvent } from './visitor-event.entity';
7
7
  export { AbandonedCart, AbandonedCartStatus } from './abandoned-cart.entity';
8
8
  export { ProductCoView } from './product-co-view.entity';
9
9
  export { AbandonedCartService, CartSnapshotMeta, AbandonmentOptions, } from './abandoned-cart.service';
10
- export { RecommendationsService } from './recommendations.service';
10
+ export { RecommendationsService, RecommendedProduct } from './recommendations.service';
11
11
  export { SearchAnalyticsService } from './search-analytics.service';
12
12
  export { JourneyBuffsService } from './journey-buffs.service';
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EACH,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,GACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EACH,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,GACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,mCAAiF;AAAxE,gHAAA,sBAAsB,OAAA;AAC/B,uEAAoE;AAA3D,kIAAA,sBAAsB,OAAA;AAC/B,+DAAsD;AAA7C,oHAAA,YAAY,OAAA;AACrB,iEAA6E;AAApE,sHAAA,aAAa,OAAA;AACtB,mEAAyD;AAAhD,uHAAA,aAAa,OAAA;AACtB,mEAIkC;AAH9B,8HAAA,oBAAoB,OAAA;AAIxB,qEAAmE;AAA1D,iIAAA,sBAAsB,OAAA;AAC/B,uEAAoE;AAA3D,kIAAA,sBAAsB,OAAA;AAC/B,iEAA8D;AAArD,4HAAA,mBAAmB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,mCAAiF;AAAxE,gHAAA,sBAAsB,OAAA;AAC/B,uEAAoE;AAA3D,kIAAA,sBAAsB,OAAA;AAC/B,+DAAsD;AAA7C,oHAAA,YAAY,OAAA;AACrB,iEAA6E;AAApE,sHAAA,aAAa,OAAA;AACtB,mEAAyD;AAAhD,uHAAA,aAAa,OAAA;AACtB,mEAIkC;AAH9B,8HAAA,oBAAoB,OAAA;AAIxB,qEAAuF;AAA9E,iIAAA,sBAAsB,OAAA;AAC/B,uEAAoE;AAA3D,kIAAA,sBAAsB,OAAA;AAC/B,iEAA8D;AAArD,4HAAA,mBAAmB,OAAA"}
@@ -21,10 +21,7 @@ export declare class RecommendationsController {
21
21
  items?: undefined;
22
22
  } | {
23
23
  productId: number;
24
- items: {
25
- productId: number;
26
- score: number;
27
- }[];
24
+ items: import("./recommendations.service").RecommendedProduct[];
28
25
  error?: undefined;
29
26
  }>;
30
27
  /**
@@ -40,10 +37,7 @@ export declare class RecommendationsController {
40
37
  items?: undefined;
41
38
  } | {
42
39
  visitorId: string;
43
- items: {
44
- productId: number;
45
- score: number;
46
- }[];
40
+ items: import("./recommendations.service").RecommendedProduct[];
47
41
  error?: undefined;
48
42
  }>;
49
43
  /**
@@ -53,10 +47,7 @@ export declare class RecommendationsController {
53
47
  trending(chRaw?: string, hRaw?: string, lRaw?: string): Promise<{
54
48
  channelId: number;
55
49
  hours: number;
56
- items: {
57
- productId: number;
58
- views: number;
59
- }[];
50
+ items: import("./recommendations.service").RecommendedProduct[];
60
51
  }>;
61
52
  /**
62
53
  * Admin-only: manually kick the aggregation cron. Normally runs
@@ -1 +1 @@
1
- {"version":3,"file":"recommendations.controller.d.ts","sourceRoot":"","sources":["../src/recommendations.controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,cAAc,EAAqB,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE;;;;;;;GAOG;AACH,qBACa,yBAAyB;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,sBAAsB;IAE5D;;;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@@ -1,4 +1,19 @@
1
1
  import { TransactionalConnection } from '@vendure/core';
2
+ /** Row shape returned by every read-side endpoint. `productName` and
3
+ * `productSlug` are best-effort enrichments — they'll be null when
4
+ * the product has been deleted or when the `product_translation`
5
+ * table doesn't have a row for it in any language. */
6
+ export interface RecommendedProduct {
7
+ productId: number;
8
+ productName: string | null;
9
+ productSlug: string | null;
10
+ /** Numeric score returned by whichever endpoint produced this row.
11
+ * Callers should read `score` for co-view based responses and
12
+ * `views` for the raw trending endpoint — both are populated
13
+ * here so a UI can render one column regardless. */
14
+ score: number;
15
+ views: number;
16
+ }
2
17
  /**
3
18
  * Product recommendations driven by observed co-viewing behaviour.
4
19
  *
@@ -12,6 +27,13 @@ import { TransactionalConnection } from '@vendure/core';
12
27
  * data for the latter, and small stores don't have enough of it for
13
28
  * useful signals. Co-views come from every browsing session, so a
14
29
  * store with 1k daily visitors gets useful recs from day one.
30
+ *
31
+ * Every read-side response is enriched with the product NAME and
32
+ * SLUG (via a single bulk lookup against `product_translation`) so
33
+ * the admin UI + a first-party storefront can render "Windows Server
34
+ * 2022 Datacenter #42" without a second round-trip. Bare product ids
35
+ * are still returned so storefronts that prefer their own hydration
36
+ * path can ignore the extra fields.
15
37
  */
16
38
  export declare class RecommendationsService {
17
39
  private connection;
@@ -31,32 +53,33 @@ export declare class RecommendationsService {
31
53
  }>;
32
54
  /**
33
55
  * Read side: "customers who viewed X also viewed Y" for one
34
- * product, ordered by co-view score, capped at `limit`. Returns
35
- * bare product ids so the storefront can hydrate names / images
36
- * from its usual product-fetch path.
56
+ * product, ordered by co-view score, capped at `limit`.
37
57
  */
38
- alsoViewed(productId: number, channelId?: number, limit?: number): Promise<Array<{
39
- productId: number;
40
- score: number;
41
- }>>;
58
+ alsoViewed(productId: number, channelId?: number, limit?: number): Promise<RecommendedProduct[]>;
42
59
  /**
43
60
  * Personalised recommendations for a returning visitor: look at
44
61
  * the last N products they viewed, and rank co-viewed products by
45
62
  * combined score across those seed products (excluding the seeds
46
63
  * themselves).
47
64
  */
48
- personalRecommendations(visitorId: string, channelId?: number, limit?: number): Promise<Array<{
49
- productId: number;
50
- score: number;
51
- }>>;
65
+ personalRecommendations(visitorId: string, channelId?: number, limit?: number): Promise<RecommendedProduct[]>;
52
66
  /**
53
67
  * "Trending now" — most-viewed products in the last N hours.
54
68
  * Useful for a homepage rail; uses `product_view` events, so it
55
69
  * reflects real interest, not just search-console clicks.
56
70
  */
57
- trending(channelId?: number, sinceHours?: number, limit?: number): Promise<Array<{
58
- productId: number;
59
- views: number;
60
- }>>;
71
+ trending(channelId?: number, sinceHours?: number, limit?: number): Promise<RecommendedProduct[]>;
72
+ /**
73
+ * Bulk-fetch product names + slugs for a list of product ids in
74
+ * one round-trip. Prefers the English translation when a product
75
+ * has more than one, then falls back to whichever translation
76
+ * MariaDB returns first. Returns two maps keyed by productId; keys
77
+ * absent from the maps mean the product either doesn't exist any
78
+ * more or has no translation row at all (unusual — Vendure
79
+ * always creates one on product create).
80
+ */
81
+ private fetchProductInfo;
82
+ /** Apply the bulk name lookup to a set of raw rec rows. */
83
+ private enrichWithNames;
61
84
  }
62
85
  //# sourceMappingURL=recommendations.service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"recommendations.service.d.ts","sourceRoot":"","sources":["../src/recommendations.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAIxD;;;;;;;;;;;;;GAaG;AACH,qBACa,sBAAsB;IACnB,OAAO,CAAC,UAAU;gBAAV,UAAU,EAAE,uBAAuB;IAEvD;;;;;;;;;OASG;IACG,gBAAgB,CAAC,UAAU,SAAK,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAyDnE;;;;;OAKG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,SAAI,EAAE,KAAK,SAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC1E,SAAS,EAAE,MAAM,CAAC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,SAAI,EAAE,KAAK,SAAK,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAmC1G;;;;OAIG;IACG,QAAQ,CAAC,SAAS,SAAI,EAAE,UAAU,SAAK,EAAE,KAAK,SAAK,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAwBzF;;;;;;;;OAQG;YACW,gBAAgB;IAuC9B,2DAA2D;YAC7C,eAAe;CAehC"}
@@ -26,6 +26,13 @@ const loggerCtx = 'HuloRecommendationsService';
26
26
  * data for the latter, and small stores don't have enough of it for
27
27
  * useful signals. Co-views come from every browsing session, so a
28
28
  * store with 1k daily visitors gets useful recs from day one.
29
+ *
30
+ * Every read-side response is enriched with the product NAME and
31
+ * SLUG (via a single bulk lookup against `product_translation`) so
32
+ * the admin UI + a first-party storefront can render "Windows Server
33
+ * 2022 Datacenter #42" without a second round-trip. Bare product ids
34
+ * are still returned so storefronts that prefer their own hydration
35
+ * path can ignore the extra fields.
29
36
  */
30
37
  let RecommendationsService = class RecommendationsService {
31
38
  constructor(connection) {
@@ -94,9 +101,7 @@ let RecommendationsService = class RecommendationsService {
94
101
  }
95
102
  /**
96
103
  * Read side: "customers who viewed X also viewed Y" for one
97
- * product, ordered by co-view score, capped at `limit`. Returns
98
- * bare product ids so the storefront can hydrate names / images
99
- * from its usual product-fetch path.
104
+ * product, ordered by co-view score, capped at `limit`.
100
105
  */
101
106
  async alsoViewed(productId, channelId = 1, limit = 10) {
102
107
  const rows = await this.connection.rawConnection.query(`SELECT productIdB AS productId, viewsTogether AS score
@@ -104,7 +109,11 @@ let RecommendationsService = class RecommendationsService {
104
109
  WHERE productIdA = ? AND channelId = ?
105
110
  ORDER BY viewsTogether DESC, lastUpdated DESC
106
111
  LIMIT ?`, [productId, channelId, Math.min(Math.max(1, limit), 50)]);
107
- return rows.map(r => ({ productId: Number(r.productId), score: Number(r.score) }));
112
+ return this.enrichWithNames(rows.map(r => ({
113
+ productId: Number(r.productId),
114
+ score: Number(r.score),
115
+ views: Number(r.score),
116
+ })));
108
117
  }
109
118
  /**
110
119
  * Personalised recommendations for a returning visitor: look at
@@ -135,7 +144,11 @@ let RecommendationsService = class RecommendationsService {
135
144
  GROUP BY productIdB
136
145
  ORDER BY score DESC
137
146
  LIMIT ?`, [...seedIds, channelId, ...seedIds, Math.min(Math.max(1, limit), 50)]);
138
- return rows.map(r => ({ productId: Number(r.productId), score: Number(r.score) }));
147
+ return this.enrichWithNames(rows.map(r => ({
148
+ productId: Number(r.productId),
149
+ score: Number(r.score),
150
+ views: Number(r.score),
151
+ })));
139
152
  }
140
153
  /**
141
154
  * "Trending now" — most-viewed products in the last N hours.
@@ -156,7 +169,68 @@ let RecommendationsService = class RecommendationsService {
156
169
  HAVING productId > 0
157
170
  ORDER BY views DESC
158
171
  LIMIT ?`, [channelId, since, Math.min(Math.max(1, limit), 50)]);
159
- return rows.map(r => ({ productId: Number(r.productId), views: Number(r.views) }));
172
+ return this.enrichWithNames(rows.map(r => ({
173
+ productId: Number(r.productId),
174
+ score: Number(r.views),
175
+ views: Number(r.views),
176
+ })));
177
+ }
178
+ /**
179
+ * Bulk-fetch product names + slugs for a list of product ids in
180
+ * one round-trip. Prefers the English translation when a product
181
+ * has more than one, then falls back to whichever translation
182
+ * MariaDB returns first. Returns two maps keyed by productId; keys
183
+ * absent from the maps mean the product either doesn't exist any
184
+ * more or has no translation row at all (unusual — Vendure
185
+ * always creates one on product create).
186
+ */
187
+ async fetchProductInfo(ids) {
188
+ const names = new Map();
189
+ const slugs = new Map();
190
+ if (!ids.length)
191
+ return { names, slugs };
192
+ const placeholders = ids.map(() => '?').join(',');
193
+ try {
194
+ // `deletedAt IS NULL` on product so we don't surface
195
+ // soft-deleted products in the admin UI. Order by
196
+ // languageCode = 'en' DESC so English wins the tie for
197
+ // multi-locale stores; single-locale installs will
198
+ // naturally land on their only translation.
199
+ const rows = await this.connection.rawConnection.query(`SELECT pt.baseId AS productId, pt.name, pt.slug
200
+ FROM product_translation pt
201
+ JOIN product p ON p.id = pt.baseId AND p.deletedAt IS NULL
202
+ WHERE pt.baseId IN (${placeholders})
203
+ ORDER BY pt.baseId, pt.languageCode = 'en' DESC`, ids);
204
+ for (const r of rows) {
205
+ const id = Number(r.productId);
206
+ // First-write wins — the ORDER BY puts English first
207
+ // for each baseId, so we keep that one and skip
208
+ // subsequent translations.
209
+ if (!names.has(id))
210
+ names.set(id, String(r.name || ''));
211
+ if (!slugs.has(id))
212
+ slugs.set(id, String(r.slug || ''));
213
+ }
214
+ }
215
+ catch (e) {
216
+ // Never break the recs endpoint on a name-lookup failure —
217
+ // an admin can still see the id and click through to the
218
+ // Vendure catalog page manually.
219
+ common_1.Logger.warn(`Product info lookup failed: ${e === null || e === void 0 ? void 0 : e.message}`, loggerCtx);
220
+ }
221
+ return { names, slugs };
222
+ }
223
+ /** Apply the bulk name lookup to a set of raw rec rows. */
224
+ async enrichWithNames(rows) {
225
+ const ids = rows.map(r => r.productId);
226
+ const { names, slugs } = await this.fetchProductInfo(ids);
227
+ return rows.map(r => ({
228
+ productId: r.productId,
229
+ productName: names.get(r.productId) || null,
230
+ productSlug: slugs.get(r.productId) || null,
231
+ score: r.score,
232
+ views: r.views,
233
+ }));
160
234
  }
161
235
  };
162
236
  exports.RecommendationsService = RecommendationsService;
@@ -1 +1 @@
1
- {"version":3,"file":"recommendations.service.js","sourceRoot":"","sources":["../src/recommendations.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAoD;AACpD,wCAAwD;AAExD,MAAM,SAAS,GAAG,4BAA4B,CAAC;AAE/C;;;;;;;;;;;;;GAaG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAC/B,YAAoB,UAAmC;QAAnC,eAAU,GAAV,UAAU,CAAyB;IAAG,CAAC;IAE3D;;;;;;;;;OASG;IACH,KAAK,CAAC,gBAAgB,CAAC,UAAU,GAAG,EAAE;QAClC,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC;QAC3C,MAAM,K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AD,CAAC,uBAAD,CAAC,CAAE,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;QACxE,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,2DAA2D;IACnD,KAAK,CAAC,eAAe,CAAC,IAI5B;QACE,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACvC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAC1D,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAClB,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,IAAI;YAC3C,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,IAAI;YAC3C,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,KAAK,EAAE,CAAC,CAAC,KAAK;SACjB,CAAC,CAAC,CAAC;IACR,CAAC;CACJ,CAAA;AAhOY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;qCAEuB,8BAAuB;GAD9C,sBAAsB,CAgOlC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huloglobal/vendure-plugin-visitor-analytics",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "Full-funnel visitor analytics for Vendure storefronts \u2014 pageviews, time-on-page, session journey, exit pages, funnel drop-off, and per-visitor profile drawer with parsed user-agent + MaxMind GeoLite2 enrichment. Auto-issues visitor + session cookies on first request; logs guest and signed-in events against the same visitor id so the journey survives login.",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "author": "Wayne Garrison <wayne@garrison.me.uk>",