Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(pageview) - add location parameter #6

Merged
merged 1 commit into from
Apr 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ var ReactI13n = require('react-i13n').ReactI13n;
ReactI13n.getInstance().execute('pageview', {
tracker: [tracker name], // optional
page: [page url], // get the page url, or keep empty to let google analytics handle it
location: [page location], // get the page location, or keep empty to let google analytics handle it
title: [page title] // get the page title, or keep empty to let google analytics handle it
});

// in component (React 0.14+)
this.props.i13n.executeEvent('pageview', {
tracker: [tracker name], // optional
page: [page url],
location: [page location],
title: [page title]
});
```
Expand Down
2 changes: 2 additions & 0 deletions index.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ ReactI13nGoogleAnalytics.prototype.getPlugin = function () {
* @param {Object} payload payload object
* @param {Object} payload.tracker page title
* @param {Object} payload.title page title
* @param {Object} payload.location page location
* @param {Object} payload.url current url
* @param {Function} calback callback function
*/
Expand All @@ -61,6 +62,7 @@ ReactI13nGoogleAnalytics.prototype.getPlugin = function () {
arguments: [
'pageview',
{
location: payload.location,
page: payload.url,
title: payload.title,
hitCallback: callback
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/index.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ describe('ga plugin client', function () {
global.ga = function (actionSend, actionName, options) {
expect(actionSend).to.eql('send');
expect(actionName).to.eql('pageview');
expect(options.location).to.eql('http://www.mywebsite.com/foo');
expect(options.page).to.eql('/foo');
expect(options.title).to.eql('Foo');
options.hitCallback && options.hitCallback();
};
reactI13nGoogleAnalytics.getPlugin().eventHandlers.pageview({
location: 'http://www.mywebsite.com/foo',
url: '/foo',
title: 'Foo'
}, function beaconCallback () {
Expand All @@ -78,12 +80,14 @@ describe('ga plugin client', function () {
global.ga = function (actionSend, actionName, options) {
expect(actionSend).to.eql(tracker + '.send');
expect(actionName).to.eql('pageview');
expect(options.location).to.eql('http://www.mywebsite.com/foo');
expect(options.page).to.eql('/foo');
expect(options.title).to.eql('Foo');
options.hitCallback && options.hitCallback();
};
reactI13nGoogleAnalytics.getPlugin().eventHandlers.pageview({
tracker: tracker,
location: 'http://www.mywebsite.com/foo',
url: '/foo',
title: 'Foo'
}, function beaconCallback () {
Expand Down