@convex-internal/web-analytics 2.1.0 → 2.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 +25 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/posthog.d.ts +1 -0
- package/dist/posthog.js +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,6 +29,31 @@ capture("www-login", undefined, {
|
|
|
29
29
|
});
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
### `getDistinctId`
|
|
33
|
+
|
|
34
|
+
PostHog's identifier for the current visitor. After consent is granted it is
|
|
35
|
+
stored in a cookie on `.convex.dev`, so every Convex site in the browser uses
|
|
36
|
+
the same ID.
|
|
37
|
+
|
|
38
|
+
When this helper returns a value, consent has been granted. Pass that ID to a
|
|
39
|
+
third-party tool so you can match that tool's events or sessions, such as a
|
|
40
|
+
support chat, back to the same visitor in PostHog.
|
|
41
|
+
|
|
42
|
+
It's expected that a call on first load is always `undefined`, so call again
|
|
43
|
+
after consent is granted.
|
|
44
|
+
|
|
45
|
+
It returns one of:
|
|
46
|
+
|
|
47
|
+
- **`undefined`**. PostHog is not initialized (localhost, non-production, or
|
|
48
|
+
still loading), or consent has not been granted. Before consent, PostHog
|
|
49
|
+
still has a cookieless ID, but it is not stable across sites or even page
|
|
50
|
+
reloads, so returning it would create noise rather than being useful.
|
|
51
|
+
- **Anonymous UUID**, such as `"019a7d8f-9190-7844-a5c0-73d461a3a5d1"`.
|
|
52
|
+
Consent has been granted but this browser has not logged into the
|
|
53
|
+
dashboard where the user is identified.
|
|
54
|
+
- **Convex profile ID**, such as `"4281"`. Consent has been granted and this
|
|
55
|
+
browser has logged into the dashboard.
|
|
56
|
+
|
|
32
57
|
### Consent banner
|
|
33
58
|
|
|
34
59
|
The banner is visible when `consent` is `"undecided"`. It is hidden while
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/posthog.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ConsentStatus } from "./consent.js";
|
|
2
2
|
export declare const POSTHOG_PUBLIC_PROJECT_TOKEN = "phc_JDNTRxeh2li2sQTRO0IcOYMJcp8fPs5nTK9TU751nQK";
|
|
3
3
|
export declare function initPostHog(): void;
|
|
4
|
+
export declare function getDistinctId(): string | undefined;
|
|
4
5
|
export declare function syncPostHogConsent(consent: ConsentStatus): void;
|
package/dist/posthog.js
CHANGED
|
@@ -32,6 +32,16 @@ export function initPostHog() {
|
|
|
32
32
|
person_profiles: "identified_only",
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
+
export function getDistinctId() {
|
|
36
|
+
if (!posthog.__loaded) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
// Cookieless IDs change across sites and reloads, so aren't useful to return.
|
|
40
|
+
if (posthog.get_explicit_consent_status() !== "granted") {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return posthog.get_distinct_id();
|
|
44
|
+
}
|
|
35
45
|
export function syncPostHogConsent(consent) {
|
|
36
46
|
if (!posthog.__loaded) {
|
|
37
47
|
return;
|