Skip to content

Commit df424ba

Browse files
authored
Merge pull request #52 from adjust/v560
Version 5.6.0
2 parents 3340026 + 555cdc1 commit df424ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1312
-713
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
### Version 5.6.0 (30th January 2023)
2+
#### Added
3+
- Added a return of Promise from `trackEvent` method.
4+
5+
#### Fixed
6+
- Fixed SDK state synchronization issue between multiple tabs.
7+
8+
---
9+
110
### Version 5.5.0 (17th November 2022)
211
#### Added
312
- Added `setReferrer` method to set referrer and trigger `/sdk_click` request manually.
@@ -6,6 +15,7 @@
615
- Fixed [issue](https://github.com/adjust/web_sdk/issues/46) which caused site not to load when cookies are blocked in browser.
716

817
---
18+
919
### Version 5.4.0 (20th September 2022)
1020
#### Added
1121
- Added support of Data Residency.

README.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Read this in other languages: [English][en-readme], [中文][zh-readme], [日本
1616
* [Stop/Restart SDK](#stop-restart-sdk)
1717
* [GDPR Forget Me](#gdpr-forget-me)
1818
* [Marketing Opt-out](#marketing-opt-out)
19+
* [Data residency](#data-residency)
1920
* [License](#license)
2021

2122
## <a id="example-app">Example apps</a>
@@ -37,12 +38,12 @@ To lazy <a id="loading-snippet">load the Adjust Web SDK through CDN</a> paste th
3738

3839
The Adjust Web SDK should be loaded only once per page and it should be initiated once per page load.
3940

40-
When loading the sdk through CDN we suggest using minified version. You can target specific version like `https://cdn.adjust.com/adjust-5.5.0.min.js`, or you can target latest version `https://cdn.adjust.com/adjust-latest.min.js` if you want automatic updates without need to change the target file. The sdk files are cached so they are served as fast as possible, and the cache is refreshed every half an hour. If you want updates immediately make sure to target specific version.
41+
When loading the sdk through CDN we suggest using minified version. You can target specific version like `https://cdn.adjust.com/adjust-5.6.0.min.js`, or you can target latest version `https://cdn.adjust.com/adjust-latest.min.js` if you want automatic updates without need to change the target file. The sdk files are cached so they are served as fast as possible, and the cache is refreshed every half an hour. If you want updates immediately make sure to target specific version.
4142

4243
You may want to use [Subresource Integrity (SRI)](sri-mdn) feature to mitigate XSS attacks risk. In this case you could use the loading snippet that enables SRI check instructing browser to validate the script before running it:
4344
```html
4445
<script type="application/javascript">
45-
!function(t,e,a,r,n,s,o,l,i,d,u){t.Adjust=t.Adjust||{},t.Adjust_q=t.Adjust_q||[];for(var c=0;c<l.length;c++)i(t.Adjust,t.Adjust_q,l[c]);d=e.createElement(a),u=e.getElementsByTagName(a)[0],d.async=!0,d.src="https://cdn.adjust.com/adjust-latest.min.js",d.crossOrigin="anonymous",d.integrity=s,d.onload=function(){for(var e=0;e<t.Adjust_q.length;e++)t.Adjust[t.Adjust_q[e][0]].apply(t.Adjust,t.Adjust_q[e][1]);t.Adjust_q=[]},u.parentNode.insertBefore(d,u)}(window,document,"script",0,0,"sha384-ti9hnBz5iMLIfOik3tirvSeTYG6T0ZZTluQjGNeL0/WZP2kNe+pi8On+zOoBJCl7",0,["initSdk","getAttribution","getWebUUID","setReferrer","trackEvent","addGlobalCallbackParameters","addGlobalPartnerParameters","removeGlobalCallbackParameter","removeGlobalPartnerParameter","clearGlobalCallbackParameters","clearGlobalPartnerParameters","switchToOfflineMode","switchBackToOnlineMode","stop","restart","gdprForgetMe","disableThirdPartySharing","initSmartBanner","showSmartBanner","hideSmartBanner"],(function(t,e,a){t[a]=function(){e.push([a,arguments])}}));
46+
!function(t,e,a,r,n,s,o,d,l,i,u){t.Adjust=t.Adjust||{},t.Adjust_q=t.Adjust_q||[];for(var c=0;c<d.length;c++)l(t.Adjust,t.Adjust_q,d[c]);i=e.createElement(a),u=e.getElementsByTagName(a)[0],i.async=!0,i.src="https://cdn.adjust.com/adjust-latest.min.js",i.crossOrigin="anonymous",i.integrity=s,i.onload=function(){for(var e=0;e<t.Adjust_q.length;e++)t.Adjust[t.Adjust_q[e][0]].apply(t.Adjust,t.Adjust_q[e][1]);t.Adjust_q=[]},u.parentNode.insertBefore(i,u)}(window,document,"script",0,0,"sha384-BqbTn9xyk5DPznti1ZP8ksxKiOFhKufLBFWm5eNMCnZABFSG1eqQfcu5dsiZJHu5",0,["initSdk","getAttribution","getWebUUID","setReferrer","trackEvent","addGlobalCallbackParameters","addGlobalPartnerParameters","removeGlobalCallbackParameter","removeGlobalPartnerParameter","clearGlobalCallbackParameters","clearGlobalPartnerParameters","switchToOfflineMode","switchBackToOnlineMode","stop","restart","gdprForgetMe","disableThirdPartySharing","initSmartBanner","showSmartBanner","hideSmartBanner"],(function(t,e,a){t[a]=function(){e.push([a,arguments])}}));
4647
</script>
4748
```
4849

@@ -235,6 +236,36 @@ You can read more about special partners and these integrations in our [guide to
235236

236237
It's possible to provide event deduplication id in order to avoid tracking duplicated events. Deduplication list limit is set in initialization configuration as described [above](#event-deduplication-list-limit)
237238

239+
### Tracking an event and redirect to an external page
240+
241+
Sometimes you want to redirect user to an external page and track this redirect as an event. For this case to avoid redirect to happen earlier than the event was actually tracked `trackEvent` method returns a `Promise` which is fulfilled after the SDK has sent the event and received a response from the backend and rejected when some internal error happen.
242+
243+
> **Important** It might take pretty much time until this promise is settled so it's recommended to use a timeout.
244+
245+
Please note that due to internal requests queue the event wouldn't be lost even if it timed out or an error happened, the SDK will preserve the event to the next time it's loaded and try to send it again.
246+
247+
Example:
248+
249+
```js
250+
Promise
251+
.race([
252+
Adjust.trackEvent({
253+
eventToken: 'YOUR_EVENT_TOKEN',
254+
// ... other event parameters
255+
}),
256+
new Promise((resolve, reject) => {
257+
setTimeout(() => reject('Timed out'), 2000)
258+
})
259+
])
260+
.catch(error => {
261+
// ...
262+
})
263+
.then(() => {
264+
// ... perform redirect, for example
265+
window.location.href = "https://www.example.org/"
266+
});
267+
```
268+
238269
## <a id="global-callback-parameters">Global callback parameters</a>
239270

240271
There are several methods available for global callback parameters like adding, removing and clearing them. Here is the list of each available method:
@@ -440,6 +471,27 @@ Please note that `referrer` should be properly URL-encoded.
440471

441472
> **Important** For proper attribution this method should be called as close as possible to SDK initialization.
442473
474+
## <a id="data-residency">Data residency</a>
475+
476+
The data residency feature allows you to choose the country in which Adjust stores your data. This is useful if you are operating in a country with strict privacy requirements. When you set up data residency, Adjust stores your data in a data center located in the region your have chosen.
477+
478+
To set your country of data residency, pass a `dataResidency` argument in your `initSdk` call.
479+
480+
```js
481+
Adjust.initSdk({
482+
"appToken": "YOUR_APP_TOKEN",
483+
"environment": "production",
484+
"logLevel": "verbose",
485+
"dataResidency": "EU"
486+
})
487+
```
488+
489+
The following values are accepted:
490+
491+
- `EU` – sets the data residency region to the EU.
492+
- `TR` – sets the data residency region to Turkey.
493+
- `US` – sets the data residency region to the USA.
494+
443495
## <a id="license">License</a>
444496

445497
The Adjust SDK is licensed under the MIT License.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.5.0
1+
5.6.0

dist/INTEGRITY

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sha384-ti9hnBz5iMLIfOik3tirvSeTYG6T0ZZTluQjGNeL0/WZP2kNe+pi8On+zOoBJCl7
1+
sha384-BqbTn9xyk5DPznti1ZP8ksxKiOFhKufLBFWm5eNMCnZABFSG1eqQfcu5dsiZJHu5

dist/adjust-latest.d.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ declare namespace Adjust {
232232
*
233233
* @param {EventParams} params Parameters of event to be tracked.
234234
*
235+
* @returns Promise which is fulfilled when event was tracked and rejected if some internal error occured.
236+
*
237+
* **Important**: It might take pretty much time so do not block user application logic waiting for this promise to
238+
* become settled and consider using a timeout (see examples).
239+
*
235240
* @example
236241
* Adjust.trackEvent({
237242
* eventToken: 'YOUR_EVENT_TOKEN',
@@ -245,13 +250,19 @@ declare namespace Adjust {
245250
* partnerParams: [
246251
* {key: 'key-1', value: 'new-value-1'},
247252
* {key: 'some-partner-key-1', value: 'some-partner-value-1'},
248-
* {key: 'key-2', value: 'new-value-2'},
249-
* {key: 'some-partner-key-2', value: 'some-partner-value-2'},
250-
* {key: 'some-partner-key-1', value: 'some-partner-value-3'}
253+
* {key: 'key-2', value: 'new-value-2'}
251254
* ]
252255
* });
256+
*
257+
* @example
258+
* Promise.race([
259+
* Adjust.trackEvent({ eventToken: 'YOUR_EVENT_TOKEN' }),
260+
* new Promise((resolve, reject) => {
261+
* setTimeout(() => reject(new Error("Timed out")), 5000);
262+
* })
263+
* ]);
253264
*/
254-
function trackEvent(params: EventParams): void
265+
function trackEvent(params: EventParams): Promise<void>
255266

256267
/**
257268
* Add global callback parameters

dist/adjust-latest.js

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ function isLocalStorageSupported() /*: boolean*/{
21802180
|}*/
21812181
var Globals = {
21822182
namespace: "adjust-sdk" || 0,
2183-
version: "5.5.0" || 0,
2183+
version: "5.6.0" || 0,
21842184
env: "production"
21852185
};
21862186
/* harmony default export */ const globals = (Globals);
@@ -7452,6 +7452,9 @@ import { type DocumentT, type HttpSuccessResponseT, type HttpErrorResponseT, typ
74527452

74537453

74547454

7455+
7456+
7457+
74557458
/**
74567459
* Flag to mark if session watch is already on
74577460
*
@@ -7540,6 +7543,7 @@ function session_destroy() /*: void*/{
75407543
if (_pva) {
75417544
clearTimeout(_idTimeout);
75427545
off(documentExt, _pva.visibilityChange, _handleVisibilityChange);
7546+
on(documentExt, _pva.visibilityChange, _restoreAfterAsyncEnable);
75437547
}
75447548
}
75457549

@@ -7584,6 +7588,16 @@ function _handleVisibilityChange() /*: void*/{
75847588
var handler = _pva && documentExt[_pva.hidden] ? _handleBackground : _handleForeground;
75857589
_idTimeout = setTimeout(handler, 0);
75867590
}
7591+
function _restoreAfterAsyncEnable() /*: void*/{
7592+
if (!_pva || documentExt[_pva.hidden]) {
7593+
return;
7594+
}
7595+
reload();
7596+
if (!_running && disable_status() === 'on') {
7597+
off(documentExt, _pva.visibilityChange, _restoreAfterAsyncEnable);
7598+
main.__internal__.restartAfterAsyncEnable();
7599+
}
7600+
}
75877601

75887602
/**
75897603
* Handle session request finish; update installed state
@@ -8239,13 +8253,14 @@ function _checkEventDeduplicationId(id /*: string*/) /*: Promise<?number>*/{
82398253
* @param {number=} timestamp
82408254
* @return Promise
82418255
*/
8242-
function event_event(params /*: EventParamsT*/, timestamp /*: number*/) /*: void | Promise<void>*/{
8256+
function event_event(params /*: EventParamsT*/, timestamp /*: number*/) /*: Promise<void>*/{
82438257
if (!params || params && (isEmpty(params) || !params.eventToken)) {
8244-
logger.error('You must provide event token in order to track event');
8245-
return;
8258+
var reason = 'You must provide event token in order to track event';
8259+
logger.error(reason);
8260+
return event_Promise.reject(reason);
82468261
}
82478262
return _checkEventDeduplicationId(params.deduplicationId).then(get).then(function (globalParams) {
8248-
push({
8263+
return push({
82498264
url: '/event',
82508265
method: 'POST',
82518266
params: event_prepareParams(params, globalParams)
@@ -8256,6 +8271,7 @@ function event_event(params /*: EventParamsT*/, timestamp /*: number*/) /*: void
82568271
if (error && error.message) {
82578272
logger.error(error.message);
82588273
}
8274+
return event_Promise.reject(error);
82598275
});
82608276
}
82618277
;// CONCATENATED MODULE: ./src/sdk/sdk-click.js
@@ -9484,13 +9500,8 @@ function setReferrer(referrer /*: string*/) {
94849500
*
94859501
* @param {Object} params
94869502
*/
9487-
function trackEvent(params /*: EventParamsT*/) /*: void*/{
9488-
_preCheck('track event', function (timestamp) {
9489-
return event_event(params, timestamp);
9490-
}, {
9491-
schedule: true,
9492-
waitForInitFinished: true
9493-
});
9503+
function trackEvent(params /*: EventParamsT*/) /*: Promise<void>*/{
9504+
return _internalTrackEvent(params);
94949505
}
94959506

94969507
/**
@@ -9612,8 +9623,7 @@ function gdprForgetMe() /*: void*/{
96129623
*/
96139624
function disableThirdPartySharing() /*: void*/{
96149625
_preCheck('disable third-party sharing', _handleDisableThirdPartySharing, {
9615-
schedule: true,
9616-
waitForInitFinished: false
9626+
schedule: true
96179627
});
96189628
}
96199629
function initSmartBanner(options /*: SmartBannerOptionsT*/) /*: void*/{
@@ -9839,6 +9849,34 @@ function _start(options /*: InitOptionsT*/) /*: void*/{
98399849
}
98409850
start().then(main_continue).then(sdkClick).catch(main_error);
98419851
}
9852+
function _internalTrackEvent(params /*: EventParamsT*/) {
9853+
if (storage.getType() === STORAGE_TYPES.NO_STORAGE) {
9854+
var reason = 'Adjust SDK can not track event, no storage available';
9855+
logger.log(reason);
9856+
return main_Promise.reject(reason);
9857+
}
9858+
if (disable_status() !== 'on') {
9859+
var _reason = 'Adjust SDK is disabled, can not track event';
9860+
logger.log(_reason);
9861+
return main_Promise.reject(_reason);
9862+
}
9863+
if (!_isInitialised()) {
9864+
var _reason2 = 'Adjust SDK can not track event, sdk instance is not initialized';
9865+
logger.error(_reason2);
9866+
return main_Promise.reject(_reason2);
9867+
}
9868+
return new main_Promise(function (resolve) {
9869+
var _callback = function _callback(timestamp) {
9870+
return resolve(event_event(params, timestamp));
9871+
};
9872+
if (!_isInstalled || !_isStarted && _isInitialised()) {
9873+
delay(_callback, 'track event');
9874+
logger.log('Running track event is delayed until Adjust SDK is up');
9875+
} else {
9876+
_callback();
9877+
}
9878+
});
9879+
}
98429880

98439881
/**
98449882
* Check if it's possible to run provided method
@@ -9861,12 +9899,12 @@ function _preCheck(description /*: string*/, callback /*: () => mixed*/) /*: mix
98619899
logger.log("Adjust SDK is disabled, can not ".concat(description));
98629900
return;
98639901
}
9864-
if (!optionalInit && waitForInitFinished && !_isInitialised()) {
9902+
if (!(optionalInit || _isInitialised()) && waitForInitFinished) {
98659903
logger.error("Adjust SDK can not ".concat(description, ", sdk instance is not initialized"));
98669904
return;
98679905
}
98689906
if (typeof callback === 'function') {
9869-
if (schedule && !(_isInstalled && _isStarted) && (_isInitialised() || optionalInit)) {
9907+
if (schedule && !(_isInstalled && _isStarted) && (optionalInit || _isInitialised())) {
98709908
delay(callback, description);
98719909
logger.log("Running ".concat(description, " is delayed until Adjust SDK is up"));
98729910
} else {
@@ -9877,6 +9915,12 @@ function _preCheck(description /*: string*/, callback /*: () => mixed*/) /*: mix
98779915
function _clearDatabase() {
98789916
return storage.deleteDatabase();
98799917
}
9918+
function _restartAfterAsyncEnable() {
9919+
logger.log('Adjust SDK has been restarted due to asynchronous enable');
9920+
if (main_options) {
9921+
_start(main_options);
9922+
}
9923+
}
98809924
var Adjust = {
98819925
initSdk: initSdk,
98829926
getAttribution: main_getAttribution,
@@ -9901,6 +9945,9 @@ var Adjust = {
99019945
__testonly__: {
99029946
destroy: main_destroy,
99039947
clearDatabase: _clearDatabase
9948+
},
9949+
__internal__: {
9950+
restartAfterAsyncEnable: _restartAfterAsyncEnable
99049951
}
99059952
};
99069953
/* harmony default export */ const main = (Adjust);

dist/adjust-latest.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/sdk.snippet-sri.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/chinese/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Read this in other languages: [English][en-readme], [中文][zh-readme], [日本
1616
* [停用/重启 SDK](#stop-restart-sdk)
1717
* [GDPR 被遗忘权](#gdpr-forget-me)
1818
* [选择退出营销活动](#marketing-opt-out)
19+
* [数据驻留](#data-residency)
1920
* [许可协议](#license)
2021

2122
## <a id="example-app">应用示例</a>
@@ -37,7 +38,7 @@ Read this in other languages: [English][en-readme], [中文][zh-readme], [日本
3738

3839
Adjust Web SDK 在每个页面应当仅加载一次,每次页面加载应当初始化一次。
3940

40-
在通过 CDN 加载 SDK 时,我们建议您使用精简版本。您可以定向特定版本,如 `https://cdn.adjust.com/adjust-5.5.0.min.js`;如果您需要自动更新,不想变更目标文件,也可以定向最新版本:`https://cdn.adjust.com/adjust-latest.min.js` 。SDK 文件均有缓存,因此能以最快速度获取,缓存每半小时刷新一次。如果您想立即获得更新,请务必定向特定版本。
41+
在通过 CDN 加载 SDK 时,我们建议您使用精简版本。您可以定向特定版本,如 `https://cdn.adjust.com/adjust-5.6.0.min.js`;如果您需要自动更新,不想变更目标文件,也可以定向最新版本:`https://cdn.adjust.com/adjust-latest.min.js` 。SDK 文件均有缓存,因此能以最快速度获取,缓存每半小时刷新一次。如果您想立即获得更新,请务必定向特定版本。
4142

4243
您也可以通过 NPM 安装我们的 SDK:
4344

@@ -356,6 +357,27 @@ Adjust.gdprForgetMe();
356357
Adjust.disableThirdPartySharing();
357358
```
358359

360+
## <a id="data-residency">数据驻留</a>
361+
362+
通过数据驻留 (data residency) 功能,您可以选择 Adjust 将您的数据存储在哪个国家。当应用运营的国家拥有严格的隐私规定时,此功能会非常有用。设置数据驻留后,Adjust 会将您的数据存储在所选地区的数据中心。
363+
364+
要设置您的数据驻留地区,请在 `initSdk`调用中传递一个 `dataResidency` 参数。
365+
366+
```js
367+
Adjust.initSdk({
368+
"appToken": "YOUR_APP_TOKEN",
369+
"environment": "production",
370+
"logLevel": "verbose",
371+
"dataResidency": "EU"
372+
})
373+
```
374+
375+
可用值如下:
376+
377+
- `EU` – 将数据驻留地区设为欧盟。
378+
- `TR` – 将数据驻留地区设为土耳其。
379+
- `US` – 将数据驻留地区设为美国。
380+
359381
## <a id="license">许可协议</a>
360382

361383
Adjust SDK 已获得 MIT 许可。

0 commit comments

Comments
 (0)