Preserve ability to disable analytics behavior, explicitly document this option

This commit is contained in:
Robin North
2018-01-24 11:26:13 +00:00
parent cc384b9b16
commit f642eec047
3 changed files with 27 additions and 30 deletions

View File

@@ -371,12 +371,14 @@ Enable pushState. Only disable if you are crazy.
Internaly, this option is used when `popstate` is used (to not pushState again). Internaly, this option is used when `popstate` is used (to not pushState again).
You should forget that option. You should forget that option.
##### `analytics` (Function, default to a function that push `_gaq` `trackPageview` or send `ga` `pageview` ##### `analytics` (Function|Boolean, default to a function that pushes `_gaq` `_trackPageview` or sends `ga` `pageview`
Function that allow you to add behavior for analytics. By default it try to track Function that allows you to add behavior for analytics. By default it tries to track
a pageview with Google Analytics. a pageview with Google Analytics.
It's called every time a page is switched, even for history buttons. It's called every time a page is switched, even for history buttons.
Set to `false` to disable this behavior.
##### `scrollTo` (Integer, default to 0) ##### `scrollTo` (Integer, default to 0)
Value (in px) to scrollTo when a page is switched. Value (in px) to scrollTo when a page is switched.
@@ -543,4 +545,3 @@ Clone this repository and run `npm run example`, which will open the example app
## [CHANGELOG](CHANGELOG.md) ## [CHANGELOG](CHANGELOG.md)
## [LICENSE](LICENSE) ## [LICENSE](LICENSE)

View File

@@ -9,7 +9,9 @@ module.exports = function(options) {
this.options.switches = this.options.switches || {} this.options.switches = this.options.switches || {}
this.options.switchesOptions = this.options.switchesOptions || {} this.options.switchesOptions = this.options.switchesOptions || {}
this.options.history = this.options.history || true this.options.history = this.options.history || true
this.options.analytics = (typeof this.options.analytics === "function") ? this.options.analytics : function() { this.options.analytics = (typeof this.options.analytics === "function" || this.options.analytics === false) ?
this.options.analytics :
function() {
if (window._gaq) { if (window._gaq) {
_gaq.push(["_trackPageview"]) _gaq.push(["_trackPageview"])
} }

View File

@@ -34,26 +34,20 @@ tape("test parse initalization options function", function(t) {
var options1 = {}; var options1 = {};
parseOptions.apply(body1, [options1]); parseOptions.apply(body1, [options1]);
t.deepEqual(body1.options.elements, "a[href], form[action]"); t.equal(body1.options.elements, "a[href], form[action]");
t.deepEqual(body1.options.selectors.length, 2, "selectors length"); t.equal(body1.options.selectors.length, 2, "selectors length");
t.deepEqual(body1.options.selectors[0], "title"); t.equal(body1.options.selectors[0], "title");
t.deepEqual(body1.options.selectors[1], ".js-Pjax"); t.equal(body1.options.selectors[1], ".js-Pjax");
t.equal(isObjLiteral(body1.options.switches), true);
t.deepEqual(isObjLiteral(body1.options.switches), true); t.equal(enumerableKeys(body1.options.switches), 2);// head and body
t.deepEqual(enumerableKeys(body1.options.switches), 2);// head and body t.equal(isObjLiteral(body1.options.switchesOptions), true);
t.equal(enumerableKeys(body1.options.switchesOptions), 0);
t.deepEqual(isObjLiteral(body1.options.switchesOptions), true); t.equal(body1.options.history, true);
t.deepEqual(enumerableKeys(body1.options.switchesOptions), 0); t.equal(typeof body1.options.analytics, "function");
t.equal(body1.options.scrollTo, 0);
t.deepEqual(body1.options.history, true); t.equal(body1.options.scrollRestoration, true);
t.equal(body1.options.cacheBust, true);
// TODO analytics is a little weird right now t.equal(body1.options.debug, false);
t.deepEqual(typeof body1.options.analytics, "function");
t.deepEqual(body1.options.scrollTo, 0);
t.deepEqual(body1.options.cacheBust, true);
t.deepEqual(body1.options.debug, false);
t.deepEqual(body1.options.scrollRestoration, true)
t.end(); t.end();
}); });