Skip to content

Commit

Permalink
add click plugin url config back (#1874)
Browse files Browse the repository at this point in the history
  • Loading branch information
Karlie-777 committed Aug 3, 2022
1 parent 6d2a751 commit b14bb33
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PageAction } from "../../../src/events/PageAction";
import { DomContentHandler } from '../../../src/handlers/DomContentHandler';
import { IPageActionOverrideValues } from '../../../src/Interfaces/Datamodel'
import { mergeConfig } from "../../../src/common/Utils";
import { sanitizeUrl } from "../../../src/DataCollector";



Expand Down Expand Up @@ -1052,6 +1053,59 @@ export class ClickEventTest extends AITestClass {
Assert.equal(false, spy.called);
}
});

this.testCase({
name: "Test sanitizeUrl",
test: () => {
let fakeLocation1 = null;
let fakeLocation2 = {
protocol:"https:",
hostname:"www.test.com",
host:"www.test.com",
port:"3000",
pathname:"/path",
hash:"#test",
search:"?q=search&rlz=1C1CHBF"
} as any;
let fakeLocation3 = {
protocol:"https:",
host:"www.test.com",
port:"",
pathname:"",
hash:"",
search:"?q=search&rlz=1C1CHBF"
} as any;

const config1 = {
urlCollectHash: true,
urlCollectQuery: true
};
const config2 = {
urlCollectHash: false,
urlCollectQuery: false
};
const config3 = {
urlCollectHash:false,
urlCollectQuery: true
};


let url1 = sanitizeUrl(config1, fakeLocation1);
Assert.equal(null, url1);

let url2 = sanitizeUrl(config2, fakeLocation2);
Assert.equal("https://www.test.com:3000/path", url2);

let url3 = sanitizeUrl(config1,fakeLocation2);
Assert.equal("https://www.test.com:3000/path#test?q=search&rlz=1C1CHBF", url3);

let url4 = sanitizeUrl(config3, fakeLocation3);
Assert.equal("https://www.test.com?q=search&rlz=1C1CHBF", url4);

let url5 = sanitizeUrl(config1, fakeLocation3);
Assert.equal("https://www.test.com?q=search&rlz=1C1CHBF", url5);
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ export function sanitizeUrl(config: IClickAnalyticsConfiguration, location: Loca
var url = location.protocol + "//" + (location.hostname || location.host) + // location.hostname is not supported on Opera and Opera for Android
(isValueAssigned(location.port) ? ":" + location.port : "") +
location.pathname;

if (!!config.urlCollectHash) { // false by default
url += (isValueAssigned(location.hash)? location.hash : "");
}

if (!!config.urlCollectQuery) { // false by default
url += (isValueAssigned(location.search)? location.search : "");
}

return url;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ export interface IClickAnalyticsConfiguration {
* Default will be false
*/
dropInvalidEvents?: boolean;
/**
* Enables the logging of values after a "#" character of the URL. Default is "false."
*/
urlCollectHash?: boolean;
/**
* Enables the logging of the query string of the URL. Default is "false."
*/
urlCollectQuery?: boolean;
}

/**
Expand Down

0 comments on commit b14bb33

Please sign in to comment.