4.0.3 • Published 1 year ago

tracking-link v4.0.3

Weekly downloads
37
License
MIT
Repository
github
Last release
1 year ago

TrackingLink

npm Version License

TrackingLink is React component that helps to track clicks for links on the page.

Features

  • Supports ctrl/cmd + click to open url in a new tab/window
  • Navigates to the URL when tracking function is resolved or when the timeout is resolved first (this helps to avoid problems with analytics-blocking browser extensions or when your tracking function has failed)
  • Configurable timeouts
  • Supports middle mouse click (mouse wheel click) to open link in a new window/tab

Installation

npm i --save tracking-link

Usage

For example you have an image wrapped into 'a' tag and want to track clicks onto that link and then navigate a user to the url specified in href.

import TrackingLink from "tracking-link";
const asyncTrackingFunc = new Promise(resolve => {
  // Async tracking operations
  resolve();
});

function SomeComponent() {
  return (
    <TrackingLink href="/image/cat.jpg" onClick={asyncTrackingFunc}>
      <img src="cat.jpg" />
    </TrackingLink>
  );
}

Now when you click the image, TrackingLink will call your tracking function and when it resolves (or when timeout is resolved first) it will navigate user to the URL specified in the 'href' prop.

Available props

propTypes = {
  // accessibility label applied to <a> tag, describing its purpose or destination for screen reader users
  ariaLabel: PropTypes.string,
  // a React node you want to wrap into <a> link
  children: PropTypes.node.isRequired,
  // href - url where navigate when tracking function is resolved
  href: PropTypes.string.isRequired,
  // className is applied to the <a> tag
  className: PropTypes.string,
  // tracking function must be a Promise instance
  onClick: PropTypes.func,
  // opens link in a new tab/window (default = false)
  targetBlank: PropTypes.bool,
  // don't navigate to the url (default = false)
  preventDefault: PropTypes.bool,
  // timeout (ms) to which the tracking function is limited (default = 500)
  trackingTimeout: PropTypes.number
};

Made by The Daily Beast team

4.0.3

1 year ago

4.0.2

2 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.2.0

6 years ago

3.1.0

6 years ago

3.0.4

6 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago