Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clickanalytics plugin url config back #1874

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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