Skip to content

Commit

Permalink
Bootstrap project
Browse files Browse the repository at this point in the history
  • Loading branch information
fed committed Dec 9, 2017
1 parent 84fefb5 commit 952536e
Show file tree
Hide file tree
Showing 7 changed files with 1,784 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
@@ -0,0 +1,3 @@
{
"presets": ["env", "react"]
}
13 changes: 13 additions & 0 deletions .editorconfig
@@ -0,0 +1,13 @@
# http://editorconfig.org
root = true

[*]
end_of_line = LF
charset = utf-8
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
11 changes: 11 additions & 0 deletions .flowconfig
@@ -0,0 +1,11 @@
[ignore]

[include]

[libs]

[lints]

[options]

[strict]
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
44 changes: 44 additions & 0 deletions index.js
@@ -0,0 +1,44 @@
// @flow
import * as React from 'react';
import ReactGA from 'react-ga';
import { withRouter } from 'react-router-dom';
import type { Location, RouterHistory } from 'react-router-dom';

type Props = {
id: string,
children?: React.Node,
debug: boolean,
location: Location,
history: RouterHistory
};

class ReactRouterGA extends React.Component<Props> {
constructor(props) {
super(props);
ReactGA.initialize(props.id);
}

componentDidMount() {
this.sendPageView(this.props.location);
this.props.history.listen(this.sendPageView);
}

sendPageView(location: Location) {
ReactGA.set({ page: location.pathname });
ReactGA.pageview(location.pathname);

if (this.props.debug) {
console.info(`[react-router-ga] Page view: ${location.pathname}`);
}
}

render() {
return this.props.children;
}
}

ReactRouterGA.defaultProps = {
debug: false
};

export default withRouter(Analytics);
37 changes: 37 additions & 0 deletions package.json
@@ -0,0 +1,37 @@
{
"name": "react-router-ga",
"version": "0.0.0",
"main": "lib/index.js",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/fknussel/react-router-ga.git"
},
"author": {
"name": "Federico Knüssel",
"email": "fknussel@gmail.com"
},
"keywords": [
"react-router-ga",
"react-router-dom",
"react-ga",
"analytics",
"react-analytics",
"react-router-analytics"
],
"scripts": {
"flow": "flow",
"build": "babel index.js --out-file lib/index.js"
},
"peerDependencies": {
"react": "^16.2.0",
"react-ga": "^2.3.5",
"react-router-dom": "^4.2.2"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"flow-bin": "^0.61.0"
}
}

0 comments on commit 952536e

Please sign in to comment.