diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2016-02-13 13:02:06 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2016-03-08 00:28:22 +0300 |
commit | 33b5706a69265806f983a369156a4252d70b3e37 (patch) | |
tree | 480059eade428534f193371fb5aca26c7f8c297d /js | |
parent | 94ae3af6bd8b63560ffd8a432028ab0a6babe4ed (diff) |
fix overlay when using a custom piwik.php path for tracking
Diffstat (limited to 'js')
-rw-r--r-- | js/piwik.js | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/js/piwik.js b/js/piwik.js index 3f6a2f350e..6739d51b81 100644 --- a/js/piwik.js +++ b/js/piwik.js @@ -1702,6 +1702,21 @@ if (typeof window.Piwik !== 'object') { return -1; } + function stringEndsWith(str, suffix) { + str = String(str); + return str.indexOf(suffix, str.length - suffix.length) !== -1; + } + + function stringContains(str, needle) { + str = String(str); + return str.indexOf(needle) !== -1; + } + + function removeCharactersFromEndOfString(str, numCharactersToRemove) { + str = String(str); + return str.substr(0, str.length - numCharactersToRemove); + } + /************************************************************ * Element Visiblility ************************************************************/ @@ -2658,10 +2673,29 @@ if (typeof window.Piwik !== 'object') { return apiUrl; } - if (trackerUrl.slice(-9) === 'piwik.php') { - trackerUrl = trackerUrl.slice(0, trackerUrl.length - 9); + // if eg http://www.example.com/js/tracker.php?version=232323 => http://www.example.com/js/tracker.php + if (stringContains(trackerUrl, '?')) { + var posQuery = trackerUrl.indexOf('?'); + trackerUrl = trackerUrl.slice(0, posQuery); + } + + if (stringEndsWith(trackerUrl, 'piwik.php')) { + // if eg without domain or path "piwik.php" => '' + trackerUrl = removeCharactersFromEndOfString(trackerUrl, 'piwik.php'.length); + } else if (stringEndsWith(trackerUrl, '.php')) { + // if eg http://www.example.com/js/piwik.php => http://www.example.com/js/ + // or if eg http://www.example.com/tracker.php => http://www.example.com/ + var lastSlash = trackerUrl.lastIndexOf('/'); + var includeLastSlash = 1; + trackerUrl = trackerUrl.slice(0, lastSlash + includeLastSlash); + } + + // if eg http://www.example.com/js/ => http://www.example.com/ (when not minified Piwik JS loaded) + if (stringEndsWith(trackerUrl, '/js/')) { + trackerUrl = removeCharactersFromEndOfString(trackerUrl, 'js/'.length); } + // http://www.example.com/ return trackerUrl; } @@ -3058,16 +3092,6 @@ if (typeof window.Piwik !== 'object') { return false; } - function stringEndsWith(str, suffix) { - str = String(str); - return str.indexOf(suffix, str.length - suffix.length) !== -1; - } - - function removeCharactersFromEndOfString(str, numCharactersToRemove) { - str = String(str); - return str.substr(0, str.length - numCharactersToRemove); - } - /* * Extract pathname from URL. element.pathname is actually supported by pretty much all browsers including * IE6 apart from some rare very old ones |