Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Merge pull request #6 from theonion/fix-clickventure
Browse files Browse the repository at this point in the history
Fix clickventure
  • Loading branch information
benghaziboy committed Jan 27, 2016
2 parents c232704 + 6d490fc commit 9a723cb
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bulbs-public-analytics-manager",
"version": "0.1.1",
"version": "0.1.2",
"authors": [
"Andrew Kos <akos@theonion.com>",
"Chris Sprehe <csprehe@theonion.com>",
Expand Down
17 changes: 16 additions & 1 deletion src/analytics-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,24 @@ var AnalyticsManager = {
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
},

getNodeHash: function(hash) {
if (hash) {
var re = RegExp('#\[A-Za-z0-9-]+');
var results = hash.match(re);
if (results && hash.search(re) === 0) {
return results[0];
}
}
},

pathInfo: function () {
var pathInfo;
var path = this.getWindowLocation().pathname;
var windowLocation = this.getWindowLocation();
var path = windowLocation.pathname;
var hash = this.getNodeHash(windowLocation.hash);
if (hash) {
path += hash;
}
var searchQuery = this.getParameterByName(this._settings.searchQueryParam);
if (searchQuery.length) {
pathInfo = path + '?' + this._settings.searchQueryParam + '=' + searchQuery;
Expand Down
63 changes: 62 additions & 1 deletion src/analytics-manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ describe("AnalyticsManager", function() {
it("strips all parameters except the specified query parameter", function () {
var pathName = '/search';
var queryParam = 'q';
var searchQuery = 'depp'
var searchQuery = 'depp';
var goodQuery = queryParam + '=' + searchQuery;

subject.init({
Expand Down Expand Up @@ -360,5 +360,66 @@ describe("AnalyticsManager", function() {

expect(path).to.equal(pathName);
});

it("should include any appended string formatted as a (#1) following the path preceding the query paramters", function() {
var pathName = '/clickventure';
var hash = '#5';
var queryParam = '?killme=kos';

subject.init({
site: 'testsite',
searchQueryParam: queryParam
});

sandbox.stub(subject, 'getWindowLocation').returns({
pathname: pathName,
search: pathName,
hash: hash + queryParam
});

var path = subject.pathInfo();
expect(path).to.equal(pathName + hash);
});

it("should include any appended string formatted as a (#1) following the path preceding the query paramters", function() {
var pathName = '/clickventure';
var hash = '#mambo-numba-5';
var queryParam = '?killme=kos';

subject.init({
site: 'testsite',
searchQueryParam: queryParam
});

sandbox.stub(subject, 'getWindowLocation').returns({
pathname: pathName,
search: pathName,
hash: hash + queryParam
});

var path = subject.pathInfo();
expect(path).to.equal(pathName + hash);
});

it("should exclude any appended string formatted as a (#1) following the path and follwing the query paramters", function() {
var pathName = '/clickventure';
var queryParam = '?mygarbage=fun#5';

subject.init({
site: 'testsite',
searchQueryParam: queryParam,
});

sandbox.stub(subject, 'getWindowLocation').returns({
pathname: pathName,
search: pathName,
hash: queryParam
});

var path = subject.pathInfo();

expect(path).to.equal(pathName);
});

});
});

0 comments on commit 9a723cb

Please sign in to comment.