From a9b2d72ef01549a70222aeb3b3e6b46850c1f800 Mon Sep 17 00:00:00 2001 From: Adlen Date: Thu, 7 Apr 2016 11:41:39 +0200 Subject: [PATCH] Feat(pageview) - add location parameter --- README.md | 2 ++ index.client.js | 2 ++ tests/unit/index.client.js | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/README.md b/README.md index df92231..3884b6c 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ 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 }); @@ -51,6 +52,7 @@ ReactI13n.getInstance().execute('pageview', { this.props.i13n.executeEvent('pageview', { tracker: [tracker name], // optional page: [page url], + location: [page location], title: [page title] }); ``` diff --git a/index.client.js b/index.client.js index 0c04dde..30a6c00 100644 --- a/index.client.js +++ b/index.client.js @@ -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 */ @@ -61,6 +62,7 @@ ReactI13nGoogleAnalytics.prototype.getPlugin = function () { arguments: [ 'pageview', { + location: payload.location, page: payload.url, title: payload.title, hitCallback: callback diff --git a/tests/unit/index.client.js b/tests/unit/index.client.js index 2608d33..9de4870 100644 --- a/tests/unit/index.client.js +++ b/tests/unit/index.client.js @@ -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 () { @@ -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 () {