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

Commit

Permalink
Fix test, update bower.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Levinson committed Oct 8, 2015
1 parent 9136342 commit 7d7a36b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"priate": true,
"name": "bulbs-public-analytics-manager",
"private": true,
"scripts": {
"test": "./node_modules/karma/bin/karma start resources/karma.conf.js"
},
Expand Down
25 changes: 12 additions & 13 deletions src/analytics-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,27 @@ var AnalyticsManager = {
}
},

getParameterByName: function(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(this.getWindowLocation().search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
},

pathInfo: function () {
var pathInfo;
var path = this.getWindowLocation().pathname;
var searchQuery = getParameterByName(this._settings.searchQueryParam);
// http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
if (this._settings.searchQueryParam) {
pathInfo = '/one/two/three?q=hey'
var searchQuery = this.getParameterByName(this._settings.searchQueryParam);
// Does a search query exist in the path?
if (searchQuery.length) {
pathInfo = '/search?' + this._settings.searchQueryParam + '=' + searchQuery;
} else {
pathInfo = path
pathInfo = path;
}

return pathInfo;
},

trackPageView: function(freshPage, optionalTitle) {
//var path = this.getWindowLocation().pathname;
var path = this.pathInfo();
if (this.trackedPaths.indexOf(path) < 0) {
ga('send', 'pageview', path);
Expand Down
7 changes: 4 additions & 3 deletions src/analytics-manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,10 @@ describe("AnalyticsManager", function() {
describe("#pathInfo", function() {

it("strips all parameters except the specified query parameter", function () {
var pathName = '/one/two/three';
var pathName = '/search';
var queryParam = 'q';
var goodQuery = queryParam + '=hey';
var searchQuery = 'depp'
var goodQuery = queryParam + '=' + searchQuery;

subject.init({
site: 'testsite',
Expand All @@ -333,7 +334,7 @@ describe("AnalyticsManager", function() {

sandbox.stub(subject, 'getWindowLocation').returns({
pathname: pathName,
search: 'no=123&' + goodQuery + '&notToBeIncluded=something'
search: 'no=123&' + goodQuery + '&notToBeIncluded=something',
});

var path = subject.pathInfo();
Expand Down

0 comments on commit 7d7a36b

Please sign in to comment.