GoogleAnalytics

Setup

    1.
    Sign up for Google Analytics and create a new web property.
    2.
    Add the JavaScript Tracking Snippet to your site. Update the tracking snippet with your tracking Id.
    During development and testing it is often helpful to use the debug version of analytics.js. Follow the instructions here to enable it.
    3.
    Install the target:
    1
    npm install --save @redux-beacon/google-analytics
    Copied!

Multiple Trackers Setup

    This target supports named trackers. Add the following line to the tracking snippet for each named tracker:
    1
    ga('create', 'UA-XXXXX-Z', 'auto', 'clientTracker');
    Copied!
    The tracker can be specified in each event definition
    using the tracker property.

Ecommerce Plugin Setup

    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

1
import GoogleAnalytics from '@redux-beacon/google-analytics';
2
3
// Create or import an events map.
4
// See "getting started" pages for instructions.
5
6
const ga = GoogleAnalytics();
7
8
const gaMiddleware = createMiddleware(eventsMap, ga);
9
const gaMetaReducer = createMetaReducer(eventsMap, ga);
Copied!

Event Definitions

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.

pageView

Docs:

1
import { trackPageView } from '@redux-beacon/google-analytics';
2
3
const pageView = trackPageView((action, prevState, nextState) => {
4
return {
5
page: /* fill me in */,
6
title: /* (optional) */,
7
location: /* (optional) */,
8
};
9
}, /* (optional) tracker names array or tracker name string */ );
Copied!
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:

1
import { trackEvent } from '@redux-beacon/google-analytics';
2
3
const event = trackEvent((action, prevState, nextState) => {
4
return {
5
category: /* fill me in */,
6
action: /* fill me in */,
7
label: /* (optional) */,
8
value: /* (optional) */,
9
};
10
}, /* (optional) tracker names array or tracker name string */ );
Copied!

timing

Docs:

1
import { trackTiming } from '@redux-beacon/google-analytics';
2
3
const userTiming = trackTiming((action, prevState, nextState) => {
4
return {
5
category: /* fill me in */,
6
var: /* fill me in */,
7
value: /* fill me in */,
8
label: /* (optional) */,
9
};
10
}, /* (optional) tracker names array or tracker name string */ );
Copied!

socialInteraction

Docs:

1
import { trackSocialInteraction } from '@redux-beacon/google-analytics';
2
3
const socialInteraction = trackSocialInteraction((action, prevState, nextState) => {
4
return {
5
network: /* fill me in */,
6
action: /* fill me in */,
7
target: /* fill me in */,
8
};
9
}, /* (optional) tracker names array or tracker name string */ );
Copied!

exception

Docs:

1
import { trackException } from '@redux-beacon/google-analytics';
2
3
const exception = trackException((action, prevState, nextState) => {
4
return {
5
description: /* (optional) */,
6
isFatal: /* (optional) */,
7
};
8
}, /* (optional) tracker names array or tracker name string */ );
Copied!
Don't need to track description or isFatal?
1
import { trackException } from '@redux-beacon/google-analytics';
2
3
const noop = () => {};
4
const exception = trackException(noop, /* (optional) tracker names array or tracker name string */ );
Copied!

ecommItem

Docs:

Requires:

1
import { trackEcommItem } from '@redux-beacon/google-analytics';
2
3
const ecommItem = trackEcommItem((action, prevState, nextState) => {
4
return {
5
id: /* fill me in */,
6
name: /* fill me in */,
7
sku: /* (optional) */,
8
category: /* (optional) */,
9
price: /* (optional) */,
10
quantity: /* (optional) */,
11
};
12
}, /* (optional) tracker names array or tracker name string */ );
Copied!

ecommTransaction

Docs:

Requires:

1
import { trackEcommTransaction } from '@redux-beacon/google-analytics';
2
3
const ecommTransaction = trackEcommTransaction((action, prevState, nextState) => {
4
return {
5
id: /* fill me in */,
6
affiliation: /* (optional) */,
7
revenue: /* (optional) */,
8
shipping: /* (optional) */,
9
tax: /* (optional) */,
10
};
11
}, /* (optional) tracker names array or tracker name string */ );
Copied!

ecommSend

Docs:

Requires:

1
import { ecommSend } from '@redux-beacon/google-analytics';
2
3
const ecommSendSignal = ecommSend(/* (optional) tracker names array or tracker name string */);
Copied!

ecommClear

Docs:

Requires:

1
import { ecommClear } from '@redux-beacon/google-analytics';
2
3
const ecommClearSignal = ecommClear(/* (optional) tracker names array or tracker name string */);
Copied!

ecommImpression

Docs:

Requires:

1
import { trackEcommImpression } from '@redux-beacon/google-analytics';
2
3
const ecommImpression = trackEcommImpression((action, prevState, nextState) => {
4
return {
5
id: /* either this or the name field has to be filled */,
6
name: /* either this or the id field has to be filled */,
7
list: /* (optional) */,
8
brand: /* (optional) */,
9
category: /* (optional) */,
10
variant: /* (optional) */,
11
position: /* (optional) */,
12
price: /* (optional) */,
13
};
14
}, /* (optional) tracker names array or tracker name string */ );
Copied!

ecommProduct

Docs:

Requires:

1
import { trackEcommProduct } from '@redux-beacon/google-analytics';
2
3
const ecommProduct = trackEcommProduct((action, prevState, nextState) => {
4
return {
5
id: /* either this or the name field has to be filled */,
6
name: /* either this or the id field has to be filled */,
7
brand: /* (optional) */,
8
category: /* (optional) */,
9
variant: /* (optional) */,
10
price: /* (optional) */,
11
quantity: /* (optional) */,
12
coupon: /* (optional) */,
13
position: /* (optional) */,
14
};
15
}, /* (optional) tracker names array or tracker name string */ );
Copied!

ecommPromotion

Docs:

Requires:

1
import { trackEcommPromotion } from '@redux-beacon/google-analytics';
2
3
const ecommPromotion = trackEcommPromotion((action, prevState, nextState) => {
4
return {
5
id: /* either this or the name field has to be filled */,
6
name: /* either this or the id field has to be filled */,
7
creative: /* (optional) */,
8
position: /* (optional) */,
9
};
10
}, /* (optional) tracker names array or tracker name string */ );
Copied!

ecommAction

Docs:

Requires:

1
import { trackEcommAction } from '@redux-beacon/google-analytics';
2
3
const ecommAction = trackEcommAction((action, prevState, nextState) => {
4
return {
5
actionName: /* fill me in */
6
id: /* fill me in if the actionName is "purchase" or "refund" */,
7
affiliation: /* (optional) */,
8
revenue: /* (optional) */,
9
tax: /* (optional) */,
10
shipping: /* (optional) */,
11
coupon: /* (optional) */,
12
list: /* (optional) */,
13
step: /* (optional) */,
14
option: /* (optional) */,
15
};
16
}, /* (optional) tracker names array or tracker name string */ );
Copied!
Last modified 2yr ago