@deltabreen/analytics-react 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DeltaBreen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,31 @@
1
- # Temporary Holding Version
1
+ # @deltabreen/analytics-react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Analytics by DeltaBreen for React apps (Vite, Remix and others; for Next.js use `@deltabreen/analytics-next`). It loads
4
+ the same per-site script as the `<script>` tag, so pageviews (page changes included), heatmaps, errors, Web Vitals,
5
+ experiments, recordings and surveys all work the same. On a server it does nothing.
6
+
7
+ ```bash
8
+ npm install @deltabreen/analytics-react
9
+ ```
10
+
11
+ ```jsx
12
+ import { Analytics, useVariant, useFlag, track } from '@deltabreen/analytics-react';
13
+
14
+ export function App() {
15
+ return (<><Routes /><Analytics siteKey="ans_YOUR_KEY" /></>);
16
+ }
17
+
18
+ function Hero() {
19
+ const v = useVariant('hero-copy'); // null until the tracker has loaded, or for people outside the test
20
+ return <h1 onClick={() => track('Hero clicked')}>{v === 'b' ? 'Ship faster' : 'Build better'}</h1>;
21
+ }
22
+ ```
23
+
24
+ `<Analytics />` takes `origin: '/stats'` to load and send through your own domain (see the proxy docs) and
25
+ `consent="tcf"` to follow a consent banner on the IAB's framework. `track`, `identify`, `consent`, `variant`, `flag`
26
+ and `ready` come with it, from `@deltabreen/analytics`.
27
+
28
+ Both hooks start at the original so a server render and the first client render agree, then update once the tracker
29
+ has loaded. For a test where that first frame matters, use a visual variant (the page waits for it) or a redirect.
30
+
31
+ Docs: https://analytics.deltabreen.eu/docs/install
package/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { InitOptions } from '@deltabreen/analytics';
2
+ export * from '@deltabreen/analytics';
3
+ /** Loads the tracker once, near the root of the app; renders nothing. */
4
+ export function Analytics(props: InitOptions): null;
5
+ /** The variant this person sees, or null for the original (also on a server and before the tracker has loaded). */
6
+ export function useVariant(key: string): string | null;
7
+ /** Whether a feature flag is on for this person (false on a server and before the tracker has loaded). */
8
+ export function useFlag(key: string): boolean;
package/index.js ADDED
@@ -0,0 +1,34 @@
1
+ 'use client';
2
+ // React helpers: <Analytics siteKey="ans_…" /> once near the root, and hooks for variants and flags. Both hooks start
3
+ // at the original (null / false) so a server render and the first client render agree, then update once the tracker
4
+ // has loaded. Marked as client code, so Next.js's App Router can place it in a server layout. The core's functions
5
+ // come with it, named one by one since a client module cannot re-export with *.
6
+ import { useEffect, useState } from 'react';
7
+ import { flag, init, ready, variant } from '@deltabreen/analytics';
8
+
9
+ export { consent, flag, identify, init, notFound, optOut, pageview, ready, track, variant } from '@deltabreen/analytics';
10
+
11
+ export function Analytics({ siteKey, origin, consent }) {
12
+ useEffect(() => {
13
+ init({ siteKey, origin, consent });
14
+ }, [siteKey, origin, consent]);
15
+ return null;
16
+ }
17
+
18
+ function useTracker(read, initial, key) {
19
+ const [value, setValue] = useState(initial);
20
+ useEffect(() => {
21
+ let live = true;
22
+ setValue(read(key));
23
+ ready().then(() => {
24
+ if (live) setValue(read(key));
25
+ });
26
+ return () => {
27
+ live = false;
28
+ };
29
+ }, [key]);
30
+ return value;
31
+ }
32
+
33
+ export const useVariant = (key) => useTracker(variant, null, key);
34
+ export const useFlag = (key) => useTracker(flag, false, key);
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@deltabreen/analytics-react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Analytics by DeltaBreen for React: an <Analytics /> component and hooks for experiment variants and feature flags.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./index.d.ts",
9
+ "default": "./index.js"
10
+ },
11
+ "./package.json": "./package.json"
12
+ },
13
+ "files": [
14
+ "index.js",
15
+ "index.d.ts",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "sideEffects": false,
20
+ "dependencies": {
21
+ "@deltabreen/analytics": "^0.2.0"
22
+ },
23
+ "peerDependencies": {
24
+ "react": ">=17"
25
+ },
26
+ "engines": {
27
+ "node": ">=18"
28
+ },
29
+ "license": "MIT",
30
+ "scripts": {
31
+ "test": "node --test test/*.test.mjs"
32
+ },
33
+ "keywords": [
34
+ "analytics",
35
+ "cookieless",
36
+ "heatmaps",
37
+ "ab-testing",
38
+ "feature-flags",
39
+ "deltabreen",
40
+ "react"
41
+ ],
42
+ "homepage": "https://analytics.deltabreen.eu/docs/install"
43
+ }