{"id":19857707,"url":"https://github.com/markmur/view-tracker","last_synced_at":"2025-07-31T09:10:18.836Z","repository":{"id":98553394,"uuid":"445552272","full_name":"markmur/view-tracker","owner":"markmur","description":null,"archived":false,"fork":false,"pushed_at":"2022-01-07T14:41:51.000Z","size":180,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-28T23:47:07.223Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/markmur.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":"2022-01-07T14:41:17.000Z","updated_at":"2022-01-07T14:41:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"a091d5ac-2183-468d-9575-b00d27157cb0","html_url":"https://github.com/markmur/view-tracker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/markmur/view-tracker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmur%2Fview-tracker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmur%2Fview-tracker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmur%2Fview-tracker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmur%2Fview-tracker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markmur","download_url":"https://codeload.github.com/markmur/view-tracker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmur%2Fview-tracker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268016932,"owners_count":24181657,"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","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-12T14:19:31.179Z","updated_at":"2025-07-31T09:10:18.812Z","avatar_url":"https://github.com/markmur.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# View Tracker\n\nReact view/impression tracking component to determine if a user has seen 100% a given\nelement for a minimum of 250ms.\n\n## Props\n\n| Name         | Type                       | Required | Default                                                                | Description                                                                                                                   |\n| ------------ | -------------------------- | -------- | ---------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |\n| `once`       | Boolean                    |          | true                                                                   | Boolean to indicate whether to track an element _once_. Set to false to fire the `onView` event every time it comes into view |\n| `options`    | Object                     |          | `{ minTimeVisible: 250, errorMargin: 0.05, percentCompensation: 0.1 }` | Options for `ViewObserver` instantiation                                                                                      |\n| `children`   | Node                       |          |                                                                        | A single element to track                                                                                                     |\n| `onView()`   | Function(visible: Boolean) |          |                                                                        | Callback fired when element meets impression conditions                                                                       |\n| `onHide()`   | Function(visible: Boolean) |          |                                                                        | Callback fired when element goes out of view                                                                                  |\n| `onChange()` | Function(visible: Boolean) |          |                                                                        | Callback fired when element visibility changes                                                                                |\n\n## Usage\n\n**NOTE** The `ViewTracker` uses `React.Children.only` to enforce a single child node. It will throw an error if you try to specify an array of children.\n\n```js\nimport React, { Component } from 'react'\nimport { ViewTracker } from 'view-tracker'\n\nclass App extends Component {\n  sendEvent = componentName =\u003e () =\u003e {\n    // Send event to google analytics\n    eventBus.trigger('tracking:event', /* { tracking options } */)\n  })\n\n  render() {\n    return (\n      \u003cdiv\u003e\n        \u003cViewTracker onView={this.sendEvent('component-1')}\u003e\n          \u003cComponentOne /\u003e\n        \u003c/ViewTracker\u003e\n\n        \u003cViewTracker onView={this.sendEvent('component-2')}\u003e\n          \u003cComponentTwo /\u003e\n        \u003c/ViewTracker\u003e\n      \u003c/div\u003e\n    )\n  }\n}\n```\n\n### Tracking an impression\n\nA \"view\" refers to the sending of a tracking event strictly _once_ when an element comes into view. A \"impression\" refers to tracking an element _every time_ it comes into view. Prior to `v1.0.0`, \"impressions\" were the default behaviour. This has since changed and `once={true}` is set by default. If you specifically want to track an element every time it comes into view, set the `once` prop to `false`.\n\n```js\nimport { ViewTracker } from 'view-tracker'\n\nconst trackImpression = () =\u003e {\n  // This event will be fired every time the element comes into view\n}\n\n\u003cViewTracker once={false} onView={trackImpression}\u003e\n  \u003cComponentOne /\u003e\n\u003c/ViewTracker\u003e\n```\n\n## Rules for View\n\n| Rules (View) `once={true}`                                 |\n| ---------------------------------------------------------- |\n| Must be 100% visible in the viewport                       |\n| Visible for minimum of 250ms                               |\n| Must completely cover the viewport if larger than viewport |\n\n## Rules for Impression (_deprecated_)\n\n\u003e The following guideline is now deprecated in favour of the one above\n\n| Rules (Impression) `once={false}`                                     |\n| --------------------------------------------------------------------- |\n| Views must be tracked every time the element disappears and reappears |\n| Fire event on window focus                                            |\n| Fire event on orientation change                                      |\n| Fire event is screen resolution changes                               |\n\n---","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmur%2Fview-tracker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkmur%2Fview-tracker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmur%2Fview-tracker/lists"}