Skip to content

Commit

Permalink
Merge pull request #544 from Countly/bug-fixes-11.3
Browse files Browse the repository at this point in the history
11.3 update
  • Loading branch information
turtledreams authored Jan 9, 2025
2 parents a81d981 + 372b8c9 commit fd3716e
Show file tree
Hide file tree
Showing 8 changed files with 1,620 additions and 748 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 24.11.3

- Added support for content resizing (Experimental!)
- Mitigated an issue where device ID type was assigned wrongly when SDK was generating an ID after stored device ID was cleared.
- Mitigated an issue where device ID type of initially generated requests were not correctly reassigned after offline mode.

## 24.11.2
- Added a new init method to set the interval of Content Zone's timer (Experimental!):
- `content_zone_timer_interval` to set the timer interval in `seconds`
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/bridged_utils.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function initMain(name, version) {
}

const SDK_NAME = "javascript_native_web";
const SDK_VERSION = "24.11.2";
const SDK_VERSION = "24.11.3";

// tests
describe("Bridged SDK Utilities Tests", () => {
Expand Down
1,960 changes: 1,386 additions & 574 deletions cypress/e2e/device_id_init_scenarios.cy.js

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions cypress/support/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ var Countly = require("../../lib/countly");

const appKey = "YOUR_APP_KEY";
const sWait = 100;
const sWait2 = 550;
const mWait = 4000;
const lWait = 10000;
/**
* resets Countly
* @param {Function} callback - callback function that includes the Countly init and the tests
*/
function haltAndClearStorage(callback) {
if (Countly.i !== undefined) {
if (Countly.halt !== undefined) {
Countly.halt();
}
cy.wait(sWait).then(() => {
cy.clearLocalStorage();
cy.clearAllLocalStorage();
cy.clearAllCookies();
cy.wait(sWait).then(() => {
callback();
});
Expand Down Expand Up @@ -54,14 +56,14 @@ function getTimestampMs() {
* @param {number} waitIncrement - time increment to retry the tests
* @param {Function} continueCallback - callback function with tests
*/
var waitFunction = function(startTime, waitTime, waitIncrement, continueCallback) {
var waitFunction = function (startTime, waitTime, waitIncrement, continueCallback) {
if (waitTime <= getTimestampMs() - startTime) {
// we have waited enough
continueCallback();
}
else {
// we need to wait more
cy.wait(waitIncrement).then(()=>{
cy.wait(waitIncrement).then(() => {
waitFunction(startTime, waitTime, waitIncrement, continueCallback);
});
}
Expand Down Expand Up @@ -204,7 +206,7 @@ function testNormalFlow(rq, viewName, countlyAppKey) {
const thirdRequest = JSON.parse(rq[2].events);
expect(thirdRequest.length).to.equal(2);
cy.check_event(thirdRequest[0], { key: "test", count: 1, sum: 1, dur: 1, segmentation: { test: "test" } }, undefined, "");
cy.check_event(thirdRequest[0], { key: "test", count: 1, sum: 1, dur: 1, segmentation: { } }, undefined, "");
cy.check_event(thirdRequest[0], { key: "test", count: 1, sum: 1, dur: 1, segmentation: {} }, undefined, "");

// 4
const fourthRequest = JSON.parse(rq[3].user_details);
Expand Down Expand Up @@ -329,6 +331,7 @@ function turnSearchStringToObject(searchString) {
module.exports = {
haltAndClearStorage,
sWait,
sWait2,
mWait,
lWait,
appKey,
Expand Down
71 changes: 60 additions & 11 deletions lib/countly.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
statusCode: "cly_hc_status_code",
errorMessage: "cly_hc_error_message"
});
var SDK_VERSION = "24.11.2";
var SDK_VERSION = "24.11.3";
var SDK_NAME = "javascript_native_web";

// 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)
Expand Down Expand Up @@ -1176,6 +1176,7 @@
_classPrivateFieldGet2(_removeValueFromStorage, _this).call(_this, "cly_id");
_classPrivateFieldGet2(_removeValueFromStorage, _this).call(_this, "cly_id_type");
_classPrivateFieldGet2(_removeValueFromStorage, _this).call(_this, "cly_session");
tempIdModeWasEnabled = false;
}

// init configuration is printed out here:
Expand Down Expand Up @@ -1520,6 +1521,22 @@
localStorage.setItem("cly_testLocal", true);
// clean up test
localStorage.removeItem("cly_testLocal");
localStorage.removeItem("cly_old_token");
localStorage.removeItem("cly_cmp_id");
localStorage.removeItem("cly_cmp_uid");
localStorage.removeItem("cly_id");
localStorage.removeItem("cly_id_type");
localStorage.removeItem("cly_queue");
localStorage.removeItem("cly_session");
localStorage.removeItem("cly_remote_configs");
localStorage.removeItem("cly_event");
localStorage.removeItem("cly_ignore");
localStorage.removeItem("cly_fb_widgets");
localStorage.removeItem("cly_token");
localStorage.removeItem("cly_hc_error_count");
localStorage.removeItem("cly_hc_warning_count");
localStorage.removeItem("cly_hc_status_code");
localStorage.removeItem("cly_hc_error_message");
} catch (e) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.ERROR, "halt, Local storage test failed, will fallback to cookies");
_classPrivateFieldSet2(_lsSupport, _this, false);
Expand Down Expand Up @@ -1744,12 +1761,15 @@
}
});
_defineProperty(this, "enable_offline_mode", function () {
if (_classPrivateFieldGet2(_offlineMode, _this)) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.WARNING, "enable_offline_mode, Countly is already in offline mode.");
return;
}
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.INFO, "enable_offline_mode, Enabling offline mode");
// clear consents
_this.remove_consent_internal(Countly.features, false);
_classPrivateFieldSet2(_offlineMode, _this, true);
_this.device_id = "[CLY]_temp_id";
_this.device_id = _this.device_id;
_classPrivateFieldSet2(_deviceIdType, _this, DeviceIdTypeInternalEnums.TEMPORARY_ID);
});
_defineProperty(this, "disable_offline_mode", function (device_id) {
Expand All @@ -1761,7 +1781,6 @@
_classPrivateFieldSet2(_offlineMode, _this, false);
if (device_id && _this.device_id !== device_id) {
_this.device_id = device_id;
_this.device_id = _this.device_id;
_classPrivateFieldSet2(_deviceIdType, _this, DeviceIdTypeInternalEnums.DEVELOPER_SUPPLIED);
_classPrivateFieldGet2(_setValueInStorage, _this).call(_this, "cly_id", _this.device_id);
_classPrivateFieldGet2(_setValueInStorage, _this).call(_this, "cly_id_type", DeviceIdTypeInternalEnums.DEVELOPER_SUPPLIED);
Expand All @@ -1771,7 +1790,6 @@
if (_this.device_id === "[CLY]_temp_id") {
_this.device_id = generateUUID();
}
_this.device_id = _this.device_id;
if (_this.device_id !== _classPrivateFieldGet2(_getValueFromStorage, _this).call(_this, "cly_id")) {
_classPrivateFieldGet2(_setValueInStorage, _this).call(_this, "cly_id", _this.device_id);
_classPrivateFieldGet2(_setValueInStorage, _this).call(_this, "cly_id_type", DeviceIdTypeInternalEnums.SDK_GENERATED);
Expand All @@ -1782,6 +1800,7 @@
for (var i = 0; i < _classPrivateFieldGet2(_requestQueue, _this).length; i++) {
if (_classPrivateFieldGet2(_requestQueue, _this)[i].device_id === "[CLY]_temp_id") {
_classPrivateFieldGet2(_requestQueue, _this)[i].device_id = _this.device_id;
_classPrivateFieldGet2(_requestQueue, _this)[i].t = _classPrivateFieldGet2(_deviceIdType, _this);
needResync = true;
}
}
Expand Down Expand Up @@ -4027,7 +4046,6 @@
wrapper.appendChild(iframe);
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "present_feedback_widget, Appended the iframe");
add_event_listener(window, "message", function (e) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "present_feedback_widget, Received message from widget with origin: [" + e.origin + "] and data: [" + e.data + "]");
var data = {};
try {
data = JSON.parse(e.data);
Expand All @@ -4036,9 +4054,11 @@
}
if (data.close !== true) {
// to not mix with content we check against true value
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "present_feedback_widget, These are not the closing signals you are looking for");
// this.#log(logLevelEnums.DEBUG, "present_feedback_widget, These are not the closing signals you are looking for");
// silent ignore
return;
}
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "present_feedback_widget, Received message from widget with origin: [" + e.origin + "] and data: [" + e.data + "]");
document.getElementById("countly-" + feedbackWidgetFamily + "-wrapper-" + presentableFeedback._id).style.display = "none";
document.getElementById("csbg").style.display = "none";
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "present_feedback_widget, Closed the widget");
Expand Down Expand Up @@ -4372,6 +4392,20 @@
window.addEventListener('message', function (event) {
_classPrivateFieldGet2(_interpretContentMessage, _this).call(_this, event);
});
var resizeTimeout;
window.addEventListener('resize', function () {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(function () {
var width = window.innerWidth;
var height = window.innerHeight;
var iframe = document.getElementById(_classPrivateFieldGet2(_contentIframeID, _this));
iframe.contentWindow.postMessage({
type: 'resize',
width: width,
height: height
}, '*');
}, 200);
});
}, true);
});
_classPrivateFieldInitSpec(this, _displayContent, function (content) {
Expand Down Expand Up @@ -4399,19 +4433,21 @@
document.body.appendChild(iframe);
});
_classPrivateFieldInitSpec(this, _interpretContentMessage, function (messageEvent) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Received message from: [" + messageEvent.origin + "] with data: [" + JSON.stringify(messageEvent.data) + "]");
if (messageEvent.origin !== _this.url) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.ERROR, "sendContentRequest, Received message from invalid origin");
// this.#log(logLevelEnums.ERROR, "sendContentRequest, Received message from invalid origin");
// silent ignore
return;
}
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Received message from: [" + messageEvent.origin + "] with data: [" + JSON.stringify(messageEvent.data) + "]");
var _messageEvent$data = messageEvent.data,
close = _messageEvent$data.close,
link = _messageEvent$data.link,
event = _messageEvent$data.event;
event = _messageEvent$data.event,
resize_me = _messageEvent$data.resize_me;
if (event) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Received event: [" + event + "]");
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Received event");
if (close === 1) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Closing content frame for event: [" + event + "]");
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Closing content frame for event");
_classPrivateFieldGet2(_closeContentFrame, _this).call(_this);
}
if (!Array.isArray(event)) {
Expand All @@ -4435,6 +4471,19 @@
window.open(link, "_blank");
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Opened link in new tab: [".concat(link, "]"));
}
if (resize_me) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Resizing iframe");
var resInfo = _classPrivateFieldGet2(_getResolution, _this).call(_this, true);
var dimensionToUse = resize_me.p;
if (resInfo.width >= resInfo.height) {
dimensionToUse = resize_me.l;
}
var iframe = document.getElementById(_classPrivateFieldGet2(_contentIframeID, _this));
iframe.style.left = dimensionToUse.x + "px";
iframe.style.top = dimensionToUse.y + "px";
iframe.style.width = dimensionToUse.w + "px";
iframe.style.height = dimensionToUse.h + "px";
}
if (close === 1) {
_classPrivateFieldGet2(_closeContentFrame, _this).call(_this);
}
Expand Down
Loading

0 comments on commit fd3716e

Please sign in to comment.