Skip to content
This repository was archived by the owner on Jun 20, 2025. It is now read-only.
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
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,15 @@ var PiwikTracker = function(opts) {
applyModifierAndTrackLocation(modifier, location);
});

if (!opts.ignoreInitialVisit && history.location) {
applyModifierAndTrackLocation(modifier, history.location);
var initialLocation;
if (history.location) {
initialLocation = history.location;
} else if (typeof history.getCurrentLocation === 'function') {
initialLocation = history.getCurrentLocation();
}

if (!opts.ignoreInitialVisit && initialLocation) {
applyModifierAndTrackLocation(modifier, initialLocation);
}

return history;
Expand Down
33 changes: 33 additions & 0 deletions test/client.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,39 @@ describe('piwik-react-router client tests', function () {
]);
});

it ('should correctly track the initial visit if opts.ignoreInitialVisit is disabled with React Router v3', () => {
const piwikReactRouter = testUtils.requireNoCache('../')({
url: 'foo.bar',
siteId: 1,
});

const unlistenFn = sinon.spy();
let listenStub = sinon.stub().returns(unlistenFn);

var object = { getCurrentLocation: function() {
return {
pathname: '/foo/bar.html',
search: '?foo=bar'
};
}}

const locationFn = sinon.spy(object, "getCurrentLocation");

const history = {
listen: listenStub,
getCurrentLocation: locationFn
};

piwikReactRouter.connectToHistory(history);

assert.includeDeepMembers(window._paq, [
[ 'setCustomUrl', '/foo/bar.html?foo=bar' ],
[ 'trackPageView' ]
]);

assert.isTrue(locationFn.called);
});

it ('should correctly ignore the initial visit if the appropriate option is enabled', () => {
const piwikReactRouter = testUtils.requireNoCache('../')({
url: 'foo.bar',
Expand Down