Mailspring/internal_packages/link-tracking/lib/link-tracking-panel.jsx
Drew Regitsky fe7a894e51 feat(new-plugins): add open tracking and link tracking plugins
Summary:
Adds two (very similar) plugins - Open Tracking and Link Tracking.
Both can be enabled via a button in the composer. Open tracking
inserts a tracking pixel right before send, and link tracking replaces
all links with tracked redirects. Both plugins use the new Metadata
service to store their open/click counts, and have backend servers to
respectively serve the pixel image or handle the redirects. Requests
also trigger a metadata update to increment the open/click counters.

Test Plan: Manual for now

Reviewers: evan, bengotow, drew

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D2583
2016-02-19 12:42:56 -08:00

48 lines
1.1 KiB
JavaScript

import {React} from 'nylas-exports'
import plugin from '../package.json'
export default class LinkTrackingPanel extends React.Component {
static displayName = 'LinkTrackingPanel';
static propTypes = {
message: React.PropTypes.object.isRequired,
};
constructor(props) {
super(props);
this.state = this._getStateFromMessage(props.message)
}
componentWillReceiveProps(newProps) {
this.setState(this._getStateFromMessage(newProps.message));
}
_getStateFromMessage(message) {
const metadata = message.metadataForPluginId(plugin.appId);
return metadata ? {links: metadata.links} : {};
}
_renderContents() {
return this.state.links.map(link => {
return (<tr className="link-info">
<td className="link-url">{link.url}</td>
<td className="link-count">{link.click_count + " clicks"}</td>
</tr>)
})
}
render() {
if (this.state.links) {
return (<div className="link-tracking-panel">
<h4>Link Tracking Enabled</h4>
<table>
<tbody>
{this._renderContents()}
</tbody>
</table>
</div>);
}
return <div></div>;
}
}