Skip to content

Commit fd3716e

Browse files
authored
Merge pull request #544 from Countly/bug-fixes-11.3
11.3 update
2 parents a81d981 + 372b8c9 commit fd3716e

8 files changed

+1620
-748
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 24.11.3
2+
3+
- Added support for content resizing (Experimental!)
4+
- Mitigated an issue where device ID type was assigned wrongly when SDK was generating an ID after stored device ID was cleared.
5+
- Mitigated an issue where device ID type of initially generated requests were not correctly reassigned after offline mode.
6+
17
## 24.11.2
28
- Added a new init method to set the interval of Content Zone's timer (Experimental!):
39
- `content_zone_timer_interval` to set the timer interval in `seconds`

cypress/e2e/bridged_utils.cy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function initMain(name, version) {
1515
}
1616

1717
const SDK_NAME = "javascript_native_web";
18-
const SDK_VERSION = "24.11.2";
18+
const SDK_VERSION = "24.11.3";
1919

2020
// tests
2121
describe("Bridged SDK Utilities Tests", () => {

cypress/e2e/device_id_init_scenarios.cy.js

+1,386-574
Large diffs are not rendered by default.

cypress/support/helper.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ var Countly = require("../../lib/countly");
22

33
const appKey = "YOUR_APP_KEY";
44
const sWait = 100;
5+
const sWait2 = 550;
56
const mWait = 4000;
67
const lWait = 10000;
78
/**
89
* resets Countly
910
* @param {Function} callback - callback function that includes the Countly init and the tests
1011
*/
1112
function haltAndClearStorage(callback) {
12-
if (Countly.i !== undefined) {
13+
if (Countly.halt !== undefined) {
1314
Countly.halt();
1415
}
1516
cy.wait(sWait).then(() => {
16-
cy.clearLocalStorage();
17+
cy.clearAllLocalStorage();
18+
cy.clearAllCookies();
1719
cy.wait(sWait).then(() => {
1820
callback();
1921
});
@@ -54,14 +56,14 @@ function getTimestampMs() {
5456
* @param {number} waitIncrement - time increment to retry the tests
5557
* @param {Function} continueCallback - callback function with tests
5658
*/
57-
var waitFunction = function(startTime, waitTime, waitIncrement, continueCallback) {
59+
var waitFunction = function (startTime, waitTime, waitIncrement, continueCallback) {
5860
if (waitTime <= getTimestampMs() - startTime) {
5961
// we have waited enough
6062
continueCallback();
6163
}
6264
else {
6365
// we need to wait more
64-
cy.wait(waitIncrement).then(()=>{
66+
cy.wait(waitIncrement).then(() => {
6567
waitFunction(startTime, waitTime, waitIncrement, continueCallback);
6668
});
6769
}
@@ -204,7 +206,7 @@ function testNormalFlow(rq, viewName, countlyAppKey) {
204206
const thirdRequest = JSON.parse(rq[2].events);
205207
expect(thirdRequest.length).to.equal(2);
206208
cy.check_event(thirdRequest[0], { key: "test", count: 1, sum: 1, dur: 1, segmentation: { test: "test" } }, undefined, "");
207-
cy.check_event(thirdRequest[0], { key: "test", count: 1, sum: 1, dur: 1, segmentation: { } }, undefined, "");
209+
cy.check_event(thirdRequest[0], { key: "test", count: 1, sum: 1, dur: 1, segmentation: {} }, undefined, "");
208210

209211
// 4
210212
const fourthRequest = JSON.parse(rq[3].user_details);
@@ -329,6 +331,7 @@ function turnSearchStringToObject(searchString) {
329331
module.exports = {
330332
haltAndClearStorage,
331333
sWait,
334+
sWait2,
332335
mWait,
333336
lWait,
334337
appKey,

lib/countly.js

+60-11
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
statusCode: "cly_hc_status_code",
210210
errorMessage: "cly_hc_error_message"
211211
});
212-
var SDK_VERSION = "24.11.2";
212+
var SDK_VERSION = "24.11.3";
213213
var SDK_NAME = "javascript_native_web";
214214

215215
// Using this on document.referrer would return an array with 17 elements in it. The 12th element (array[11]) would be the path we are looking for. Others would be things like password and such (use https://regex101.com/ to check more)
@@ -1176,6 +1176,7 @@
11761176
_classPrivateFieldGet2(_removeValueFromStorage, _this).call(_this, "cly_id");
11771177
_classPrivateFieldGet2(_removeValueFromStorage, _this).call(_this, "cly_id_type");
11781178
_classPrivateFieldGet2(_removeValueFromStorage, _this).call(_this, "cly_session");
1179+
tempIdModeWasEnabled = false;
11791180
}
11801181

11811182
// init configuration is printed out here:
@@ -1520,6 +1521,22 @@
15201521
localStorage.setItem("cly_testLocal", true);
15211522
// clean up test
15221523
localStorage.removeItem("cly_testLocal");
1524+
localStorage.removeItem("cly_old_token");
1525+
localStorage.removeItem("cly_cmp_id");
1526+
localStorage.removeItem("cly_cmp_uid");
1527+
localStorage.removeItem("cly_id");
1528+
localStorage.removeItem("cly_id_type");
1529+
localStorage.removeItem("cly_queue");
1530+
localStorage.removeItem("cly_session");
1531+
localStorage.removeItem("cly_remote_configs");
1532+
localStorage.removeItem("cly_event");
1533+
localStorage.removeItem("cly_ignore");
1534+
localStorage.removeItem("cly_fb_widgets");
1535+
localStorage.removeItem("cly_token");
1536+
localStorage.removeItem("cly_hc_error_count");
1537+
localStorage.removeItem("cly_hc_warning_count");
1538+
localStorage.removeItem("cly_hc_status_code");
1539+
localStorage.removeItem("cly_hc_error_message");
15231540
} catch (e) {
15241541
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.ERROR, "halt, Local storage test failed, will fallback to cookies");
15251542
_classPrivateFieldSet2(_lsSupport, _this, false);
@@ -1744,12 +1761,15 @@
17441761
}
17451762
});
17461763
_defineProperty(this, "enable_offline_mode", function () {
1764+
if (_classPrivateFieldGet2(_offlineMode, _this)) {
1765+
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.WARNING, "enable_offline_mode, Countly is already in offline mode.");
1766+
return;
1767+
}
17471768
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.INFO, "enable_offline_mode, Enabling offline mode");
17481769
// clear consents
17491770
_this.remove_consent_internal(Countly.features, false);
17501771
_classPrivateFieldSet2(_offlineMode, _this, true);
17511772
_this.device_id = "[CLY]_temp_id";
1752-
_this.device_id = _this.device_id;
17531773
_classPrivateFieldSet2(_deviceIdType, _this, DeviceIdTypeInternalEnums.TEMPORARY_ID);
17541774
});
17551775
_defineProperty(this, "disable_offline_mode", function (device_id) {
@@ -1761,7 +1781,6 @@
17611781
_classPrivateFieldSet2(_offlineMode, _this, false);
17621782
if (device_id && _this.device_id !== device_id) {
17631783
_this.device_id = device_id;
1764-
_this.device_id = _this.device_id;
17651784
_classPrivateFieldSet2(_deviceIdType, _this, DeviceIdTypeInternalEnums.DEVELOPER_SUPPLIED);
17661785
_classPrivateFieldGet2(_setValueInStorage, _this).call(_this, "cly_id", _this.device_id);
17671786
_classPrivateFieldGet2(_setValueInStorage, _this).call(_this, "cly_id_type", DeviceIdTypeInternalEnums.DEVELOPER_SUPPLIED);
@@ -1771,7 +1790,6 @@
17711790
if (_this.device_id === "[CLY]_temp_id") {
17721791
_this.device_id = generateUUID();
17731792
}
1774-
_this.device_id = _this.device_id;
17751793
if (_this.device_id !== _classPrivateFieldGet2(_getValueFromStorage, _this).call(_this, "cly_id")) {
17761794
_classPrivateFieldGet2(_setValueInStorage, _this).call(_this, "cly_id", _this.device_id);
17771795
_classPrivateFieldGet2(_setValueInStorage, _this).call(_this, "cly_id_type", DeviceIdTypeInternalEnums.SDK_GENERATED);
@@ -1782,6 +1800,7 @@
17821800
for (var i = 0; i < _classPrivateFieldGet2(_requestQueue, _this).length; i++) {
17831801
if (_classPrivateFieldGet2(_requestQueue, _this)[i].device_id === "[CLY]_temp_id") {
17841802
_classPrivateFieldGet2(_requestQueue, _this)[i].device_id = _this.device_id;
1803+
_classPrivateFieldGet2(_requestQueue, _this)[i].t = _classPrivateFieldGet2(_deviceIdType, _this);
17851804
needResync = true;
17861805
}
17871806
}
@@ -4027,7 +4046,6 @@
40274046
wrapper.appendChild(iframe);
40284047
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "present_feedback_widget, Appended the iframe");
40294048
add_event_listener(window, "message", function (e) {
4030-
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "present_feedback_widget, Received message from widget with origin: [" + e.origin + "] and data: [" + e.data + "]");
40314049
var data = {};
40324050
try {
40334051
data = JSON.parse(e.data);
@@ -4036,9 +4054,11 @@
40364054
}
40374055
if (data.close !== true) {
40384056
// to not mix with content we check against true value
4039-
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "present_feedback_widget, These are not the closing signals you are looking for");
4057+
// this.#log(logLevelEnums.DEBUG, "present_feedback_widget, These are not the closing signals you are looking for");
4058+
// silent ignore
40404059
return;
40414060
}
4061+
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "present_feedback_widget, Received message from widget with origin: [" + e.origin + "] and data: [" + e.data + "]");
40424062
document.getElementById("countly-" + feedbackWidgetFamily + "-wrapper-" + presentableFeedback._id).style.display = "none";
40434063
document.getElementById("csbg").style.display = "none";
40444064
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "present_feedback_widget, Closed the widget");
@@ -4372,6 +4392,20 @@
43724392
window.addEventListener('message', function (event) {
43734393
_classPrivateFieldGet2(_interpretContentMessage, _this).call(_this, event);
43744394
});
4395+
var resizeTimeout;
4396+
window.addEventListener('resize', function () {
4397+
clearTimeout(resizeTimeout);
4398+
resizeTimeout = setTimeout(function () {
4399+
var width = window.innerWidth;
4400+
var height = window.innerHeight;
4401+
var iframe = document.getElementById(_classPrivateFieldGet2(_contentIframeID, _this));
4402+
iframe.contentWindow.postMessage({
4403+
type: 'resize',
4404+
width: width,
4405+
height: height
4406+
}, '*');
4407+
}, 200);
4408+
});
43754409
}, true);
43764410
});
43774411
_classPrivateFieldInitSpec(this, _displayContent, function (content) {
@@ -4399,19 +4433,21 @@
43994433
document.body.appendChild(iframe);
44004434
});
44014435
_classPrivateFieldInitSpec(this, _interpretContentMessage, function (messageEvent) {
4402-
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Received message from: [" + messageEvent.origin + "] with data: [" + JSON.stringify(messageEvent.data) + "]");
44034436
if (messageEvent.origin !== _this.url) {
4404-
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.ERROR, "sendContentRequest, Received message from invalid origin");
4437+
// this.#log(logLevelEnums.ERROR, "sendContentRequest, Received message from invalid origin");
4438+
// silent ignore
44054439
return;
44064440
}
4441+
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Received message from: [" + messageEvent.origin + "] with data: [" + JSON.stringify(messageEvent.data) + "]");
44074442
var _messageEvent$data = messageEvent.data,
44084443
close = _messageEvent$data.close,
44094444
link = _messageEvent$data.link,
4410-
event = _messageEvent$data.event;
4445+
event = _messageEvent$data.event,
4446+
resize_me = _messageEvent$data.resize_me;
44114447
if (event) {
4412-
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Received event: [" + event + "]");
4448+
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Received event");
44134449
if (close === 1) {
4414-
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Closing content frame for event: [" + event + "]");
4450+
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Closing content frame for event");
44154451
_classPrivateFieldGet2(_closeContentFrame, _this).call(_this);
44164452
}
44174453
if (!Array.isArray(event)) {
@@ -4435,6 +4471,19 @@
44354471
window.open(link, "_blank");
44364472
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Opened link in new tab: [".concat(link, "]"));
44374473
}
4474+
if (resize_me) {
4475+
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Resizing iframe");
4476+
var resInfo = _classPrivateFieldGet2(_getResolution, _this).call(_this, true);
4477+
var dimensionToUse = resize_me.p;
4478+
if (resInfo.width >= resInfo.height) {
4479+
dimensionToUse = resize_me.l;
4480+
}
4481+
var iframe = document.getElementById(_classPrivateFieldGet2(_contentIframeID, _this));
4482+
iframe.style.left = dimensionToUse.x + "px";
4483+
iframe.style.top = dimensionToUse.y + "px";
4484+
iframe.style.width = dimensionToUse.w + "px";
4485+
iframe.style.height = dimensionToUse.h + "px";
4486+
}
44384487
if (close === 1) {
44394488
_classPrivateFieldGet2(_closeContentFrame, _this).call(_this);
44404489
}

0 commit comments

Comments
 (0)