Skip to content

Commit

Permalink
Merge pull request #52 from adjust/v560
Browse files Browse the repository at this point in the history
Version 5.6.0
  • Loading branch information
YaraMatkova authored Jan 30, 2023
2 parents 3340026 + 555cdc1 commit df424ba
Show file tree
Hide file tree
Showing 43 changed files with 1,312 additions and 713 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### Version 5.6.0 (30th January 2023)
#### Added
- Added a return of Promise from `trackEvent` method.

#### Fixed
- Fixed SDK state synchronization issue between multiple tabs.

---

### Version 5.5.0 (17th November 2022)
#### Added
- Added `setReferrer` method to set referrer and trigger `/sdk_click` request manually.
Expand All @@ -6,6 +15,7 @@
- Fixed [issue](https://github.com/adjust/web_sdk/issues/46) which caused site not to load when cookies are blocked in browser.

---

### Version 5.4.0 (20th September 2022)
#### Added
- Added support of Data Residency.
Expand Down
56 changes: 54 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Read this in other languages: [English][en-readme], [中文][zh-readme], [日本
* [Stop/Restart SDK](#stop-restart-sdk)
* [GDPR Forget Me](#gdpr-forget-me)
* [Marketing Opt-out](#marketing-opt-out)
* [Data residency](#data-residency)
* [License](#license)

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

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

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.
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.

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:
```html
<script type="application/javascript">
!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])}}));
!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])}}));
</script>
```

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

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)

### Tracking an event and redirect to an external page

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.

> **Important** It might take pretty much time until this promise is settled so it's recommended to use a timeout.
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.

Example:

```js
Promise
.race([
Adjust.trackEvent({
eventToken: 'YOUR_EVENT_TOKEN',
// ... other event parameters
}),
new Promise((resolve, reject) => {
setTimeout(() => reject('Timed out'), 2000)
})
])
.catch(error => {
// ...
})
.then(() => {
// ... perform redirect, for example
window.location.href = "https://www.example.org/"
});
```

## <a id="global-callback-parameters">Global callback parameters</a>

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

> **Important** For proper attribution this method should be called as close as possible to SDK initialization.
## <a id="data-residency">Data residency</a>

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.

To set your country of data residency, pass a `dataResidency` argument in your `initSdk` call.

```js
Adjust.initSdk({
"appToken": "YOUR_APP_TOKEN",
"environment": "production",
"logLevel": "verbose",
"dataResidency": "EU"
})
```

The following values are accepted:

- `EU` – sets the data residency region to the EU.
- `TR` – sets the data residency region to Turkey.
- `US` – sets the data residency region to the USA.

## <a id="license">License</a>

The Adjust SDK is licensed under the MIT License.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.5.0
5.6.0
2 changes: 1 addition & 1 deletion dist/INTEGRITY
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sha384-ti9hnBz5iMLIfOik3tirvSeTYG6T0ZZTluQjGNeL0/WZP2kNe+pi8On+zOoBJCl7
sha384-BqbTn9xyk5DPznti1ZP8ksxKiOFhKufLBFWm5eNMCnZABFSG1eqQfcu5dsiZJHu5
19 changes: 15 additions & 4 deletions dist/adjust-latest.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ declare namespace Adjust {
*
* @param {EventParams} params Parameters of event to be tracked.
*
* @returns Promise which is fulfilled when event was tracked and rejected if some internal error occured.
*
* **Important**: It might take pretty much time so do not block user application logic waiting for this promise to
* become settled and consider using a timeout (see examples).
*
* @example
* Adjust.trackEvent({
* eventToken: 'YOUR_EVENT_TOKEN',
Expand All @@ -245,13 +250,19 @@ declare namespace Adjust {
* partnerParams: [
* {key: 'key-1', value: 'new-value-1'},
* {key: 'some-partner-key-1', value: 'some-partner-value-1'},
* {key: 'key-2', value: 'new-value-2'},
* {key: 'some-partner-key-2', value: 'some-partner-value-2'},
* {key: 'some-partner-key-1', value: 'some-partner-value-3'}
* {key: 'key-2', value: 'new-value-2'}
* ]
* });
*
* @example
* Promise.race([
* Adjust.trackEvent({ eventToken: 'YOUR_EVENT_TOKEN' }),
* new Promise((resolve, reject) => {
* setTimeout(() => reject(new Error("Timed out")), 5000);
* })
* ]);
*/
function trackEvent(params: EventParams): void
function trackEvent(params: EventParams): Promise<void>

/**
* Add global callback parameters
Expand Down
79 changes: 63 additions & 16 deletions dist/adjust-latest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ function isLocalStorageSupported() /*: boolean*/{
|}*/
var Globals = {
namespace: "adjust-sdk" || 0,
version: "5.5.0" || 0,
version: "5.6.0" || 0,
env: "production"
};
/* harmony default export */ const globals = (Globals);
Expand Down Expand Up @@ -7452,6 +7452,9 @@ import { type DocumentT, type HttpSuccessResponseT, type HttpErrorResponseT, typ






/**
* Flag to mark if session watch is already on
*
Expand Down Expand Up @@ -7540,6 +7543,7 @@ function session_destroy() /*: void*/{
if (_pva) {
clearTimeout(_idTimeout);
off(documentExt, _pva.visibilityChange, _handleVisibilityChange);
on(documentExt, _pva.visibilityChange, _restoreAfterAsyncEnable);
}
}

Expand Down Expand Up @@ -7584,6 +7588,16 @@ function _handleVisibilityChange() /*: void*/{
var handler = _pva && documentExt[_pva.hidden] ? _handleBackground : _handleForeground;
_idTimeout = setTimeout(handler, 0);
}
function _restoreAfterAsyncEnable() /*: void*/{
if (!_pva || documentExt[_pva.hidden]) {
return;
}
reload();
if (!_running && disable_status() === 'on') {
off(documentExt, _pva.visibilityChange, _restoreAfterAsyncEnable);
main.__internal__.restartAfterAsyncEnable();
}
}

/**
* Handle session request finish; update installed state
Expand Down Expand Up @@ -8239,13 +8253,14 @@ function _checkEventDeduplicationId(id /*: string*/) /*: Promise<?number>*/{
* @param {number=} timestamp
* @return Promise
*/
function event_event(params /*: EventParamsT*/, timestamp /*: number*/) /*: void | Promise<void>*/{
function event_event(params /*: EventParamsT*/, timestamp /*: number*/) /*: Promise<void>*/{
if (!params || params && (isEmpty(params) || !params.eventToken)) {
logger.error('You must provide event token in order to track event');
return;
var reason = 'You must provide event token in order to track event';
logger.error(reason);
return event_Promise.reject(reason);
}
return _checkEventDeduplicationId(params.deduplicationId).then(get).then(function (globalParams) {
push({
return push({
url: '/event',
method: 'POST',
params: event_prepareParams(params, globalParams)
Expand All @@ -8256,6 +8271,7 @@ function event_event(params /*: EventParamsT*/, timestamp /*: number*/) /*: void
if (error && error.message) {
logger.error(error.message);
}
return event_Promise.reject(error);
});
}
;// CONCATENATED MODULE: ./src/sdk/sdk-click.js
Expand Down Expand Up @@ -9484,13 +9500,8 @@ function setReferrer(referrer /*: string*/) {
*
* @param {Object} params
*/
function trackEvent(params /*: EventParamsT*/) /*: void*/{
_preCheck('track event', function (timestamp) {
return event_event(params, timestamp);
}, {
schedule: true,
waitForInitFinished: true
});
function trackEvent(params /*: EventParamsT*/) /*: Promise<void>*/{
return _internalTrackEvent(params);
}

/**
Expand Down Expand Up @@ -9612,8 +9623,7 @@ function gdprForgetMe() /*: void*/{
*/
function disableThirdPartySharing() /*: void*/{
_preCheck('disable third-party sharing', _handleDisableThirdPartySharing, {
schedule: true,
waitForInitFinished: false
schedule: true
});
}
function initSmartBanner(options /*: SmartBannerOptionsT*/) /*: void*/{
Expand Down Expand Up @@ -9839,6 +9849,34 @@ function _start(options /*: InitOptionsT*/) /*: void*/{
}
start().then(main_continue).then(sdkClick).catch(main_error);
}
function _internalTrackEvent(params /*: EventParamsT*/) {
if (storage.getType() === STORAGE_TYPES.NO_STORAGE) {
var reason = 'Adjust SDK can not track event, no storage available';
logger.log(reason);
return main_Promise.reject(reason);
}
if (disable_status() !== 'on') {
var _reason = 'Adjust SDK is disabled, can not track event';
logger.log(_reason);
return main_Promise.reject(_reason);
}
if (!_isInitialised()) {
var _reason2 = 'Adjust SDK can not track event, sdk instance is not initialized';
logger.error(_reason2);
return main_Promise.reject(_reason2);
}
return new main_Promise(function (resolve) {
var _callback = function _callback(timestamp) {
return resolve(event_event(params, timestamp));
};
if (!_isInstalled || !_isStarted && _isInitialised()) {
delay(_callback, 'track event');
logger.log('Running track event is delayed until Adjust SDK is up');
} else {
_callback();
}
});
}

/**
* Check if it's possible to run provided method
Expand All @@ -9861,12 +9899,12 @@ function _preCheck(description /*: string*/, callback /*: () => mixed*/) /*: mix
logger.log("Adjust SDK is disabled, can not ".concat(description));
return;
}
if (!optionalInit && waitForInitFinished && !_isInitialised()) {
if (!(optionalInit || _isInitialised()) && waitForInitFinished) {
logger.error("Adjust SDK can not ".concat(description, ", sdk instance is not initialized"));
return;
}
if (typeof callback === 'function') {
if (schedule && !(_isInstalled && _isStarted) && (_isInitialised() || optionalInit)) {
if (schedule && !(_isInstalled && _isStarted) && (optionalInit || _isInitialised())) {
delay(callback, description);
logger.log("Running ".concat(description, " is delayed until Adjust SDK is up"));
} else {
Expand All @@ -9877,6 +9915,12 @@ function _preCheck(description /*: string*/, callback /*: () => mixed*/) /*: mix
function _clearDatabase() {
return storage.deleteDatabase();
}
function _restartAfterAsyncEnable() {
logger.log('Adjust SDK has been restarted due to asynchronous enable');
if (main_options) {
_start(main_options);
}
}
var Adjust = {
initSdk: initSdk,
getAttribution: main_getAttribution,
Expand All @@ -9901,6 +9945,9 @@ var Adjust = {
__testonly__: {
destroy: main_destroy,
clearDatabase: _clearDatabase
},
__internal__: {
restartAfterAsyncEnable: _restartAfterAsyncEnable
}
};
/* harmony default export */ const main = (Adjust);
Expand Down
2 changes: 1 addition & 1 deletion dist/adjust-latest.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sdk.snippet-sri.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion docs/chinese/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Read this in other languages: [English][en-readme], [中文][zh-readme], [日本
* [停用/重启 SDK](#stop-restart-sdk)
* [GDPR 被遗忘权](#gdpr-forget-me)
* [选择退出营销活动](#marketing-opt-out)
* [数据驻留](#data-residency)
* [许可协议](#license)

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

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

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

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

Expand Down Expand Up @@ -356,6 +357,27 @@ Adjust.gdprForgetMe();
Adjust.disableThirdPartySharing();
```

## <a id="data-residency">数据驻留</a>

通过数据驻留 (data residency) 功能,您可以选择 Adjust 将您的数据存储在哪个国家。当应用运营的国家拥有严格的隐私规定时,此功能会非常有用。设置数据驻留后,Adjust 会将您的数据存储在所选地区的数据中心。

要设置您的数据驻留地区,请在 `initSdk`调用中传递一个 `dataResidency` 参数。

```js
Adjust.initSdk({
"appToken": "YOUR_APP_TOKEN",
"environment": "production",
"logLevel": "verbose",
"dataResidency": "EU"
})
```

可用值如下:

- `EU` – 将数据驻留地区设为欧盟。
- `TR` – 将数据驻留地区设为土耳其。
- `US` – 将数据驻留地区设为美国。

## <a id="license">许可协议</a>

Adjust SDK 已获得 MIT 许可。
Expand Down
Loading

0 comments on commit df424ba

Please sign in to comment.