From d002ead76a4c0c3d5ef25fe808be330de385c2d2 Mon Sep 17 00:00:00 2001 From: turtledreams Date: Thu, 28 Dec 2023 20:11:00 +0900 Subject: [PATCH] 1 --- CHANGELOG.md | 1 + cypress/e2e/utm.cy.js | 14 +++++++------- cypress/e2e/view_utm_referrer.cy.js | 6 +++--- modules/CountlyClass.js | 6 +++++- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35c3787..8f8f185 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cypress/e2e/utm.cy.js b/cypress/e2e/utm.cy.js index 57aa43c..21c97d2 100644 --- a/cypress/e2e/utm.cy.js +++ b/cypress/e2e/utm.cy.js @@ -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; @@ -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; @@ -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) => { @@ -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 }); @@ -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 }); diff --git a/cypress/e2e/view_utm_referrer.cy.js b/cypress/e2e/view_utm_referrer.cy.js index cbfe86b..b91050c 100644 --- a/cypress/e2e/view_utm_referrer.cy.js +++ b/cypress/e2e/view_utm_referrer.cy.js @@ -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 @@ -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); @@ -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); diff --git a/modules/CountlyClass.js b/modules/CountlyClass.js index 9b9a9ca..29f63a7 100644 --- a/modules/CountlyClass.js +++ b/modules/CountlyClass.js @@ -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") {