@tell-rs/react 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/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # @tell-rs/react
2
+
3
+ Tell SDK React bindings — provider, hooks, and components.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ # npm
9
+ npm install @tell-rs/react @tell-rs/browser
10
+
11
+ # yarn
12
+ yarn add @tell-rs/react @tell-rs/browser
13
+
14
+ # pnpm
15
+ pnpm add @tell-rs/react @tell-rs/browser
16
+
17
+ # bun
18
+ bun add @tell-rs/react @tell-rs/browser
19
+ ```
20
+
21
+ `@tell-rs/browser` is a peer dependency and must be installed alongside `@tell-rs/react`.
22
+
23
+ ## Quick Start
24
+
25
+ ### 1. Add the provider
26
+
27
+ Wrap your app with `TellProvider` at the root:
28
+
29
+ ```tsx
30
+ // src/App.tsx
31
+ import { TellProvider } from "@tell-rs/react";
32
+
33
+ export default function App() {
34
+ return (
35
+ <TellProvider apiKey="your-api-key">
36
+ <YourApp />
37
+ </TellProvider>
38
+ );
39
+ }
40
+ ```
41
+
42
+ ### 2. Track events
43
+
44
+ ```tsx
45
+ import { useTrack } from "@tell-rs/react";
46
+
47
+ function SignUpButton() {
48
+ const track = useTrack();
49
+
50
+ return (
51
+ <button onClick={() => track("Sign Up Clicked", { plan: "pro" })}>
52
+ Sign Up
53
+ </button>
54
+ );
55
+ }
56
+ ```
57
+
58
+ ### 3. Identify users
59
+
60
+ ```tsx
61
+ import { useIdentify } from "@tell-rs/react";
62
+
63
+ function LoginForm() {
64
+ const identify = useIdentify();
65
+
66
+ function onLogin(user: { id: string; email: string }) {
67
+ identify(user.id, { email: user.email });
68
+ }
69
+
70
+ // ...
71
+ }
72
+ ```
73
+
74
+ ## API
75
+
76
+ ### `<TellProvider>`
77
+
78
+ | Prop | Type | Description |
79
+ |------|------|-------------|
80
+ | `apiKey` | `string` | **Required.** Your Tell API key. |
81
+ | `options` | `TellBrowserConfig` | Optional config passed to `tell.configure()`. |
82
+ | `children` | `ReactNode` | Your app tree. |
83
+
84
+ Calls `tell.configure()` once on mount and `tell.close()` on unmount.
85
+
86
+ ### Hooks
87
+
88
+ | Hook | Returns | Description |
89
+ |------|---------|-------------|
90
+ | `useTell()` | `TellInstance` | The Tell singleton for direct access. |
91
+ | `useTrack()` | `(name, props?) => void` | Stable callback for tracking events. |
92
+ | `useIdentify()` | `(userId, traits?) => void` | Stable callback for identifying users. |
93
+
94
+ ### Direct access
95
+
96
+ For cases where hooks aren't suitable:
97
+
98
+ ```ts
99
+ import { tell } from "@tell-rs/react";
100
+
101
+ tell.track("Background Task Done");
102
+ ```
103
+
104
+ ## License
105
+
106
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.tsx
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
+ TellProvider: () => TellProvider,
35
+ tell: () => import_browser2.tell,
36
+ useIdentify: () => useIdentify,
37
+ useTell: () => useTell,
38
+ useTrack: () => useTrack
39
+ });
40
+ module.exports = __toCommonJS(index_exports);
41
+ var import_react = require("react");
42
+ var import_browser = __toESM(require("@tell-rs/browser"), 1);
43
+ var import_browser2 = require("@tell-rs/browser");
44
+ var import_jsx_runtime = require("react/jsx-runtime");
45
+ var TellContext = (0, import_react.createContext)(import_browser.default);
46
+ function TellProvider({ apiKey, options, children }) {
47
+ const initialized = (0, import_react.useRef)(false);
48
+ (0, import_react.useEffect)(() => {
49
+ if (!initialized.current) {
50
+ import_browser.default.configure(apiKey, options);
51
+ initialized.current = true;
52
+ }
53
+ return () => {
54
+ import_browser.default.close();
55
+ };
56
+ }, []);
57
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TellContext, { value: import_browser.default, children });
58
+ }
59
+ function useTell() {
60
+ return (0, import_react.useContext)(TellContext);
61
+ }
62
+ function useTrack() {
63
+ const t = useTell();
64
+ return (0, import_react.useCallback)(
65
+ (eventName, properties) => {
66
+ t.track(eventName, properties);
67
+ },
68
+ [t]
69
+ );
70
+ }
71
+ function useIdentify() {
72
+ const t = useTell();
73
+ return (0, import_react.useCallback)(
74
+ (userId, traits) => {
75
+ t.identify(userId, traits);
76
+ },
77
+ [t]
78
+ );
79
+ }
80
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n useContext,\n useEffect,\n useCallback,\n useRef,\n type ReactNode,\n} from \"react\";\nimport tell from \"@tell-rs/browser\";\nimport type { TellBrowserConfig, TellInstance, Properties } from \"@tell-rs/browser\";\n\n// Re-export everything from @tell-rs/browser for convenience\nexport { tell } from \"@tell-rs/browser\";\nexport type { TellBrowserConfig, TellInstance, Properties } from \"@tell-rs/browser\";\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\nconst TellContext = createContext<TellInstance>(tell);\n\nexport interface TellProviderProps {\n apiKey: string;\n options?: TellBrowserConfig;\n children: ReactNode;\n}\n\n/**\n * Initializes the Tell SDK and provides it to the React tree.\n * Call once at the root of your app.\n */\nexport function TellProvider({ apiKey, options, children }: TellProviderProps) {\n const initialized = useRef(false);\n\n useEffect(() => {\n if (!initialized.current) {\n tell.configure(apiKey, options);\n initialized.current = true;\n }\n return () => {\n tell.close();\n };\n }, []); // eslint-disable-line react-hooks/exhaustive-deps\n\n return <TellContext value={tell}>{children}</TellContext>;\n}\n\n// ---------------------------------------------------------------------------\n// Hooks\n// ---------------------------------------------------------------------------\n\n/** Access the Tell singleton instance. */\nexport function useTell(): TellInstance {\n return useContext(TellContext);\n}\n\n/** Returns a stable `track` function. */\nexport function useTrack() {\n const t = useTell();\n return useCallback(\n (eventName: string, properties?: Properties) => {\n t.track(eventName, properties);\n },\n [t]\n );\n}\n\n/** Returns a stable `identify` function. */\nexport function useIdentify() {\n const t = useTell();\n return useCallback(\n (userId: string, traits?: Properties) => {\n t.identify(userId, traits);\n },\n [t]\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAOO;AACP,qBAAiB;AAIjB,IAAAA,kBAAqB;AAgCZ;AAzBT,IAAM,kBAAc,4BAA4B,eAAAC,OAAI;AAY7C,SAAS,aAAa,EAAE,QAAQ,SAAS,SAAS,GAAsB;AAC7E,QAAM,kBAAc,qBAAO,KAAK;AAEhC,8BAAU,MAAM;AACd,QAAI,CAAC,YAAY,SAAS;AACxB,qBAAAA,QAAK,UAAU,QAAQ,OAAO;AAC9B,kBAAY,UAAU;AAAA,IACxB;AACA,WAAO,MAAM;AACX,qBAAAA,QAAK,MAAM;AAAA,IACb;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO,4CAAC,eAAY,OAAO,eAAAA,SAAO,UAAS;AAC7C;AAOO,SAAS,UAAwB;AACtC,aAAO,yBAAW,WAAW;AAC/B;AAGO,SAAS,WAAW;AACzB,QAAM,IAAI,QAAQ;AAClB,aAAO;AAAA,IACL,CAAC,WAAmB,eAA4B;AAC9C,QAAE,MAAM,WAAW,UAAU;AAAA,IAC/B;AAAA,IACA,CAAC,CAAC;AAAA,EACJ;AACF;AAGO,SAAS,cAAc;AAC5B,QAAM,IAAI,QAAQ;AAClB,aAAO;AAAA,IACL,CAAC,QAAgB,WAAwB;AACvC,QAAE,SAAS,QAAQ,MAAM;AAAA,IAC3B;AAAA,IACA,CAAC,CAAC;AAAA,EACJ;AACF;","names":["import_browser","tell"]}
@@ -0,0 +1,23 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { TellBrowserConfig, Properties, TellInstance } from '@tell-rs/browser';
4
+ export { Properties, TellBrowserConfig, TellInstance, tell } from '@tell-rs/browser';
5
+
6
+ interface TellProviderProps {
7
+ apiKey: string;
8
+ options?: TellBrowserConfig;
9
+ children: ReactNode;
10
+ }
11
+ /**
12
+ * Initializes the Tell SDK and provides it to the React tree.
13
+ * Call once at the root of your app.
14
+ */
15
+ declare function TellProvider({ apiKey, options, children }: TellProviderProps): react_jsx_runtime.JSX.Element;
16
+ /** Access the Tell singleton instance. */
17
+ declare function useTell(): TellInstance;
18
+ /** Returns a stable `track` function. */
19
+ declare function useTrack(): (eventName: string, properties?: Properties) => void;
20
+ /** Returns a stable `identify` function. */
21
+ declare function useIdentify(): (userId: string, traits?: Properties) => void;
22
+
23
+ export { TellProvider, type TellProviderProps, useIdentify, useTell, useTrack };
@@ -0,0 +1,23 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { TellBrowserConfig, Properties, TellInstance } from '@tell-rs/browser';
4
+ export { Properties, TellBrowserConfig, TellInstance, tell } from '@tell-rs/browser';
5
+
6
+ interface TellProviderProps {
7
+ apiKey: string;
8
+ options?: TellBrowserConfig;
9
+ children: ReactNode;
10
+ }
11
+ /**
12
+ * Initializes the Tell SDK and provides it to the React tree.
13
+ * Call once at the root of your app.
14
+ */
15
+ declare function TellProvider({ apiKey, options, children }: TellProviderProps): react_jsx_runtime.JSX.Element;
16
+ /** Access the Tell singleton instance. */
17
+ declare function useTell(): TellInstance;
18
+ /** Returns a stable `track` function. */
19
+ declare function useTrack(): (eventName: string, properties?: Properties) => void;
20
+ /** Returns a stable `identify` function. */
21
+ declare function useIdentify(): (userId: string, traits?: Properties) => void;
22
+
23
+ export { TellProvider, type TellProviderProps, useIdentify, useTell, useTrack };
package/dist/index.js ADDED
@@ -0,0 +1,56 @@
1
+ "use client";
2
+
3
+ // src/index.tsx
4
+ import {
5
+ createContext,
6
+ useContext,
7
+ useEffect,
8
+ useCallback,
9
+ useRef
10
+ } from "react";
11
+ import tell from "@tell-rs/browser";
12
+ import { tell as tell2 } from "@tell-rs/browser";
13
+ import { jsx } from "react/jsx-runtime";
14
+ var TellContext = createContext(tell);
15
+ function TellProvider({ apiKey, options, children }) {
16
+ const initialized = useRef(false);
17
+ useEffect(() => {
18
+ if (!initialized.current) {
19
+ tell.configure(apiKey, options);
20
+ initialized.current = true;
21
+ }
22
+ return () => {
23
+ tell.close();
24
+ };
25
+ }, []);
26
+ return /* @__PURE__ */ jsx(TellContext, { value: tell, children });
27
+ }
28
+ function useTell() {
29
+ return useContext(TellContext);
30
+ }
31
+ function useTrack() {
32
+ const t = useTell();
33
+ return useCallback(
34
+ (eventName, properties) => {
35
+ t.track(eventName, properties);
36
+ },
37
+ [t]
38
+ );
39
+ }
40
+ function useIdentify() {
41
+ const t = useTell();
42
+ return useCallback(
43
+ (userId, traits) => {
44
+ t.identify(userId, traits);
45
+ },
46
+ [t]
47
+ );
48
+ }
49
+ export {
50
+ TellProvider,
51
+ tell2 as tell,
52
+ useIdentify,
53
+ useTell,
54
+ useTrack
55
+ };
56
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n useContext,\n useEffect,\n useCallback,\n useRef,\n type ReactNode,\n} from \"react\";\nimport tell from \"@tell-rs/browser\";\nimport type { TellBrowserConfig, TellInstance, Properties } from \"@tell-rs/browser\";\n\n// Re-export everything from @tell-rs/browser for convenience\nexport { tell } from \"@tell-rs/browser\";\nexport type { TellBrowserConfig, TellInstance, Properties } from \"@tell-rs/browser\";\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\nconst TellContext = createContext<TellInstance>(tell);\n\nexport interface TellProviderProps {\n apiKey: string;\n options?: TellBrowserConfig;\n children: ReactNode;\n}\n\n/**\n * Initializes the Tell SDK and provides it to the React tree.\n * Call once at the root of your app.\n */\nexport function TellProvider({ apiKey, options, children }: TellProviderProps) {\n const initialized = useRef(false);\n\n useEffect(() => {\n if (!initialized.current) {\n tell.configure(apiKey, options);\n initialized.current = true;\n }\n return () => {\n tell.close();\n };\n }, []); // eslint-disable-line react-hooks/exhaustive-deps\n\n return <TellContext value={tell}>{children}</TellContext>;\n}\n\n// ---------------------------------------------------------------------------\n// Hooks\n// ---------------------------------------------------------------------------\n\n/** Access the Tell singleton instance. */\nexport function useTell(): TellInstance {\n return useContext(TellContext);\n}\n\n/** Returns a stable `track` function. */\nexport function useTrack() {\n const t = useTell();\n return useCallback(\n (eventName: string, properties?: Properties) => {\n t.track(eventName, properties);\n },\n [t]\n );\n}\n\n/** Returns a stable `identify` function. */\nexport function useIdentify() {\n const t = useTell();\n return useCallback(\n (userId: string, traits?: Properties) => {\n t.identify(userId, traits);\n },\n [t]\n );\n}\n"],"mappings":";;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,OAAO,UAAU;AAIjB,SAAS,QAAAA,aAAY;AAgCZ;AAzBT,IAAM,cAAc,cAA4B,IAAI;AAY7C,SAAS,aAAa,EAAE,QAAQ,SAAS,SAAS,GAAsB;AAC7E,QAAM,cAAc,OAAO,KAAK;AAEhC,YAAU,MAAM;AACd,QAAI,CAAC,YAAY,SAAS;AACxB,WAAK,UAAU,QAAQ,OAAO;AAC9B,kBAAY,UAAU;AAAA,IACxB;AACA,WAAO,MAAM;AACX,WAAK,MAAM;AAAA,IACb;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO,oBAAC,eAAY,OAAO,MAAO,UAAS;AAC7C;AAOO,SAAS,UAAwB;AACtC,SAAO,WAAW,WAAW;AAC/B;AAGO,SAAS,WAAW;AACzB,QAAM,IAAI,QAAQ;AAClB,SAAO;AAAA,IACL,CAAC,WAAmB,eAA4B;AAC9C,QAAE,MAAM,WAAW,UAAU;AAAA,IAC/B;AAAA,IACA,CAAC,CAAC;AAAA,EACJ;AACF;AAGO,SAAS,cAAc;AAC5B,QAAM,IAAI,QAAQ;AAClB,SAAO;AAAA,IACL,CAAC,QAAgB,WAAwB;AACvC,QAAE,SAAS,QAAQ,MAAM;AAAA,IAC3B;AAAA,IACA,CAAC,CAAC;AAAA,EACJ;AACF;","names":["tell"]}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@tell-rs/react",
3
+ "version": "0.1.0",
4
+ "description": "Tell SDK React bindings — provider, hooks, and components",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": ["dist"],
17
+ "scripts": {
18
+ "build": "tsup",
19
+ "test": "echo 'no tests'",
20
+ "typecheck": "tsc --noEmit",
21
+ "clean": "rm -rf dist"
22
+ },
23
+ "peerDependencies": {
24
+ "react": ">=18",
25
+ "@tell-rs/browser": "*"
26
+ },
27
+ "devDependencies": {
28
+ "@types/react": "^19.0.0",
29
+ "react": "^19.0.0",
30
+ "@tell-rs/browser": "*",
31
+ "tsup": "^8.0.0",
32
+ "typescript": "^5.5.0"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/tell-rs/tell-js.git",
37
+ "directory": "packages/react"
38
+ },
39
+ "homepage": "https://tell.rs",
40
+ "keywords": ["analytics", "react", "hooks", "tell"],
41
+ "license": "MIT",
42
+ "author": "Arcade Labs Inc."
43
+ }