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.constga=GoogleAnalytics();constgaMiddleware=createMiddleware(eventsMap, ga);constgaMetaReducer=createMetaReducer(eventsMap, ga);
Don't see your event listed? Please submit a pull request to the Redux Beacon repository 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.
import { trackPageView } from'@redux-beacon/google-analytics';constpageView=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.
import { trackEvent } from'@redux-beacon/google-analytics';constevent=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 */ );
import { trackTiming } from'@redux-beacon/google-analytics';constuserTiming=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 */ );
import { trackSocialInteraction } from'@redux-beacon/google-analytics';constsocialInteraction=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 { trackEcommImpression } from'@redux-beacon/google-analytics';constecommImpression=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 */ );
import { trackEcommProduct } from'@redux-beacon/google-analytics';constecommProduct=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 */ );
import { trackEcommPromotion } from'@redux-beacon/google-analytics';constecommPromotion=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 */ );