@njakob/gtag
v0.0.1
Published
Simple Google Analytics wrapper for Redux
Downloads
3
Readme
Installation
$ npm install @njakob/gtag
$ yarn add @njakob/gtag
Usage
Redux
import { createStore, applyMiddleware, combineReducers, compose } from 'redux';
import * as gtag from '@njakob/gtag';
const yourEnhancers = compose(
applyMiddleware(
gtag.middleware({ gaTrackingID: 'YOUR_TRACKING_ID' }),
// Other middlewares
),
);
const store = createStore(yourReducer, yourEnhancers);
store.dispatch(gtag.trackPageViewAction('/'))
Server side
import { getSnippet } from '@njakob/gtag';
export default () => `<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
</head>
<body>
<div id="react-root"></div>
${gtag.getSnippet()}
</body>
</html>`;
Changelog
See changelog.