@convex-internal/web-analytics 2.2.2 → 2.3.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
@@ -59,6 +59,8 @@ It returns one of:
59
59
  The banner is visible when `consent` is `"undecided"`. It is hidden while
60
60
  `consent` is `"unknown"`, `"consented"`, or `"declined"`.
61
61
 
62
+ React and Svelte accept an optional `hideBanner` prop, defaulting to `false`.
63
+
62
64
  Theme with `--wa-banner-*` variables on `.wa-banner`:
63
65
 
64
66
  ```css
@@ -127,6 +129,26 @@ import { WebAnalyticsProvider } from "@convex-internal/web-analytics/react";
127
129
  <WebAnalyticsProvider>{children}</WebAnalyticsProvider>;
128
130
  ```
129
131
 
132
+ For example, hide the banner on `/start` and `/login` redirect pages in Next.js:
133
+
134
+ ```tsx
135
+ "use client";
136
+
137
+ import { WebAnalyticsProvider } from "@convex-internal/web-analytics/react";
138
+ import { usePathname } from "next/navigation";
139
+ import type { ReactNode } from "react";
140
+
141
+ export function Analytics({ children }: { children: ReactNode }) {
142
+ const pathname = usePathname();
143
+
144
+ return (
145
+ <WebAnalyticsProvider hideBanner={["/start", "/login"].includes(pathname)}>
146
+ {children}
147
+ </WebAnalyticsProvider>
148
+ );
149
+ }
150
+ ```
151
+
130
152
  ### `Consented`
131
153
 
132
154
  Renders children only when `consent` is `"consented"`. It renders nothing during
@@ -158,7 +180,7 @@ only when `consent === "consented"`.
158
180
  ## Svelte
159
181
 
160
182
  The Svelte entry exports only `WebAnalytics`. Render it once in the root
161
- layout. It has no props and no snippet: it starts PostHog and shows the banner.
183
+ layout. It starts PostHog and shows the banner.
162
184
  There is no `Consented` wrapper or consent store. Those can be added later;
163
185
  nothing using the Svelte entry has needed them yet.
164
186
 
@@ -1,2 +1,4 @@
1
1
  import "../banner.css";
2
- export declare function ConsentBanner(): import("react").JSX.Element | null;
2
+ export declare function ConsentBanner({ hideBanner, }: {
3
+ hideBanner?: boolean;
4
+ }): import("react").JSX.Element | null;
@@ -6,9 +6,9 @@ import { hasGPC } from "../consent.js";
6
6
  import { bannerCopy } from "../strings.js";
7
7
  import { useConsent } from "./useConsent.js";
8
8
  import "../banner.css";
9
- export function ConsentBanner() {
9
+ export function ConsentBanner({ hideBanner = false, }) {
10
10
  const { consent, setConsent } = useConsent();
11
- const shouldShow = consent === "undecided";
11
+ const shouldShow = consent === "undecided" && !hideBanner;
12
12
  const wasShowing = useRef(false);
13
13
  const recordedGPCDecision = useRef(false);
14
14
  useEffect(() => {
@@ -3,9 +3,11 @@ import { type ConsentStatus } from "../consent.js";
3
3
  export type { ConsentStatus };
4
4
  export interface WebAnalyticsProviderProps {
5
5
  children: ReactNode;
6
+ /** Hide the banner while keeping consent handling and analytics active. */
7
+ hideBanner?: boolean;
6
8
  }
7
9
  export declare const ConsentContext: import("react").Context<{
8
10
  consent: ConsentStatus;
9
11
  setConsent: (status: "consented" | "declined") => void;
10
12
  } | null>;
11
- export declare function WebAnalyticsProvider({ children }: WebAnalyticsProviderProps): import("react").JSX.Element;
13
+ export declare function WebAnalyticsProvider({ children, hideBanner, }: WebAnalyticsProviderProps): import("react").JSX.Element;
@@ -6,7 +6,7 @@ import { initPostHog, syncPostHogConsent } from "../posthog.js";
6
6
  import { ConsentBanner } from "./ConsentBanner.js";
7
7
  import { useBooleanCookie } from "./useCookie.js";
8
8
  export const ConsentContext = createContext(null);
9
- export function WebAnalyticsProvider({ children }) {
9
+ export function WebAnalyticsProvider({ children, hideBanner = false, }) {
10
10
  const { value, isReady, setValue } = useBooleanCookie(COOKIE_NAME);
11
11
  const consent = resolveConsent(isReady, value, hasGPC());
12
12
  useEffect(() => {
@@ -20,5 +20,5 @@ export function WebAnalyticsProvider({ children }) {
20
20
  setConsent: (status) => {
21
21
  setValue(status === "consented" ? "true" : "false");
22
22
  },
23
- }, children: [children, _jsx(ConsentBanner, {})] }));
23
+ }, children: [children, _jsx(ConsentBanner, { hideBanner: hideBanner })] }));
24
24
  }
@@ -7,12 +7,14 @@
7
7
  import { bannerCopy } from "../strings.js";
8
8
  import "../banner.css";
9
9
 
10
+ let { hideBanner = false }: { hideBanner?: boolean } = $props();
11
+
10
12
  let isReady = $state(false);
11
13
  let cookieValue = $state<boolean | undefined>(undefined);
12
14
  let recordedGPCDecision = false;
13
15
 
14
16
  const consent = $derived(resolveConsent(isReady, cookieValue, hasGPC()));
15
- const shouldShowBanner = $derived(consent === "undecided");
17
+ const shouldShowBanner = $derived(consent === "undecided" && !hideBanner);
16
18
 
17
19
  function readCookieValue(): boolean | undefined {
18
20
  const raw = getCookie(COOKIE_NAME);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@convex-internal/web-analytics",
3
- "version": "2.2.2",
3
+ "version": "2.3.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -1,2 +0,0 @@
1
- export { capture, type CaptureOptions } from "../capture.js";
2
- export type { ConsentStatus } from "../consent.js";
@@ -1 +0,0 @@
1
- export { capture } from "../capture.js";