Skip to content

Commit

Permalink
Adding analytics to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmfriedman committed Feb 15, 2019
1 parent 9e031f3 commit 59da475
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
Binary file modified icon.sketch
Binary file not shown.
35 changes: 34 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -57,6 +57,8 @@
"@types/node": "^10.12.18",
"@types/react": "^16.8.3",
"@types/react-dom": "^16.0.11",
"@types/react-router": "^4.4.4",
"@types/react-router-dom": "^4.3.1",
"babel-loader": "^8.0.5",
"copyfiles": "^2.1.0",
"enzyme": "^3.8.0",
Expand All @@ -69,6 +71,7 @@
"react-app-rewire-hot-loader": "^1.0.3",
"react-app-rewired": "^2.0.2",
"react-dom": "^16.8.1",
"react-ga": "^2.5.7",
"react-hot-loader": "^4.6.3",
"react-markdown-loader": "git+https://github.com/jamesmfriedman/react-markdown-loader.git#master",
"react-router-dom": "^4.3.1",
Expand All @@ -89,4 +92,4 @@
"not ie <= 11",
"not op_mini all"
]
}
}
20 changes: 17 additions & 3 deletions src/rmwc/docs/index.tsx
@@ -1,5 +1,8 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Router } from 'react-router-dom';
import createBrowserHistory from 'history/createBrowserHistory'
import ReactGA from 'react-ga';

import '@material/button/dist/mdc.button.css';
import '@material/card/dist/mdc.card.css';
Expand Down Expand Up @@ -47,15 +50,17 @@ import { AppContainer } from 'react-hot-loader';
import App from './App';
// @ts-ignore
import { unregister } from './registerServiceWorker';
// @ts-ignore
import { BrowserRouter as Router } from 'react-router-dom';
import { RMWCProvider } from '@rmwc/provider';

const history = createBrowserHistory({
basename: process.env.PUBLIC_URL
});

const renderApp = (Component: React.ComponentType<any>) => {
ReactDOM.render(
<RMWCProvider>
<AppContainer>
<Router basename={process.env.PUBLIC_URL}>
<Router history={history}>
<Component location={window.location.href} />
</Router>
</AppContainer>
Expand All @@ -70,8 +75,17 @@ if (module.hot) {
module.hot.accept(['./App'], () => renderApp(App));
}

const initAnalytics = () => {
ReactGA.initialize('UA-97702366-5');
const doPageView = () => ReactGA.pageview(window.location.pathname + window.location.search)
history.listen(() => doPageView());
doPageView();
}


const init = () => {
renderApp(App);
initAnalytics();
unregister();
};

Expand Down

0 comments on commit 59da475

Please sign in to comment.