@activescott/analytics 0.2.0 → 0.2.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.
package/README.md
CHANGED
|
@@ -49,6 +49,32 @@ Identify by stable id only — never pass emails, phone numbers, or other PII in
|
|
|
49
49
|
|
|
50
50
|
With no `apiKey` the provider renders children with zero PostHog code paths.
|
|
51
51
|
|
|
52
|
+
### Sibling mounting (dynamic import without remounting the page)
|
|
53
|
+
|
|
54
|
+
If you code-split the analytics module (so disabled installs pay no bundle
|
|
55
|
+
cost), do not wrap the app in the provider once the import resolves —
|
|
56
|
+
swapping a wrapper in around mounted UI remounts the whole subtree. Mount it
|
|
57
|
+
childless as a sibling instead; pageviews, identification, and the shared
|
|
58
|
+
posthog-js singleton (which custom events capture through) all work the same:
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
function Analytics({ posthogKey }: { posthogKey: string }) {
|
|
62
|
+
const [analyticsModule, setAnalyticsModule] = useState<typeof import("@activescott/analytics") | null>(null)
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (posthogKey) {
|
|
65
|
+
void import("@activescott/analytics").then(setAnalyticsModule)
|
|
66
|
+
}
|
|
67
|
+
}, [posthogKey])
|
|
68
|
+
if (!analyticsModule) {
|
|
69
|
+
return null
|
|
70
|
+
}
|
|
71
|
+
return <analyticsModule.PostHogProvider apiKey={posthogKey} options={{ api_host: "/ph" }} />
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// <Analytics posthogKey={key} />
|
|
75
|
+
// <Outlet />
|
|
76
|
+
```
|
|
77
|
+
|
|
52
78
|
### 2. Add the reverse proxy route
|
|
53
79
|
|
|
54
80
|
Create `app/routes/ph.$.ts`:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-hog-provider.d.ts","sourceRoot":"","sources":["../src/post-hog-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAK/C,UAAU,oBAAoB;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;IAChC,IAAI,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"post-hog-provider.d.ts","sourceRoot":"","sources":["../src/post-hog-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAK/C,UAAU,oBAAoB;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;IAChC,IAAI,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAA;IAKnE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAC9B,MAAM,EACN,OAAO,EACP,IAAI,EACJ,QAAQ,GACT,EAAE,oBAAoB,+BAqBtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-hog-provider.js","sourceRoot":"","sources":["../src/post-hog-provider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"post-hog-provider.js","sourceRoot":"","sources":["../src/post-hog-provider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAa5D;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,MAAM,EACN,OAAO,EACP,IAAI,EACJ,QAAQ,GACa;IACrB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,4BAAG,QAAQ,GAAI,CAAA;IACxB,CAAC;IAED,OAAO,CACL,MAAC,UAAU,IACT,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;YACP,GAAG,OAAO;YACV,gBAAgB,EAAE,KAAK;SACxB,aAED,KAAC,sBAAsB,KAAG,EAC1B,KAAC,iBAAiB,IAChB,UAAU,EAAE,IAAI,EAAE,UAAU,EAC5B,UAAU,EAAE,IAAI,EAAE,UAAU,GAC5B,EACD,QAAQ,IACE,CACd,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@activescott/analytics",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "PostHog analytics integration for React Router apps — provider, SPA pageview tracking, user identification, and reverse proxy helper",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"repository": {
|
|
37
37
|
"type": "git",
|
|
38
|
-
"url": "https://github.com/activescott/js-utils.git",
|
|
38
|
+
"url": "git+https://github.com/activescott/js-utils.git",
|
|
39
39
|
"directory": "packages/analytics"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|