티스토리 뷰

Front end/React

React-google analytics 달기

Ideveloper2 2018. 2. 26. 18:38

React-google analytics 달기


> ReactGA npm 사용하기

https://milooy.wordpress.com/2016/01/14/google-analtyics-2-google-tag-manager/ 참고


import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { ConnectedRouter } from 'react-router-redux';
// import { BrowserRouter } from 'react-router-dom';
import { AppContainer } from 'react-hot-loader';

import createHistory from 'history/createBrowserHistory';

import App from 'src/App';
import createNewStore from 'src/redux/createNewStore';

import registerServiceWorker from './registerServiceWorker';
import './index.scss';

const history = createHistory();
const store = createNewStore(history);

const ReactGA = require('react-ga');

ReactGA.initialize('UA-69160528-10', { debug: true });

const onUpdate = () => {
 ReactGA.set({ page: window.location.pathname });
 ReactGA.pageview(window.location.pathname);
};

const render = Component => {
 ReactDOM.render(
   <AppContainer>
     <Provider store={store}>
       <ConnectedRouter onUpdate={onUpdate} history={history}>
         <Component />
       </ConnectedRouter>
     </Provider>
   </AppContainer>,
   document.getElementById('root')
);
};

render(App);

if (module.hot) {
 module.hot.accept('src/App', () => {
   render(App);
});
}

registerServiceWorker();

'Front end > React' 카테고리의 다른 글

React - 리덕스 미들웨어  (0) 2018.03.02
Redux- 리덕스 총정리하기  (0) 2018.03.02
React-Link to로 화면전환시 맨위로 스크롤가게하기  (0) 2018.02.21
리액트 -What is react?  (1) 2018.02.14
리액트-Redux  (0) 2018.02.09
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
TAG
more
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함