Cleanup default analytics function #113

Merged
robinnorth merged 4 commits from cleanup/analytics into master 2018-01-25 02:51:00 -05:00
Showing only changes of commit 01fb72ceeb - Show all commits

View File

@@ -3,14 +3,13 @@
var defaultSwitches = require("../switches") var defaultSwitches = require("../switches")
module.exports = function(options) { module.exports = function(options) {
this.options = options options.elements = options.elements || "a[href], form[action]"
this.options.elements = this.options.elements || "a[href], form[action]" options.selectors = options.selectors || ["title", ".js-Pjax"]
this.options.selectors = this.options.selectors || ["title", ".js-Pjax"] options.switches = options.switches || {}
this.options.switches = this.options.switches || {} options.switchesOptions = options.switchesOptions || {}
this.options.switchesOptions = this.options.switchesOptions || {} options.history = options.history || true
this.options.history = this.options.history || true options.analytics = (typeof options.analytics === "function" || options.analytics === false) ?
this.options.analytics = (typeof this.options.analytics === "function" || this.options.analytics === false) ? options.analytics :
this.options.analytics :
function() { function() {
if (window._gaq) { if (window._gaq) {
_gaq.push(["_trackPageview"]) _gaq.push(["_trackPageview"])
@@ -19,20 +18,22 @@ module.exports = function(options) {
ga("send", "pageview", {page: location.pathname, title: document.title}) ga("send", "pageview", {page: location.pathname, title: document.title})
} }
} }
this.options.scrollTo = (typeof this.options.scrollTo === "undefined") ? 0 : this.options.scrollTo; options.scrollTo = (typeof options.scrollTo === "undefined") ? 0 : options.scrollTo;
this.options.cacheBust = (typeof this.options.cacheBust === "undefined") ? true : this.options.cacheBust options.scrollRestoration = (typeof options.scrollRestoration !== "undefined") ? options.scrollRestoration : true
this.options.debug = this.options.debug || false options.cacheBust = (typeof options.cacheBust === "undefined") ? true : options.cacheBust
this.options.timeout = this.options.timeout || 0 options.debug = options.debug || false
this.options.scrollRestoration = (typeof this.options.scrollRestoration !== "undefined") ? this.options.scrollRestoration : true options.timeout = options.timeout || 0
// we cant replace body.outerHTML or head.outerHTML // we cant replace body.outerHTML or head.outerHTML
// it create a bug where new body or new head are created in the dom // it create a bug where new body or new head are created in the dom
// if you set head.outerHTML, a new body tag is appended, so the dom get 2 body // if you set head.outerHTML, a new body tag is appended, so the dom get 2 body
// & it break the switchFallback which replace head & body // & it break the switchFallback which replace head & body
if (!this.options.switches.head) { if (!options.switches.head) {
this.options.switches.head = defaultSwitches.switchElementsAlt options.switches.head = defaultSwitches.switchElementsAlt
} }
if (!this.options.switches.body) { if (!options.switches.body) {
this.options.switches.body = defaultSwitches.switchElementsAlt options.switches.body = defaultSwitches.switchElementsAlt
} }
this.options = options
} }