Skip to content
Open
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
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -50,14 +51,15 @@ class ReactRouterGA extends React.Component<Props> {
}

// 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}`);
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}, {
Expand Down