Skip to content

Commit

Permalink
Merge pull request #5 from Countly/search-query
Browse files Browse the repository at this point in the history
Search Query fortification
  • Loading branch information
ArtursKadikis authored Jan 3, 2024
2 parents 2330819 + d002ead commit 50cd80b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Added bot detection for workers
* Added the ability to clear stored device IDs in the workers
* Mitigated an issue where utm naming could have been affected if 'searchQuery' did not return '?'

## 23.12.2

Expand Down
14 changes: 7 additions & 7 deletions cypress/e2e/utm.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("UTM tests ", () => {
});
it("Checks if default utm tags works", () => {
hp.haltAndClearStorage(() => {
initMulti("YOUR_APP_KEY", "?utm_source=hehe&utm_medium=hehe1&utm_campaign=hehe2&utm_term=hehe3&utm_content=hehe4", undefined);
initMulti("YOUR_APP_KEY", "utm_source=hehe&utm_medium=hehe1&utm_campaign=hehe2&utm_term=hehe3&utm_content=hehe4", undefined);
cy.fetch_local_request_queue().then((rq) => {
cy.log(rq);
const custom = JSON.parse(rq[0].user_details).custom;
Expand All @@ -50,7 +50,7 @@ describe("UTM tests ", () => {
});
it("Checks if custom utm tags works", () => {
hp.haltAndClearStorage(() => {
initMulti("YOUR_APP_KEY", "?utm_aa=hehe&utm_bb=hoho", { aa: true, bb: true });
initMulti("YOUR_APP_KEY", "utm_aa=hehe&utm_bb=hoho", { aa: true, bb: true });
cy.fetch_local_request_queue().then((rq) => {
cy.log(rq);
const custom = JSON.parse(rq[0].user_details).custom;
Expand All @@ -69,13 +69,13 @@ describe("UTM tests ", () => {
initMulti("Countly_4", "?utm_source=hehe4", { ss: true });

// utm object not provided with default query
initMulti("Countly_3", "?utm_source=hehe3", undefined);
initMulti("Countly_3", "utm_source=hehe3", undefined);

// utm object not provided with inappropriate query
initMulti("Countly_5", "?utm_ss=hehe5", undefined);

// default (original) init with no custom tags and default query
initMulti("YOUR_APP_KEY", "?utm_source=hehe", undefined);
initMulti("YOUR_APP_KEY", "utm_source=hehe", undefined);

// check original
cy.fetch_local_request_queue().then((rq) => {
Expand Down Expand Up @@ -110,13 +110,13 @@ describe("UTM tests ", () => {
initMulti("YOUR_APP_KEY", "?utm_source=hehe", undefined);

// utm object not provided with full + weird query
initMulti("Countly_multi_1", "?utm_source=hehe&utm_medium=hehe1&utm_campaign=hehe2&utm_term=hehe3&utm_content=hehe4&fdsjhflkjhsdlkfjhsdlkjfhksdjhfkj+dsf;jsdlkjflk+=skdjflksjd=fksdfl;sd=sdkfmk&&&", undefined);
initMulti("Countly_multi_1", "utm_source=hehe&utm_medium=hehe1&utm_campaign=hehe2&utm_term=hehe3&utm_content=hehe4&fdsjhflkjhsdlkfjhsdlkjfhksdjhfkj+dsf;jsdlkjflk+=skdjflksjd=fksdfl;sd=sdkfmk&&&", undefined);

// utm object given that includes 2 default 1 custom, full plus custom query + gabledeboop
initMulti("Countly_multi_2", "?utm_source=hehe&utm_medium=hehe1&utm_campaign=hehe2&utm_term=hehe3&utm_content=hehe4&utm_sthelse=hehe5&fdsjhflkjhsdlkfjhsdlkjfhksdjhfkj+dsf;jsdlkjflk+=skdjflksjd=fksdfl;sd=sdkfmk&&&", { source: true, term: true, sthelse: true });

// empty init, garbage query + 1 default
initMulti("Countly_multi_3", "?dasdashdjkhaslkjdhsakj=dasmndlask=asdkljska&&utm_source=hehe", undefined);
initMulti("Countly_multi_3", "dasdashdjkhaslkjdhsakj=dasmndlask=asdkljska&&utm_source=hehe", undefined);

// full default utm obj + custom 1, full query + 1
initMulti("Countly_multi_4", "?utm_source=hehe&utm_medium=hehe1&utm_campaign=hehe2&utm_term=hehe3&utm_content=hehe4&utm_next=hehe5", { source: true, medium: true, campaign: true, term: true, content: true, next: true });
Expand Down Expand Up @@ -171,7 +171,7 @@ describe("UTM tests ", () => {
initMulti("Countly_multi_next_1", "?utm_sourcer=hehe&utm_mediumr=hehe1&utm_campaignr=hehe2&utm_rterm=hehe3&utm_corntent=hehe4&fdsjhflkjhsdlkfjhsdlkjfhksdjhfkj+dsf;jsdlkjflk+=skdjflksjd=fksdfl;sd=sdkfmk&&&", undefined);

// utm object default, custom query + gabledeboop
initMulti("Countly_multi_next_2", "?utm_sourcer=hehe&utm_mediumr=hehe1&utm_campaignr=hehe2&utm_rterm=hehe3&utm_corntent=hehe4&fdsjhflkjhsdlkfjhsdlkjfhksdjhfkj+dsf;jsdlkjflk+=skdjflksjd=fksdfl;sd=sdkfmk&&&", { source: true, medium: true, campaign: true, term: true, content: true });
initMulti("Countly_multi_next_2", "utm_sourcer=hehe&utm_mediumr=hehe1&utm_campaignr=hehe2&utm_rterm=hehe3&utm_corntent=hehe4&fdsjhflkjhsdlkfjhsdlkjfhksdjhfkj+dsf;jsdlkjflk+=skdjflksjd=fksdfl;sd=sdkfmk&&&", { source: true, medium: true, campaign: true, term: true, content: true });

// custom utm object, custom query + gabledeboop
initMulti("Countly_multi_next_3", "?utm_sauce=hehe&utm_pan=hehe2&dasdashdjkhaslkjdhsakj=dasmndlask=asdkljska&&utm_source=hehe", { sauce: true, pan: true });
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/view_utm_referrer.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("View with utm and referrer tests ", () => {
// we record 2 views and check if both have the same utm tag
it("Checks if a single default utm tag is at view segmentation of both views", () => {
hp.haltAndClearStorage(() => {
init("YOUR_APP_KEY", "?utm_source=hehe", undefined);
init("YOUR_APP_KEY", "utm_source=hehe", undefined);
Countly.track_view(pageNameOne); // first view
Countly.track_view(pageNameTwo); // second view
// View event should have the utm tag
Expand Down Expand Up @@ -113,7 +113,7 @@ describe("View with utm and referrer tests ", () => {
// we check if multiple custom utm tags are recorded in the view event if they are in the utm object
it("Checks if multiple custom utm tags appears in view", () => {
hp.haltAndClearStorage(() => {
init("YOUR_APP_KEY", "?utm_aa=hehe&utm_bb=hoho", { aa: true, bb: true });
init("YOUR_APP_KEY", "utm_aa=hehe&utm_bb=hoho", { aa: true, bb: true });
Countly.track_view(pageNameOne);
cy.fetch_local_event_queue().then((eq) => {
cy.check_view_event(eq[0], pageNameOne, undefined, false);
Expand Down Expand Up @@ -184,7 +184,7 @@ describe("View with utm and referrer tests ", () => {
test_mode_eq: true,
utm: { ss: true }, // utm object provided in init
getSearchQuery: function() { // override default search query
return "?utm_ss=hehe2";
return "utm_ss=hehe2";
}
});
C2.track_view(pageNameOne);
Expand Down
6 changes: 5 additions & 1 deletion modules/CountlyClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,11 @@ class CountlyClass {
var hasUTM = false;
var utms = {};
if (searchQuery) {
var parts = searchQuery.substring(1).split("&");
// remove the '?' character from the beginning if it exists
if (searchQuery.indexOf('?') === 0) {
searchQuery = searchQuery.substring(1);
};
var parts = searchQuery.split("&");
for (var i = 0; i < parts.length; i++) {
var nv = parts[i].split("=");
if (nv[0] === "cly_id") {
Expand Down

0 comments on commit 50cd80b

Please sign in to comment.