Skip to content

Instantly share code, notes, and snippets.

@jstrimpel
Last active December 28, 2015 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jstrimpel/9e2a04622a1b015c8a26 to your computer and use it in GitHub Desktop.
Save jstrimpel/9e2a04622a1b015c8a26 to your computer and use it in GitHub Desktop.
babel analytics, performance plugins
  • Capture analytics from synthetic events and gather performance metrics
  • Transform React components
{
"presets": ["es2015", "react"],
"plugins": ["analytics", "performance"]
}
import Performance from 'performance';
import Analytics from 'analytics';
<Performance environment={{'ci'}}>
<Analytics>
<App />
</Analytics>
</Performance>
import { Component } from 'react';
class Hello extends Component {
componentDidMount() {
console.log('component did mount');
}
onClick(e) {
console.log(e);
}
render () {
return <div onClick={this.clickHandler}></div>
}
}
import { Component } from 'react';
class Hello extends Component {
componentWillMount() {
if (this.context.performance && typeof this.context.performance === 'function') {
this.performance('component_will_mount');
}
}
componentDidMount() {
if (this.context.performance && typeof this.context.performance === 'function') {
this.performance('component_did_mount');
}
this._componentDidMount();
}
_componentDidMount() {
console.log('component did mount');
}
componentWillUnmount() {
if (this.context.performance && typeof this.context.performance === 'function') {
this.performance('component_will_unmount');
}
this._componentDidMount();
}
clickHandler(e) {
console.log(e);
}
_clickHandler(e) {
if (this.context.analytics && typeof this.context.analytics === 'function') {
this.context.analytics(e)
}
this.onClick(e);
}
render () {
return <div onClick={this._clickHandler}></div>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment