{"id":18834880,"url":"https://github.com/booleanhunter/reactjs-user-analytics","last_synced_at":"2026-02-27T05:39:48.191Z","repository":{"id":261542368,"uuid":"341103631","full_name":"booleanhunter/reactjs-user-analytics","owner":"booleanhunter","description":"User Analytics","archived":false,"fork":false,"pushed_at":"2024-11-07T04:37:31.000Z","size":1703,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-30T07:42:54.194Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://booleanhunter.github.io/reactjs-user-analytics/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/booleanhunter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-22T06:38:20.000Z","updated_at":"2024-11-14T06:35:07.000Z","dependencies_parsed_at":"2024-11-07T05:29:16.389Z","dependency_job_id":"a39dd90b-338e-4a17-a8bf-371fa4a1c422","html_url":"https://github.com/booleanhunter/reactjs-user-analytics","commit_stats":null,"previous_names":["booleanhunter/reactjs-user-analytics"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/booleanhunter%2Freactjs-user-analytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/booleanhunter%2Freactjs-user-analytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/booleanhunter%2Freactjs-user-analytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/booleanhunter%2Freactjs-user-analytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/booleanhunter","download_url":"https://codeload.github.com/booleanhunter/reactjs-user-analytics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239769388,"owners_count":19693868,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T02:14:10.474Z","updated_at":"2026-01-26T15:30:15.616Z","avatar_url":"https://github.com/booleanhunter.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# User Analytics\n\nThis library enables tracking of UI events when a user interacts with a React or React Native application.\n\n## Features\n- **Progressive** - Uses latest JavaScript features and design patterns for a React codebase.\n- **Extensible** - A modular architecture and usage of Dependency.Inversion patterns gives you flexibility and allows you to easily extend features.\n- **TypeScript support**.\n\n## Supported events\n- Form Events\n  - `onChange`\n- Mouse Events\n  - `onClick`\n  - `onHover`\n\n\n## Work in Progress\n- Eventually, the library will have exhaustive coverage and support for many more events, such as:\n  - Wheel Events\n  - Touch Events\n  - Keyboard Events\n  - Mouse Events\n  - and more.\n\n- User Interaction journey mapping\n- Session Recording\n\n\n## Instructions of Usage\n1. First, import the library in your project.\n\n2. In-order to add user-tracking ability to your component or element, import the `withTracking` function (Higher-order component) and wrap the component. Here's an example using a simple `Button` component:\n\n`export const ButtonWithTracking = withTracking(Button)`\n\n`ButtonWithTracking` will have all the features and properties of the `Button` component, but with interaction-tracking superpowers!\n\n3. Finally, use `ButtonWithTracking` inside your app anywhere where you'd like to track user-events occurring on this component, such as `onClick` or `onHover`.\n\n```\nimport Button, { ButtonWithTracking } from '../../elements/Button';\n\nfunction Home() {\n\n    function handleClick(e: React.MouseEvent\u003cHTMLElement, MouseEvent\u003e) {\n        // app logic goes here\n    }\n\n    function logEvent(\n        event: React.MouseEvent\u003cHTMLElement, MouseEvent\u003e,\n        interactionResource: UserInteractionResource\n    ) {\n        /*\n            do whatever you want with the resource,\n            like save it to IndexedDB, compress it, save it via API, etc\n        */\n        console.log(interactionResource);\n    }\n\n    return (\n        \u003cButtonWithTracking\n            type=\"text\"\n            onClick={handleClick}\n\n            trackers={[\n                // track onClick event\n                {\n                    action: \"onClick\", // event to track\n                    track: logEvent, // callback function that runs whenever the event occurs\n                }\n            ]}\n        \u003e   \n    )\n}\n\nexport default Home;\n```\n\nYou can add multiple tracker objects within the `trackers` array if you need to track more than one event occurring within the component.\n\n\n## Advanced Usage\n\n### Mapping a user's journey\n\n**Use-case**:\nSay you have 2 react components - a `ButtonWithTracking` configured to track `onClick` events, and a `InputWithTracking` component configured to capture `onChange` events. These components are being used in 2 different pages or templates in your application - a login form, and a newsletter subscription form.\n\nIn this scenario, it is useful to capture a global 'context' within which the events occur - such as the page or the container component details, and the app version. This information is useful to plot out the user's journey, which will give you a more contextual understanding of how the user navigates through your app.\n\n- #### Provide and capture contextual data using React Context Provider `\u003cDataContext.Provider\u003e`\nUsing the `\u003cDataContext.Provider\u003e`, you can provide the global 'context' to your tracking components without having to pass them explicitly via props. Here's how:\n\n  - Create a `DataContext` object.\n```\nconst dataContext = {\n    context: \"Login Form\",\n    app: {\n        version: \"1\",\n    },\n} as UserInteraction.DataContext;\n```\n\n  - Next, wrap your template or container component within `DataContext.Provider` and provide it the `dataContext` value:\n\n```\nimport { DataContext } from '../../../library/user-analytics/react/contexts/dataContext';\nimport Button, { ButtonWithTracking } from '../../elements/Button';\n\nfunction LoginForm() {\n\n    function logEvent(\n        event: React.MouseEvent\u003cHTMLElement, MouseEvent\u003e,\n        interactionResource: UserInteractionResource\n    ) {\n        console.log(interactionResource.app.version) // Will print \"1\"\n        console.log(interactionResource.source.context); // Will print \"Login Form\"\n\n    }\n\n    return (\n        \u003cDataContext.Provider value={dataContext}\u003e // Pass the dataContext value\n            \u003cButtonWithTracking\n                type=\"text\"\n                onClick={handleClick}\n\n                trackers={[\n                    // track onClick event\n                    {\n                        action: \"onClick\",\n                        track: logEvent,\n                        \n                        data: { // pass optional custom data\n                            color: \"blue\",\n                        }\n                    }\n                ]}\n            \u003e  \n        \u003c/DataContext.Provider\u003e \n    )\n}\n\nexport default LoginForm;\n\n```\n\nThis way, your tracking components nested anywhere within the provider will receive the `dataContext` object and will return it as part of the `UserInteractionResource` object.\n\n\n- #### Providing Data Context as regular props\n\nIf you don't want to provide data using `DataContext.Provider` or want to override it with a different value, you can pass them explicitly via props:\n\n```\nfunction LoginForm() {\n\n    function logEvent(\n        event: React.MouseEvent\u003cHTMLElement, MouseEvent\u003e,\n        interactionResource: UserInteractionResource\n    ) {\n        console.log(interactionResource.app.version) // Will print \"0\"\n        console.log(interactionResource.source.context); // Will print \"Login Form\"\n\n    }\n\n    return (\n        \u003cButtonWithTracking\n            type=\"text\"\n            onClick={handleClick}\n\n            trackers={[\n                // track onClick event\n                {\n                    action: \"onClick\",\n                    track: logEvent,\n                    \n                    data: { // pass optional custom data\n                        color: \"blue\",\n                    }\n                }\n            ]}\n  \n            dataContext={{ // Pass dataContext explicitly\n                app: {\n                    version: \"0\",\n                },\n                context: \"Login Form\"\n            }}\n        \u003e  \n    )\n}\n\nexport default LoginForm;\n\n```\n\nIn-case you have both in your application, the data context passed via props will override the values from `        \u003cDataContext.Provider\u003e`\n\n\n## API\n\n### React\n\n- #### Tracking Component Props\n\n    The tracking-enabled component will accept all props required for the original component, along with the following:\n\n    | Props | Required | Description | Type |\n    | :---        |  :----:  |  :----:   |          ---: |\n    | `trackers`  |Yes  |Each tracker object expects an `action` and `track` properties. Check the section below for the complete list of properties  |      `UserInteraction.Tracker[]`  |\n    | `origin`      |Optional | To provide some contextual information for the event origin   | `string`      |\n    | `dataContext` |Optional |an object property to  provide context of the taken event | `UserInteraction.DataContext`|\n\n\n- #### `UserInteraction.Tracker` object properties\n\n    | Property | Required |  Description | Type |\n    | :---     |  :----:  |  :----:   |  ---: |\n    | `action`   | Yes | Type of event that needs to be tracked (React Synthetic events). Can take values such as `onClick`, `onChange` | `string`   | \n    | `track` | Yes| Callback that runs when above event occurs | `(e, interactionResource: UserInteractionResource) =\u003e void` |\n    | `data` | Optional |  Can be used to provide some custom data. Accessible within `UserInteractionResource.data` | `Object\u003cany\u003e` |\n\n\n\n### Interfaces\n\n- #### `UserInteractionResource`\nThe `UserInteractionResource` object contains all properties from `BaseResource`, along with the following:\n\n```\ntype: typeof UserInteraction.TYPE; // \"UserInteraction\"\naction: UserInteraction.Action; // Type of the event, such as \"onClick\", \"onChange\"\nsource: {\n    context: string; // To capture a \"global\" context of the event, such as \"Landing page\" or \"Login form\"\n    origin?: string;\n    component: string; // Name of the React component\n    element: {\n        currentTarget: string;\n        target: string;\n        innerHTML?: string;\n        innerText?: string;\n        value?: string;\n    };\n};\ndata?: Object\u003cany\u003e; // Additional custom data that needs to be captured\n```\n\n- #### `BaseResource`\n\n```\napp: {\n    version: string,\n};\ndate: Date;\nbrowser: {\n    name: string,\n    version: string,\n    userAgent: string,\n    platform: string,\n    window: {\n        width: number,\n        height: number,\n    }\n};\nos: {\n    name: string,\n    version: string,\n};\n\n```\n\n## Check out the [docs](./docs) folder for a complete list of API reference.\n\nThis project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbooleanhunter%2Freactjs-user-analytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbooleanhunter%2Freactjs-user-analytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbooleanhunter%2Freactjs-user-analytics/lists"}