|
217 | 217 | backoffCount: "cly_hc_backoff_count", |
218 | 218 | consecutiveBackoffCount: "cly_hc_consecutive_backoff_count" |
219 | 219 | }); |
220 | | - var SDK_VERSION = "25.4.3"; |
| 220 | + var SDK_VERSION = "25.4.4"; |
221 | 221 | var SDK_NAME = "javascript_native_web"; |
222 | 222 |
|
223 | 223 | // 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) |
|
945 | 945 | var _testModeTime = /*#__PURE__*/new WeakMap(); |
946 | 946 | var _requestTimeoutDuration = /*#__PURE__*/new WeakMap(); |
947 | 947 | var _contentFilterCallback = /*#__PURE__*/new WeakMap(); |
| 948 | + var _isProcessingAsyncFromUserDataSave = /*#__PURE__*/new WeakMap(); |
948 | 949 | var _getAndSetServerConfig = /*#__PURE__*/new WeakMap(); |
949 | 950 | var _populateServerConfig = /*#__PURE__*/new WeakMap(); |
950 | 951 | var _initialize = /*#__PURE__*/new WeakMap(); |
|
1101 | 1102 | _classPrivateFieldInitSpec(this, _testModeTime, void 0); |
1102 | 1103 | _classPrivateFieldInitSpec(this, _requestTimeoutDuration, void 0); |
1103 | 1104 | _classPrivateFieldInitSpec(this, _contentFilterCallback, void 0); |
| 1105 | + _classPrivateFieldInitSpec(this, _isProcessingAsyncFromUserDataSave, void 0); |
1104 | 1106 | _classPrivateFieldInitSpec(this, _getAndSetServerConfig, function () { |
1105 | 1107 | if (_this.device_id === "[CLY]_temp_id") { |
1106 | 1108 | _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.INFO, "server_config, Device ID is temporary, not fetching server config"); |
|
2059 | 2061 | var req = {}; |
2060 | 2062 | req.begin_session = 1; |
2061 | 2063 | req.metrics = JSON.stringify(_classPrivateFieldGet2(_getMetrics, _this).call(_this)); |
| 2064 | + _this.userData.save(true); // ensure user data is saved before session start |
2062 | 2065 | _classPrivateFieldGet2(_toRequestQueue, _this).call(_this, req); |
2063 | 2066 | } |
2064 | 2067 | _classPrivateFieldGet2(_setValueInStorage, _this).call(_this, "cly_session", getTimestamp() + _classPrivateFieldGet2(_sessionCookieTimeout, _this) * 60); |
|
2085 | 2088 | return; |
2086 | 2089 | } |
2087 | 2090 | _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.INFO, "session_duration, Session extended: [" + sec + "]"); |
| 2091 | + _this.userData.save(true); // ensure user data is saved before session update |
2088 | 2092 | _classPrivateFieldGet2(_toRequestQueue, _this).call(_this, { |
2089 | 2093 | session_duration: sec |
2090 | 2094 | }); |
|
2107 | 2111 | _classPrivateFieldGet2(_reportViewDuration, _this).call(_this); |
2108 | 2112 | if (!_classPrivateFieldGet2(_useSessionCookie, _this) || force) { |
2109 | 2113 | _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.INFO, "end_session, Session ended"); |
| 2114 | + _this.userData.save(true); // ensure user data is saved before session end |
2110 | 2115 | _classPrivateFieldGet2(_toRequestQueue, _this).call(_this, { |
2111 | 2116 | end_session: 1, |
2112 | 2117 | session_duration: sec |
|
2267 | 2272 | _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.ERROR, "Adding event failed. Event must have a key property"); |
2268 | 2273 | return; |
2269 | 2274 | } |
| 2275 | + if (!_classPrivateFieldGet2(_isProcessingAsyncFromUserDataSave, _this)) { |
| 2276 | + _this.userData.save(true); // ensure cached user data is saved before adding event |
| 2277 | + } |
2270 | 2278 | if (!event.count) { |
2271 | 2279 | event.count = 1; |
2272 | 2280 | } |
|
2441 | 2449 | user.byear = truncateSingleValue(user.byear, _classPrivateFieldGet2(_SCLimitValueSize, _this), "user_details", _classPrivateFieldGet2(_log, _this)); |
2442 | 2450 | user.custom = truncateObject(user.custom, _classPrivateFieldGet2(_SCLimitKeyLength, _this), _classPrivateFieldGet2(_SCLimitValueSize, _this), _classPrivateFieldGet2(_SCLimitSegmentationValues, _this), "user_details", _classPrivateFieldGet2(_log, _this)); |
2443 | 2451 | var props = ["name", "username", "email", "organization", "phone", "picture", "gender", "byear", "custom"]; |
| 2452 | + _this.userData.save(); // ensure user data (and events) is saved before sending user details |
2444 | 2453 | _classPrivateFieldGet2(_toRequestQueue, _this).call(_this, { |
2445 | 2454 | user_details: JSON.stringify(createNewObjectFromProperties(user, props)) |
2446 | 2455 | }); |
|
2627 | 2636 | * Save changes made to user's custom properties object and send them to server |
2628 | 2637 | * @memberof Countly.userData |
2629 | 2638 | * */ |
2630 | | - save: function save() { |
2631 | | - _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.INFO, "[userData] save, Saving changes to user's custom property"); |
2632 | | - if (_this.check_consent(featureEnums.USERS)) { |
2633 | | - // process async queue before sending events |
2634 | | - _classPrivateFieldGet2(_processAsyncQueue, _this).call(_this); |
2635 | | - // flush events to event queue to prevent a drill issue |
| 2639 | + save: function save(forEvents) { |
| 2640 | + _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.INFO, "[userData] save, Saving changes to user's custom property. forEvents:[" + forEvents + "]"); |
| 2641 | + if (!_this.check_consent(featureEnums.USERS) || Object.keys(_classPrivateFieldGet2(_customData, _this)).length === 0) { |
| 2642 | + return; |
| 2643 | + } |
| 2644 | + if (!forEvents) { |
| 2645 | + _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "[userData] save, flushing async queue and event queue before sending custom user data"); |
| 2646 | + _classPrivateFieldSet2(_isProcessingAsyncFromUserDataSave, _this, true); |
| 2647 | + try { |
| 2648 | + // process async queue before sending events |
| 2649 | + _classPrivateFieldGet2(_processAsyncQueue, _this).call(_this); |
| 2650 | + } finally { |
| 2651 | + _classPrivateFieldSet2(_isProcessingAsyncFromUserDataSave, _this, false); |
| 2652 | + } |
| 2653 | + |
| 2654 | + // flush events to request queue |
2636 | 2655 | _classPrivateFieldGet2(_sendEventsForced, _this).call(_this); |
2637 | | - _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.INFO, "user_details, flushed the event queue"); |
2638 | | - _classPrivateFieldGet2(_toRequestQueue, _this).call(_this, { |
2639 | | - user_details: JSON.stringify({ |
2640 | | - custom: _classPrivateFieldGet2(_customData, _this) |
2641 | | - }) |
2642 | | - }); |
2643 | 2656 | } |
| 2657 | + _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.INFO, "[userData] save, will send the following custom data to server: [" + JSON.stringify(_classPrivateFieldGet2(_customData, _this)) + "]"); |
| 2658 | + _classPrivateFieldGet2(_toRequestQueue, _this).call(_this, { |
| 2659 | + user_details: JSON.stringify({ |
| 2660 | + custom: _classPrivateFieldGet2(_customData, _this) |
| 2661 | + }) |
| 2662 | + }); |
2644 | 2663 | _classPrivateFieldSet2(_customData, _this, {}); |
2645 | 2664 | } |
2646 | 2665 | }); |
|
6516 | 6535 | _classPrivateFieldSet2(_SCBackoffDuration, this, 60); // 60 seconds |
6517 | 6536 | _classPrivateFieldSet2(_requestTimeoutDuration, this, 30000); // 30 seconds |
6518 | 6537 | _classPrivateFieldSet2(_contentFilterCallback, this, null); |
| 6538 | + _classPrivateFieldSet2(_isProcessingAsyncFromUserDataSave, this, false); |
6519 | 6539 | this.app_key = getConfig("app_key", _ob, null); |
6520 | 6540 | this.url = stripTrailingSlash(getConfig("url", _ob, "")); |
6521 | 6541 | this.serialize = getConfig("serialize", _ob, Countly.serialize); |
|
0 commit comments