Socket
Book a DemoInstallSign in
Socket

retracked

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

retracked

Isomorphic event and link tracking for React

0.1.1
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Retracked

A little library to simplify event tracking in React components.

Basic event tracking

Set it up in your bootstrap:

var myTracker = require('awesomeTracker');
var retracked = require('retracked');

var recordingFn = (fullEventKey, values) =>
  myTracker.record(fullEventKey, values);

// event types that we track
var actionNames = [
  'view',
  'click', // or tap
  'hover',
  'scroll',
  'swipe',
  'pinch',
  'expand',
];

retracked.setup(recordingFn, actionNames);

Then in your components you can namespace the event tracking by context:

var AboutApp = React.createClass({

  childContextTypes: {
    track: React.PropTypes.func,
  },

  getChildContext: function() {
    return {
      track: Retracked.makeTracker({
        namespace: 'about'
      })
    };
  },

  render: function() {
    return (
      <div>
        <JobsPage />
      </div>
    );
  }

});

Then you can use that anywhere down the ownership hierarchy:

var JobsPage = React.createClass({

  contextTypes: {
    track: React.PropTypes.func.isRequired
  },

  componentDidMount: function() {
    // track this event right now
    this.context.track('view.jobs');
  }

  render: function() {
    return (
      <div>
        {/* curried function to track when a click happens */}
        <button label="Apply" onClick={this.context.track.handle('click.apply')} />
      </div>
    );
  }

});

This package contains a component, TrackedLink, that abstracts away defining links on which you want to track clicks, so that they fire events both in regular client-side rendering and also from server-side rendered HTML before the full Javascript assets have downloaded and the full components have mounted.

For example,

    <TrackedLink
      className="open-in-app btn"
      to={appStoreUrl}
      trackingName="download_app"
    >
      Download our App
    </TrackedLink>

Keywords

react

FAQs

Package last updated on 11 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.