@connextar/house 0.23.3 → 0.24.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 +33 -10
- package/dist/analytics/browser.js +2 -2
- package/dist/analytics/posthog-extensions.d.ts +19 -0
- package/dist/analytics/posthog-extensions.d.ts.map +1 -0
- package/dist/analytics/posthog-extensions.js +19 -0
- package/dist/analytics/posthog-extensions.js.map +1 -0
- package/dist/house.css +19 -0
- package/package.json +13 -2
- package/src/analytics/browser.ts +2 -2
- package/src/analytics/posthog-extensions.ts +19 -0
- package/src/styles/house.css +19 -0
package/README.md
CHANGED
|
@@ -3367,15 +3367,16 @@ their code. AltEd did none of the three. That was the open finding
|
|
|
3367
3367
|
consent at all, and MAS and Canisters render GTM on every page. senco imports
|
|
3368
3368
|
posthog-js and never initialises it.
|
|
3369
3369
|
|
|
3370
|
-
| Entry point
|
|
3371
|
-
|
|
|
3372
|
-
| `@connextar/house/analytics`
|
|
3373
|
-
| `/analytics/client`
|
|
3374
|
-
| `/analytics/react`
|
|
3375
|
-
| `/analytics/server`
|
|
3370
|
+
| Entry point | What | Imports |
|
|
3371
|
+
| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
|
|
3372
|
+
| `@connextar/house/analytics` | `defineAnalytics`, `createRedactor`, `ingestProxy`, `logsSink`, the marker attributes | nothing |
|
|
3373
|
+
| `/analytics/client` | `createBrowserAnalytics`: consent, GTM, PostHog's config, the gate, replay | nothing; the app's posthog-js is handed in |
|
|
3374
|
+
| `/analytics/react` | `<SiteAnalytics>`, `<ConsentKnownScript>`, `<CookieSettingsButton>`, `<RecordingAllowed>`, `<NotMeasured>`, `useAnalyticsConsent` | React, `next/navigation.js` |
|
|
3375
|
+
| `/analytics/server` | `createServerAnalytics` (error reports, events), `measurementProtocol` | nothing; posthog-node and `after` are handed in |
|
|
3376
|
+
| `/analytics/posthog-extensions` | imported for its effect, before `posthog.init`: posthog-js's two lazy-loaded scripts, bundled | the app's posthog-js (optional peer) |
|
|
3376
3377
|
|
|
3377
3378
|
The server half imports no browser package, and in fact no package at all.
|
|
3378
|
-
`entry-points.test.ts` holds all
|
|
3379
|
+
`entry-points.test.ts` holds all five against the build, so a server route can
|
|
3379
3380
|
never pull posthog-js into its bundle and the PostHog versions stay the app's.
|
|
3380
3381
|
`browser.test.ts` and `server.test.ts` check the structural types against
|
|
3381
3382
|
posthog-js 1.438 and posthog-node 5.56 themselves.
|
|
@@ -3403,6 +3404,7 @@ export const browser = createBrowserAnalytics(analytics);
|
|
|
3403
3404
|
|
|
3404
3405
|
// instrumentation-client.ts
|
|
3405
3406
|
import posthog from "posthog-js";
|
|
3407
|
+
import "@connextar/house/analytics/posthog-extensions"; // before init: no fetch of /ingest/static/*.js on any page
|
|
3406
3408
|
if (process.env.NEXT_PUBLIC_POSTHOG_KEY) posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, browser.posthogConfig());
|
|
3407
3409
|
|
|
3408
3410
|
// components/analytics/site-analytics.tsx — the app's own client wrapper, since a definition holding functions
|
|
@@ -3581,9 +3583,23 @@ databaseHooks: { user: { create: { after: async (_user, context) => ga4.recordSi
|
|
|
3581
3583
|
| senco | posthog-js imported, never initialised; server events with a viewing-as gate, no redaction | the server half (events redacted, its gate kept, error reports). The browser half only if the owner wants public-page measurement. |
|
|
3582
3584
|
|
|
3583
3585
|
Each app's own cookie card in Settings keeps its UI primitives and takes
|
|
3584
|
-
`useAnalyticsConsent(browser)`. The
|
|
3585
|
-
`
|
|
3586
|
-
|
|
3586
|
+
`useAnalyticsConsent(browser)`. The CSS that keeps the card off screen before
|
|
3587
|
+
first paint ships in `house.css` since 0.24.0: once an answer is stored
|
|
3588
|
+
(`html[data-consent-known]`), and on a page carrying `data-analytics-private`
|
|
3589
|
+
or `data-viewing-as`, which an address alone would call public. An app that
|
|
3590
|
+
copied the first rule into its own stylesheet deletes it. An app's own
|
|
3591
|
+
`renderCard` puts `data-cookie-card` on its root, and `data-reopened` while
|
|
3592
|
+
reopened, or none of it applies.
|
|
3593
|
+
|
|
3594
|
+
**posthog-js's lazy scripts.** posthog-js fetches the exception autocapture
|
|
3595
|
+
(error reports) and the dead-clicks autocapture (heatmaps, whatever
|
|
3596
|
+
`capture_dead_clicks` says) from `<api_host>/static/` on every page, unless
|
|
3597
|
+
they are already registered on `window.__PosthogExtensions__`. Import
|
|
3598
|
+
`@connextar/house/analytics/posthog-extensions` before `posthog.init` and they
|
|
3599
|
+
come from the app's bundle instead: a `<NotMeasured />` page then makes no
|
|
3600
|
+
request to the relay at all, and nothing depends on the relay serving scripts.
|
|
3601
|
+
PharmaLine found it in 0.27.5. The package's `sideEffects` names the file, so a
|
|
3602
|
+
bundler does not drop the bare import. The env names are already the same
|
|
3587
3603
|
everywhere: `NEXT_PUBLIC_POSTHOG_KEY`, `NEXT_PUBLIC_POSTHOG_HOST`,
|
|
3588
3604
|
`NEXT_PUBLIC_GTM_ID`, `GA4_MEASUREMENT_ID`, `GA4_API_SECRET`.
|
|
3589
3605
|
|
|
@@ -3747,6 +3763,13 @@ mounted`. Inline the package so vite transforms it:
|
|
|
3747
3763
|
factory silently replaces the first, and an assertion on `router.refresh` then
|
|
3748
3764
|
watches a spy nothing ever called — a test that passes while proving nothing.
|
|
3749
3765
|
Build the spies once at module scope and return those from both factories.
|
|
3766
|
+
- **Check that the relay's logs route is committed.** A `.gitignore` with a
|
|
3767
|
+
bare `logs` rule (the usual debug-logs line) also ignores
|
|
3768
|
+
`app/ingest/i/v1/logs/route.ts`. Canisters and FB Web shipped without it, and
|
|
3769
|
+
the catch-all relay then answered `/ingest/i/v1/logs` with a 404. Add
|
|
3770
|
+
`!app/ingest/i/v1/logs/` after the rule, and confirm with
|
|
3771
|
+
`git ls-files app/ingest`. `git status` shows such a file as ignored, not
|
|
3772
|
+
untracked, so it is easy to miss.
|
|
3750
3773
|
- **A locale-aware app inlines its i18n package too.** `next-intl`'s
|
|
3751
3774
|
`createNavigation` also imports `next/navigation` extensionlessly, so with only
|
|
3752
3775
|
the package inlined the whole suite fails to load: `inline: [/@connextar\/house/, /next-intl/]`.
|
|
@@ -48,8 +48,8 @@ export function createBrowserAnalytics(analytics, options = {}) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
* Set before paint, so a returning visitor never sees the card flash: an inline `<script>` in `<head>`.
|
|
52
|
-
*
|
|
51
|
+
* Set before paint, so a returning visitor never sees the card flash: an inline `<script>` in `<head>`.
|
|
52
|
+
* `house.css` hides `html[data-consent-known] [data-cookie-card]:not([data-reopened])`.
|
|
53
53
|
*/
|
|
54
54
|
const consentKnownScript = `(function(){var d=document.documentElement,g=navigator.globalPrivacyControl===true,v=null;try{v=localStorage.getItem(${JSON.stringify(analytics.consentKey)})}catch(e){}if(g||v==="granted"||v==="denied")d.setAttribute(${JSON.stringify(CONSENT_KNOWN_ATTRIBUTE)},"")})()`;
|
|
55
55
|
/**
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@connextar/house/analytics/posthog-extensions` — import it for its effect, once, before `posthog.init`, in
|
|
3
|
+
* `instrumentation-client.ts`:
|
|
4
|
+
*
|
|
5
|
+
* import { posthog } from "posthog-js";
|
|
6
|
+
* import "@connextar/house/analytics/posthog-extensions";
|
|
7
|
+
*
|
|
8
|
+
* posthog-js lazy-loads two pieces through `<api_host>/static/…` on every page — the exception autocapture behind
|
|
9
|
+
* error reports, and the dead-clicks autocapture heatmaps rely on, enabled whatever `capture_dead_clicks` says —
|
|
10
|
+
* unless they are already registered on `window.__PosthogExtensions__`. These two imports register them from the
|
|
11
|
+
* app's bundle, so a page that must never be measured (`<NotMeasured />`) makes no request to the PostHog relay at
|
|
12
|
+
* all. Found in PharmaLine 0.27.5: a platform admin's changelog still fetched both scripts from `/ingest/static/`.
|
|
13
|
+
*
|
|
14
|
+
* They are the app's posthog-js (an optional peer), so the extensions always match the version that loads them.
|
|
15
|
+
*/
|
|
16
|
+
import "posthog-js/dist/exception-autocapture.js";
|
|
17
|
+
import "posthog-js/dist/dead-clicks-autocapture.js";
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=posthog-extensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posthog-extensions.d.ts","sourceRoot":"","sources":["../../src/analytics/posthog-extensions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,0CAA0C,CAAC;AAClD,OAAO,4CAA4C,CAAC;AAEpD,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@connextar/house/analytics/posthog-extensions` — import it for its effect, once, before `posthog.init`, in
|
|
3
|
+
* `instrumentation-client.ts`:
|
|
4
|
+
*
|
|
5
|
+
* import { posthog } from "posthog-js";
|
|
6
|
+
* import "@connextar/house/analytics/posthog-extensions";
|
|
7
|
+
*
|
|
8
|
+
* posthog-js lazy-loads two pieces through `<api_host>/static/…` on every page — the exception autocapture behind
|
|
9
|
+
* error reports, and the dead-clicks autocapture heatmaps rely on, enabled whatever `capture_dead_clicks` says —
|
|
10
|
+
* unless they are already registered on `window.__PosthogExtensions__`. These two imports register them from the
|
|
11
|
+
* app's bundle, so a page that must never be measured (`<NotMeasured />`) makes no request to the PostHog relay at
|
|
12
|
+
* all. Found in PharmaLine 0.27.5: a platform admin's changelog still fetched both scripts from `/ingest/static/`.
|
|
13
|
+
*
|
|
14
|
+
* They are the app's posthog-js (an optional peer), so the extensions always match the version that loads them.
|
|
15
|
+
*/
|
|
16
|
+
import "posthog-js/dist/exception-autocapture.js";
|
|
17
|
+
import "posthog-js/dist/dead-clicks-autocapture.js";
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=posthog-extensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posthog-extensions.js","sourceRoot":"","sources":["../../src/analytics/posthog-extensions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,0CAA0C,CAAC;AAClD,OAAO,4CAA4C,CAAC;AAEpD,OAAO,EAAE,CAAC"}
|
package/dist/house.css
CHANGED
|
@@ -361,6 +361,25 @@
|
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
+
/* ── The cookie card (`@connextar/house/analytics/react`) ──
|
|
365
|
+
|
|
366
|
+
The card is in the server HTML, before anyone knows the answer, so CSS keeps
|
|
367
|
+
it off screen where it must not be asked — before first paint, with no flash:
|
|
368
|
+
|
|
369
|
+
- an answer is already stored: `ConsentKnownScript` marks <html> in <head>;
|
|
370
|
+
- the page is never measured (`<NotMeasured />`), or is viewed as someone
|
|
371
|
+
(`ViewingAsBanner`): the address alone says "public", so the card would
|
|
372
|
+
otherwise ask on an administrator's changelog. Found in PharmaLine 0.27.5.
|
|
373
|
+
|
|
374
|
+
"Cookie settings" reopens it anywhere (`data-reopened`). Outside any layer,
|
|
375
|
+
so a card whose own classes set `display` (an app's `renderCard`) is still
|
|
376
|
+
hidden. */
|
|
377
|
+
html[data-consent-known] [data-cookie-card]:not([data-reopened]),
|
|
378
|
+
html:has([data-analytics-private]) [data-cookie-card]:not([data-reopened]),
|
|
379
|
+
html:has([data-viewing-as]) [data-cookie-card]:not([data-reopened]) {
|
|
380
|
+
display: none;
|
|
381
|
+
}
|
|
382
|
+
|
|
364
383
|
/* Keyframes must sit outside @layer. */
|
|
365
384
|
@keyframes house-spin {
|
|
366
385
|
to {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@connextar/house",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "The pieces every app we build needs and none of them should own a copy of.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
"url": "git+https://github.com/Connextar/cx-house.git"
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
|
-
"sideEffects":
|
|
11
|
+
"sideEffects": [
|
|
12
|
+
"**/*.css",
|
|
13
|
+
"./dist/analytics/posthog-extensions.js"
|
|
14
|
+
],
|
|
12
15
|
"files": [
|
|
13
16
|
"dist",
|
|
14
17
|
"docs",
|
|
@@ -137,6 +140,10 @@
|
|
|
137
140
|
"types": "./dist/analytics/react-index.d.ts",
|
|
138
141
|
"default": "./dist/analytics/react-index.js"
|
|
139
142
|
},
|
|
143
|
+
"./analytics/posthog-extensions": {
|
|
144
|
+
"types": "./dist/analytics/posthog-extensions.d.ts",
|
|
145
|
+
"default": "./dist/analytics/posthog-extensions.js"
|
|
146
|
+
},
|
|
140
147
|
"./analytics/server": {
|
|
141
148
|
"types": "./dist/analytics/server-index.d.ts",
|
|
142
149
|
"default": "./dist/analytics/server-index.js"
|
|
@@ -213,6 +220,7 @@
|
|
|
213
220
|
"@anthropic-ai/sdk": ">=0.122.0",
|
|
214
221
|
"next": "^16.0.0",
|
|
215
222
|
"openai": ">=7.10.0",
|
|
223
|
+
"posthog-js": ">=1.200.0",
|
|
216
224
|
"react": "^19.0.0",
|
|
217
225
|
"react-dom": "^19.0.0",
|
|
218
226
|
"react-hook-form": "^7.60.0",
|
|
@@ -231,6 +239,9 @@
|
|
|
231
239
|
"openai": {
|
|
232
240
|
"optional": true
|
|
233
241
|
},
|
|
242
|
+
"posthog-js": {
|
|
243
|
+
"optional": true
|
|
244
|
+
},
|
|
234
245
|
"zod": {
|
|
235
246
|
"optional": true
|
|
236
247
|
}
|
package/src/analytics/browser.ts
CHANGED
|
@@ -110,8 +110,8 @@ export function createBrowserAnalytics(analytics: Analytics, options: BrowserAna
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
|
-
* Set before paint, so a returning visitor never sees the card flash: an inline `<script>` in `<head>`.
|
|
114
|
-
*
|
|
113
|
+
* Set before paint, so a returning visitor never sees the card flash: an inline `<script>` in `<head>`.
|
|
114
|
+
* `house.css` hides `html[data-consent-known] [data-cookie-card]:not([data-reopened])`.
|
|
115
115
|
*/
|
|
116
116
|
const consentKnownScript = `(function(){var d=document.documentElement,g=navigator.globalPrivacyControl===true,v=null;try{v=localStorage.getItem(${JSON.stringify(
|
|
117
117
|
analytics.consentKey,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@connextar/house/analytics/posthog-extensions` — import it for its effect, once, before `posthog.init`, in
|
|
3
|
+
* `instrumentation-client.ts`:
|
|
4
|
+
*
|
|
5
|
+
* import { posthog } from "posthog-js";
|
|
6
|
+
* import "@connextar/house/analytics/posthog-extensions";
|
|
7
|
+
*
|
|
8
|
+
* posthog-js lazy-loads two pieces through `<api_host>/static/…` on every page — the exception autocapture behind
|
|
9
|
+
* error reports, and the dead-clicks autocapture heatmaps rely on, enabled whatever `capture_dead_clicks` says —
|
|
10
|
+
* unless they are already registered on `window.__PosthogExtensions__`. These two imports register them from the
|
|
11
|
+
* app's bundle, so a page that must never be measured (`<NotMeasured />`) makes no request to the PostHog relay at
|
|
12
|
+
* all. Found in PharmaLine 0.27.5: a platform admin's changelog still fetched both scripts from `/ingest/static/`.
|
|
13
|
+
*
|
|
14
|
+
* They are the app's posthog-js (an optional peer), so the extensions always match the version that loads them.
|
|
15
|
+
*/
|
|
16
|
+
import "posthog-js/dist/exception-autocapture.js";
|
|
17
|
+
import "posthog-js/dist/dead-clicks-autocapture.js";
|
|
18
|
+
|
|
19
|
+
export {};
|
package/src/styles/house.css
CHANGED
|
@@ -361,6 +361,25 @@
|
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
+
/* ── The cookie card (`@connextar/house/analytics/react`) ──
|
|
365
|
+
|
|
366
|
+
The card is in the server HTML, before anyone knows the answer, so CSS keeps
|
|
367
|
+
it off screen where it must not be asked — before first paint, with no flash:
|
|
368
|
+
|
|
369
|
+
- an answer is already stored: `ConsentKnownScript` marks <html> in <head>;
|
|
370
|
+
- the page is never measured (`<NotMeasured />`), or is viewed as someone
|
|
371
|
+
(`ViewingAsBanner`): the address alone says "public", so the card would
|
|
372
|
+
otherwise ask on an administrator's changelog. Found in PharmaLine 0.27.5.
|
|
373
|
+
|
|
374
|
+
"Cookie settings" reopens it anywhere (`data-reopened`). Outside any layer,
|
|
375
|
+
so a card whose own classes set `display` (an app's `renderCard`) is still
|
|
376
|
+
hidden. */
|
|
377
|
+
html[data-consent-known] [data-cookie-card]:not([data-reopened]),
|
|
378
|
+
html:has([data-analytics-private]) [data-cookie-card]:not([data-reopened]),
|
|
379
|
+
html:has([data-viewing-as]) [data-cookie-card]:not([data-reopened]) {
|
|
380
|
+
display: none;
|
|
381
|
+
}
|
|
382
|
+
|
|
364
383
|
/* Keyframes must sit outside @layer. */
|
|
365
384
|
@keyframes house-spin {
|
|
366
385
|
to {
|