Skip to content

Commit

Permalink
fixed #30
Browse files Browse the repository at this point in the history
  • Loading branch information
joernroeder committed Mar 20, 2017
1 parent 4e49b0c commit 36338df
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ By enabling this option occurring javascript errors will be tracked as a `JavaSc
see [http://davidwalsh.name/track-errors-google-analytics](http://davidwalsh.name/track-errors-google-analytics) for further details


### ignoreInitialVisit: `false`

By enabling `ignoreInitialVisit` it connects to the history without tracking the initial visit.


## API

### track (Location location)
Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var PiwikTracker = function(opts) {
opts.trackErrors = ((opts.trackErrors !== undefined) ? opts.trackErrors : false);
opts.enableLinkTracking = ((opts.enableLinkTracking !== undefined) ? opts.enableLinkTracking : true);
opts.updateDocumentTitle = ((opts.updateDocumentTitle !== undefined) ? opts.updateDocumentTitle : true);
opts.ignoreInitialVisit = ((opts.ignoreInitialVisit !== undefined) ? opts.ignoreInitialVisit : false);

if (!opts.url || !opts.siteId) {
// Only return warning if this is not in the test environment as it can break the Tests/CI.
Expand Down Expand Up @@ -98,6 +99,11 @@ var PiwikTracker = function(opts) {
track(loc);
});

if (!opts.ignoreInitialVisit && history.location) {
console.log('tracking initial visit', history.location);
track(history.location);
}

return history;
};

Expand Down
25 changes: 25 additions & 0 deletions test/client.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,31 @@ describe('piwik-react-router client tests', function () {
[ 'trackPageView' ]
]);
});

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

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

const history = {
listen: listenStub,
location: {
pathname: '/foo/bar.html',
search: '?foo=bar'
}
};

piwikReactRouter.connectToHistory(history);

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

it ('should correctly handle basename', () => {
Expand Down

0 comments on commit 36338df

Please sign in to comment.