Add this line to the end of your tracking snippet: ga('require', 'ecommerce');. This line must be added after you call ga('create', 'UA-XXXXX-Y').
Google Analytics will fail silently if you try to use these events without adding the require call in your initial tracking code. It is also not recommended to use GA's basic analytics plugin if you're also going to use the enhanced ecommerce plugin.
Enhanced Ecommerce Plugin Setup
Add this line to the end of your tracking snippet: ga('require', 'ec');. This line must be added after you call ga('create', 'UA-XXXXX-Y').
Google Analytics will fail silently if you try to use these events without adding the require call in your initial tracking code. It is also not recommended to use GA's basic analytics plugin if you're also going to use the basic ecommerce plugin.
Usage
import GoogleAnalytics from '@redux-beacon/google-analytics';
// Create or import an events map.
// See "getting started" pages for instructions.
const ga = GoogleAnalytics();
const gaMiddleware = createMiddleware(eventsMap, ga);
const gaMetaReducer = createMetaReducer(eventsMap, ga);
Event Definitions
pageView
Docs:
import { trackPageView } from '@redux-beacon/google-analytics';
const pageView = trackPageView((action, prevState, nextState) => {
return {
page: /* fill me in */,
title: /* (optional) */,
location: /* (optional) */,
};
}, /* (optional) tracker names array or tracker name string */ );
The last line of the tracking snippet ga('send', 'pageview') hits Google Analytics with a page view that matches the first loaded route. If you're tracking page views using Redux Beacon, be sure to remove this line so the initial page load isn't recorded twice.
event
Docs:
import { trackEvent } from '@redux-beacon/google-analytics';
const event = trackEvent((action, prevState, nextState) => {
return {
category: /* fill me in */,
action: /* fill me in */,
label: /* (optional) */,
value: /* (optional) */,
};
}, /* (optional) tracker names array or tracker name string */ );
timing
Docs:
import { trackTiming } from '@redux-beacon/google-analytics';
const userTiming = trackTiming((action, prevState, nextState) => {
return {
category: /* fill me in */,
var: /* fill me in */,
value: /* fill me in */,
label: /* (optional) */,
};
}, /* (optional) tracker names array or tracker name string */ );
socialInteraction
Docs:
import { trackSocialInteraction } from '@redux-beacon/google-analytics';
const socialInteraction = trackSocialInteraction((action, prevState, nextState) => {
return {
network: /* fill me in */,
action: /* fill me in */,
target: /* fill me in */,
};
}, /* (optional) tracker names array or tracker name string */ );
import { trackException } from '@redux-beacon/google-analytics';
const noop = () => {};
const exception = trackException(noop, /* (optional) tracker names array or tracker name string */ );
ecommItem
Docs:
Requires:
import { trackEcommItem } from '@redux-beacon/google-analytics';
const ecommItem = trackEcommItem((action, prevState, nextState) => {
return {
id: /* fill me in */,
name: /* fill me in */,
sku: /* (optional) */,
category: /* (optional) */,
price: /* (optional) */,
quantity: /* (optional) */,
};
}, /* (optional) tracker names array or tracker name string */ );
ecommTransaction
Docs:
Requires:
import { trackEcommTransaction } from '@redux-beacon/google-analytics';
const ecommTransaction = trackEcommTransaction((action, prevState, nextState) => {
return {
id: /* fill me in */,
affiliation: /* (optional) */,
revenue: /* (optional) */,
shipping: /* (optional) */,
tax: /* (optional) */,
};
}, /* (optional) tracker names array or tracker name string */ );
ecommSend
Docs:
Requires:
import { ecommSend } from '@redux-beacon/google-analytics';
const ecommSendSignal = ecommSend(/* (optional) tracker names array or tracker name string */);
ecommClear
Docs:
Requires:
import { ecommClear } from '@redux-beacon/google-analytics';
const ecommClearSignal = ecommClear(/* (optional) tracker names array or tracker name string */);
ecommImpression
Docs:
Requires:
import { trackEcommImpression } from '@redux-beacon/google-analytics';
const ecommImpression = trackEcommImpression((action, prevState, nextState) => {
return {
id: /* either this or the name field has to be filled */,
name: /* either this or the id field has to be filled */,
list: /* (optional) */,
brand: /* (optional) */,
category: /* (optional) */,
variant: /* (optional) */,
position: /* (optional) */,
price: /* (optional) */,
};
}, /* (optional) tracker names array or tracker name string */ );
ecommProduct
Docs:
Requires:
import { trackEcommProduct } from '@redux-beacon/google-analytics';
const ecommProduct = trackEcommProduct((action, prevState, nextState) => {
return {
id: /* either this or the name field has to be filled */,
name: /* either this or the id field has to be filled */,
brand: /* (optional) */,
category: /* (optional) */,
variant: /* (optional) */,
price: /* (optional) */,
quantity: /* (optional) */,
coupon: /* (optional) */,
position: /* (optional) */,
};
}, /* (optional) tracker names array or tracker name string */ );
ecommPromotion
Docs:
Requires:
import { trackEcommPromotion } from '@redux-beacon/google-analytics';
const ecommPromotion = trackEcommPromotion((action, prevState, nextState) => {
return {
id: /* either this or the name field has to be filled */,
name: /* either this or the id field has to be filled */,
creative: /* (optional) */,
position: /* (optional) */,
};
}, /* (optional) tracker names array or tracker name string */ );
ecommAction
Docs:
Requires:
import { trackEcommAction } from '@redux-beacon/google-analytics';
const ecommAction = trackEcommAction((action, prevState, nextState) => {
return {
actionName: /* fill me in */
id: /* fill me in if the actionName is "purchase" or "refund" */,
affiliation: /* (optional) */,
revenue: /* (optional) */,
tax: /* (optional) */,
shipping: /* (optional) */,
coupon: /* (optional) */,
list: /* (optional) */,
step: /* (optional) */,
option: /* (optional) */,
};
}, /* (optional) tracker names array or tracker name string */ );
Don't see your event listed? Please submit a pull request to the with the missing event. Use the source of the existing event-helpers to guide your work. If you need any support feel free to make the pull request with all you're able to do. We can fill in the gaps from there.