Skip to content

Commit

Permalink
Merge branch 'master' into optional-piwik-injection
Browse files Browse the repository at this point in the history
  • Loading branch information
joernroeder committed May 12, 2017
2 parents cf26eec + 75f75ae commit 086786e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ _Starting with v2.0 react-router won't provide a default history. [Why?](https:/
var PiwikReactRouter = require('piwik-react-router');

var piwik = PiwikReactRouter({
url : 'your-piwik-installation.com',
siteId : 1
url: 'your-piwik-installation.com',
siteId: 1
});

<Router history={piwik.connectToHistory(history)}>
Expand Down Expand Up @@ -82,6 +82,16 @@ By enabling `ignoreInitialVisit` it connects to the history without tracking the
By disabling `injectScript` the piwik.js script will not be injected automatically to allow a separate loading.


### clientTrackerName: `'piwik.js'`

The name of the `piwik.js` static resource on the Piwik server. Set this option if the Piwik instance uses a different name.


### serverTrackerName: `'piwik.php'`

The name of the `piwik.php` script on the Piwik server. Set this option if the Piwik instance uses a different name.


## API

### track (Location location)
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ var PiwikTracker = function(opts) {
opts.updateDocumentTitle = ((opts.updateDocumentTitle !== undefined) ? opts.updateDocumentTitle : true);
opts.ignoreInitialVisit = ((opts.ignoreInitialVisit !== undefined) ? opts.ignoreInitialVisit : false);
opts.injectScript = ((opts.injectScript !== undefined) ? opts.injectScript : true);
opts.clientTrackerName = ((opts.clientTrackerName !== undefined) ? opts.clientTrackerName : 'piwik.js');
opts.serverTrackerName = ((opts.serverTrackerName !== undefined) ? opts.serverTrackerName : 'piwik.php');

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 @@ -140,7 +142,7 @@ var PiwikTracker = function(opts) {
}

push(['setSiteId', opts.siteId]);
push(['setTrackerUrl', u+'piwik.php']);
push(['setTrackerUrl', u+opts.serverTrackerName]);

if (opts.userId) {
push(['setUserId', opts.userId]);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "piwik-react-router",
"version": "0.8.0",
"version": "0.8.1",
"description": "Piwik analytics component for react-router",
"keywords": [
"react",
Expand Down
37 changes: 37 additions & 0 deletions test/client.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ describe('piwik-react-router client tests', function () {
]);
});

it ('should correctly use client and server tracker name defaults', () => {
const piwikReactRouter = testUtils.requireNoCache('../')({
url: 'foo.bar',
siteId: 1
});

assert.sameDeepMembers(window._paq, [
[ 'setSiteId', 1 ],
[ 'setTrackerUrl', 'http://foo.bar/piwik.php' ],
[ 'enableLinkTracking' ]
]);
assert.strictEqual(window.document.querySelector('script').src, 'http://foo.bar/piwik.js');
});

describe ('use https protocol', () => {
before(() => {
this.jsdom();
Expand Down Expand Up @@ -116,6 +130,29 @@ describe('piwik-react-router client tests', function () {
});
});

describe ('should allow overriding piwik.js and piwik.php names', () => {
before(() => {
this.jsdom();
this.jsdom = require('jsdom-global')(jsdomBody, {
url: 'https://foo.bar'
});
});

it('should use specified names for piwik.js and piwik.php', () => {
const piwikReactRouter = testUtils.requireNoCache('../')({
url: 'foo.bar',
siteId: 1,
clientTrackerName: 'foo.js',
serverTrackerName: 'bar.php'
});

assert.includeDeepMembers(window._paq, [
['setTrackerUrl', 'https://foo.bar/bar.php'],
]);
assert.strictEqual(window.document.querySelector('script').src, 'https://foo.bar/foo.js');
});
});

// todo: test warning
describe ('should correctly warn about invalid options and return the api shim', () => {
it('should correctly return the shim and throw a warning without parameters', () =>{
Expand Down

0 comments on commit 086786e

Please sign in to comment.