Skip to content

Commit

Permalink
Fixes #3953 now detecting campaign parameters within the hash tag as …
Browse files Browse the repository at this point in the history
…well
  • Loading branch information
mattab committed May 24, 2013
1 parent d9473e5 commit 15277fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
11 changes: 4 additions & 7 deletions js/piwik.js
Expand Up @@ -752,13 +752,10 @@ if (typeof Piwik !== 'object') {
* Extract parameter from URL
*/
function getParameter(url, name) {
// scheme : // [username [: password] @] hostame [: port] [/ [path] [? query] [# fragment]]
var e = new RegExp('^(?:https?|ftp)(?::/*(?:[^?]+)[?])([^#]+)'),
matches = e.exec(url),
f = new RegExp('(?:^|&)' + name + '=([^&]*)'),
result = matches ? f.exec(matches[1]) : 0;

return result ? decodeWrapper(result[1]) : '';
var regexSearch = "[\\?&#]" + name + "=([^&#]*)";
var regex = new RegExp(regexSearch);
var results = regex.exec(url);
return results ? decodeWrapper(results[1]) : '';
}

/*
Expand Down
18 changes: 17 additions & 1 deletion tests/javascript/index.php
Expand Up @@ -436,7 +436,7 @@ function PiwikTest() {
});

test("Tracker getHostName(), getParameter(), urlFixup(), domainFixup(), titleFixup() and purify()", function() {
expect(47);
expect(57);

var tracker = Piwik.getTracker();

Expand All @@ -459,8 +459,24 @@ function PiwikTest() {

equal( tracker.hook.test._getParameter('http://piwik.org/', 'q'), '', 'no query');
equal( tracker.hook.test._getParameter('http://piwik.org/?q=test', 'q'), 'test', '?q');
equal( tracker.hook.test._getParameter('http://piwik.org/?q=test#aq=not', 'q'), 'test', '?q');
equal( tracker.hook.test._getParameter('http://piwik.org/?p=test1&q=test2', 'q'), 'test2', '&q');

// getParameter in hash tag
equal( tracker.hook.test._getParameter('http://piwik.org/?p=test1&q=test2#aq=not', 'q'), 'test2', '&q');
equal( tracker.hook.test._getParameter('http://piwik.org/?p=test1&q=test2#aq=not', 'aq'), 'not', '#aq');
equal( tracker.hook.test._getParameter('http://piwik.org/?p=test1&q=test2#bq=yes&aq=not', 'bq'), 'yes', '#bq');
equal( tracker.hook.test._getParameter('http://piwik.org/?p=test1&q=test2#pk_campaign=campaign', 'pk_campaign'), 'campaign', '#pk_campaign');
equal( tracker.hook.test._getParameter('http://piwik.org/?p=test1&q=test2#bq=yes&aq=not', 'q'), 'test2', '#q');

// URL decoded
equal( tracker.hook.test._getParameter('http://piwik.org/?q=http%3a%2f%2flocalhost%2f%3fr%3d1%26q%3dfalse', 'q'), 'http://localhost/?r=1&q=false', 'url');
equal( tracker.hook.test._getParameter('http://piwik.org/?q=http%3a%2f%2flocalhost%2f%3fr%3d1%26q%3dfalse&notq=not', 'q'), 'http://localhost/?r=1&q=false', 'url');

// non existing parameters
equal( tracker.hook.test._getParameter('http://piwik.org/?p=test1&q=test2#bq=yes&aq=not', 'bqq'), "", '#q');
equal( tracker.hook.test._getParameter('http://piwik.org/?p=test1&q=test2#bq=yes&aq=not', 'bq='), "", '#q');
equal( tracker.hook.test._getParameter('http://piwik.org/?p=test1&q=test2#bq=yes&aq=not', 'sp='), "", '#q');

equal( typeof tracker.hook.test._urlFixup, 'function', 'urlFixup' );

Expand Down

0 comments on commit 15277fb

Please sign in to comment.