From 5108babfc5563776da1996008684668411b2561a Mon Sep 17 00:00:00 2001 From: wengcan Date: Mon, 5 Nov 2018 15:56:03 +0800 Subject: [PATCH 1/2] add option to add search --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index e5bb804..bd28d59 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ import type { Location, RouterHistory } from 'react-router-dom'; type Props = { id: string, // Google Analytics Tracking ID debug: boolean, + withSearch?:boolean, children?: React.Node, location: Location, history: RouterHistory @@ -50,14 +51,15 @@ class ReactRouterGA extends React.Component { } // Sets the page value on the tracker. - window.ga('set', 'page', location.pathname); + let page = location.pathname + ( this.props.withSearch?location.search:"" ); + window.ga('set', 'page', page ); // Sending the pageview no longer requires passing the page // value since it's now stored on the tracker object. window.ga('send', 'pageview'); if (this.props.debug) { - console.info(`[react-router-ga] Page view: ${location.pathname}`); + console.info(`[react-router-ga] Page view: ${page}`); } } From 1ed43e55c7ad633a2763b381814b4f9ab609e6de Mon Sep 17 00:00:00 2001 From: wengcan Date: Mon, 5 Nov 2018 16:00:35 +0800 Subject: [PATCH 2/2] add lib --- lib/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 03f5703..bee055c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -69,14 +69,15 @@ var ReactRouterGA = function (_React$Component) { } // Sets the page value on the tracker. - window.ga('set', 'page', location.pathname); + var page = location.pathname + (this.props.withSearch ? location.search : ""); + window.ga('set', 'page', page); // Sending the pageview no longer requires passing the page // value since it's now stored on the tracker object. window.ga('send', 'pageview'); if (this.props.debug) { - console.info('[react-router-ga] Page view: ' + location.pathname); + console.info('[react-router-ga] Page view: ' + page); } } }, {