-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(MetricsElement): add MetricsElement component
Showing
16 changed files
with
715 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* eslint-disable react/no-multi-comp */ | ||
import React, {Component, PropTypes} from "react"; | ||
import ReactDOM from "react-dom"; | ||
import {Router, Route, IndexRoute, Link, IndexLink, hashHistory} from "react-router"; | ||
import {metrics, MetricsElement} from "react-metrics"; // eslint-disable-line import/no-unresolved | ||
import MetricsConfig from "./metrics.config"; | ||
import Home from "./home"; | ||
import Page from "./page"; | ||
|
||
class App extends Component { | ||
static displayName = "My Application"; | ||
|
||
static propTypes = { | ||
children: PropTypes.node | ||
}; | ||
|
||
render() { | ||
const link = (<Link to="/page/A" data-tracking-event-name="linkClick" data-tracking-value="A" ><span>Page A</span></Link>); | ||
return ( | ||
<div> | ||
<ul> | ||
<li><MetricsElement><IndexLink to="/" data-tracking-event-name="linkClick"><span>Home</span></IndexLink></MetricsElement></li> | ||
<li><MetricsElement element={link}><span>This span won't render</span></MetricsElement></li> | ||
<li><MetricsElement to="/page/B" data-tracking-event-name="linkClick" data-tracking-value="B" element={Link}><span>Page B</span></MetricsElement></li> | ||
</ul> | ||
{this.props.children && React.cloneElement(this.props.children, { | ||
appName: App.displayName | ||
})} | ||
</div> | ||
); | ||
} | ||
} | ||
const DecoratedApp = metrics(MetricsConfig, {useTrackBinding: false, attributePrefix: "data-tracking"})(App); | ||
|
||
class NotFound extends Component { | ||
render() { | ||
return ( | ||
<h1>404!</h1> | ||
); | ||
} | ||
} | ||
|
||
ReactDOM.render(( | ||
<Router history={hashHistory}> | ||
<Route path="/" component={DecoratedApp}> | ||
<IndexRoute component={Home}/> | ||
<Route path="page/:id" component={Page}/> | ||
<Route path="*" component={NotFound}/> | ||
</Route> | ||
</Router> | ||
), document.getElementById("example")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from "react"; | ||
|
||
class Home extends React.Component { | ||
render() { | ||
return <h1>Home</h1>; | ||
} | ||
} | ||
|
||
export default Home; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!doctype html> | ||
<title>React Router Example</title> | ||
<link href="../../global.css" rel="stylesheet"/> | ||
<body> | ||
<h1 class="breadcrumbs"><a href="../../index.html">React Metrics Examples</a> / <a href="../index.html">React Router</a> / MetricsElement Example</h1> | ||
<div id="example"></div> | ||
<script src="/__build__/shared.js"></script> | ||
<script src="/__build__/react-router_metricsElement.js"></script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import pkg from "../../../package.json"; | ||
const config = { | ||
vendors: [ | ||
{ | ||
api: { | ||
name: "Test", | ||
pageView(eventName, params) { | ||
return new Promise(resolve => { | ||
setTimeout(() => { | ||
resolve({ | ||
eventName, | ||
params | ||
}); | ||
}, 0 * 1000); | ||
}); | ||
}, | ||
track(eventName, params) { | ||
return new Promise(resolve => { | ||
resolve({ | ||
eventName, | ||
params | ||
}); | ||
}); | ||
}, | ||
user(user) { | ||
return new Promise(resolve => { | ||
resolve({ | ||
user | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
], | ||
pageDefaults: (routeState) => { | ||
const paths = routeState.pathname.substr(1).split("/"); | ||
const timestamp = new Date(); | ||
return { | ||
timestamp, | ||
build: pkg.version, | ||
siteName: "React Metrics Example", | ||
category: !paths[0] ? "landing" : paths[0] | ||
}; | ||
}, | ||
pageViewEvent: "pageLoad", | ||
debug: true | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, {PropTypes} from "react"; | ||
import {MetricsElement} from "react-metrics"; // eslint-disable-line import/no-unresolved | ||
|
||
// Note: `data-tracking` prefix is set in app.js as `attributePrefix` option | ||
|
||
class Page extends React.Component { | ||
static propTypes = { | ||
params: PropTypes.object | ||
} | ||
|
||
render() { | ||
const {params} = this.props; | ||
const listItem = Array.from("123").map(key => ( | ||
<li | ||
key={key} | ||
data-tracking-event-name="SomeEvent" | ||
data-tracking-key={key} | ||
data-tracking-page={params.id} | ||
> | ||
<img src={`http://placehold.it/200x50?text=Item+${key}`}/> | ||
</li> | ||
)); | ||
|
||
return ( | ||
<div> | ||
<h1>Page {params.id}</h1> | ||
{/* Ex 1: self target */} | ||
<MetricsElement element="a" data-tracking-event-name="SomeEvent" data-tracking-value="SomeValue">Link</MetricsElement> | ||
{/* Ex 2: render children only */} | ||
<MetricsElement> | ||
<a data-tracking-event-name="SomeEvent" data-tracking-value="SomeValue"> | ||
<img src="http://placehold.it/200x150?text=Image+1" style={{padding: 5}} /> | ||
</a> | ||
</MetricsElement> | ||
{/* Ex 3: event bubbling */} | ||
<MetricsElement element="a" data-tracking-event-name="SomeEvent" data-tracking-value="SomeValue"> | ||
<img src="http://placehold.it/200x150?text=Image+2" style={{padding: 5}} /> | ||
</MetricsElement> | ||
{/* Ex 4: multiple tracking items */} | ||
<MetricsElement element="ul" style={{listStyle: "none", width: 200, padding: 0}}> | ||
{listItem} | ||
</MetricsElement> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Page; |
Oops, something went wrong.