1e41f4b71Sopenharmony_ci# OAID Service 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## When to Use 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciAn Open Anonymous Device Identifier (OAID) is a non-permanent device identifier. The OAID service is useful for media application developers, ad platforms, and tracking platforms alike. Specifically, it provides personalized ads for users while protecting their personal data privacy, and also interact with third-party tracking platforms to provide conversion attribution analysis for advertisers. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciAn OAID is a 32-bit Universally Unique Identifier (UUID) generated using a Huawei algorithm. The format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ciThe OAID has the following features: 10e41f4b71Sopenharmony_ci- The OAID is device specific. Different applications on the same device obtain the same OAID. 11e41f4b71Sopenharmony_ci- The OAID obtained depends on the switch of the **ohos.permission.APP_TRACKING_CONSENT** permission. When the switch is enabled, the application obtains a valid OAID that is not all zeros. When the switch is disabled, the application obtains an all-zero OAID. 12e41f4b71Sopenharmony_ci- An OAID is generated when any application on the device enables the **ohos.permission.APP_TRACKING_CONSENT** permission for the first time. 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ciThe OAID changes in the following scenarios: 15e41f4b71Sopenharmony_ci- A user restores the factory settings of the device. 16e41f4b71Sopenharmony_ci- A user resets the OAID. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci### Available APIs 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci| API| Description| 21e41f4b71Sopenharmony_ci| -------- | -------- | 22e41f4b71Sopenharmony_ci| <!--Del-->[<!--DelEnd-->getOAID<!--Del-->](../../reference/apis-ads-kit/js-apis-oaid.md#identifiergetoaid)<!--DelEnd-->(): Promise<string> | Obtains an OAID. This API uses a promise to return the result.| 23e41f4b71Sopenharmony_ci| <!--Del-->[<!--DelEnd-->getOAID<!--Del-->](../../reference/apis-ads-kit/js-apis-oaid.md#identifiergetoaid-1)<!--DelEnd-->(callback: AsyncCallback<string>): void | Obtains an OAID. This API uses an asynchronous callback to return the result.| 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci> **NOTE** 26e41f4b71Sopenharmony_ci> To call **getOAID()**, the application must request the permission **ohos.permission.APP_TRACKING_CONSENT** and user authorization. Three situations are possible: 27e41f4b71Sopenharmony_ci> 28e41f4b71Sopenharmony_ci> - If the application has configured the permission **ohos.permission.APP_TRACKING_CONSENT** and the permission is allowed, the OAID is returned. 29e41f4b71Sopenharmony_ci> - If the application has configured the permission **ohos.permission.APP_TRACKING_CONSENT** and the permission is disallowed, 00000000-0000-0000-0000-000000000000 is returned. 30e41f4b71Sopenharmony_ci> - If the application has not configured the permission **ohos.permission.APP_TRACKING_CONSENT**, 00000000-0000-0000-0000-000000000000 is returned. 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci## How to Develop 34e41f4b71Sopenharmony_ci1. In the **module.json5** file of the module, configure the permission [ohos.permission.APP_TRACKING_CONSENT](../../security/AccessToken/permissions-for-all.md#ohospermissionapp_tracking_consent), which is a user_grant permission. In this case, the **reason** and **abilities** fields are mandatory. For details about the configuration, see [requestPermissions](../../quick-start/module-configuration-file.md#requestpermissions). 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci The sample code is as follows: 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci ```ts 39e41f4b71Sopenharmony_ci { 40e41f4b71Sopenharmony_ci "module": { 41e41f4b71Sopenharmony_ci "requestPermissions": [ 42e41f4b71Sopenharmony_ci { 43e41f4b71Sopenharmony_ci "name": "ohos.permission.APP_TRACKING_CONSENT", 44e41f4b71Sopenharmony_ci "reason": "$string:reason", 45e41f4b71Sopenharmony_ci "usedScene": { 46e41f4b71Sopenharmony_ci "abilities": [ 47e41f4b71Sopenharmony_ci "EntryFormAbility" 48e41f4b71Sopenharmony_ci ], 49e41f4b71Sopenharmony_ci "when": "inuse" 50e41f4b71Sopenharmony_ci } 51e41f4b71Sopenharmony_ci } 52e41f4b71Sopenharmony_ci ] 53e41f4b71Sopenharmony_ci } 54e41f4b71Sopenharmony_ci } 55e41f4b71Sopenharmony_ci ``` 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci2. To obtain the OAID, the application must call **requestPermissionFromUser** to obtain the corresponding permission. For details about how to obtain the context, see [Context](../../application-models/application-context-stage.md). 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci The sample code is as follows: 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci ```ts 62e41f4b71Sopenharmony_ci import { identifier } from '@kit.AdsKit'; 63e41f4b71Sopenharmony_ci import { abilityAccessCtrl, common } from '@kit.AbilityKit'; 64e41f4b71Sopenharmony_ci import { hilog } from '@kit.PerformanceAnalysisKit'; 65e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci function requestOAIDTrackingConsentPermissions(context: common.Context): void { 68e41f4b71Sopenharmony_ci // When the page is displayed, request the user to grant the permission ohos.permission.APP_TRACKING_CONSENT. 69e41f4b71Sopenharmony_ci const atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); 70e41f4b71Sopenharmony_ci try { 71e41f4b71Sopenharmony_ci atManager.requestPermissionsFromUser(context, ["ohos.permission.APP_TRACKING_CONSENT"]).then((data) => { 72e41f4b71Sopenharmony_ci if (data.authResults[0] == 0) { 73e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', '%{public}s', 'succeeded in requesting permission'); 74e41f4b71Sopenharmony_ci identifier.getOAID((err: BusinessError, data: string) => { 75e41f4b71Sopenharmony_ci if (err.code) { 76e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', '%{public}s', `get oaid failed, error: ${err.code} ${err.message}`); 77e41f4b71Sopenharmony_ci } else { 78e41f4b71Sopenharmony_ci const oaid: string = data; 79e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', '%{public}s', `succeeded in getting oaid by callback , oaid: ${oaid}`); 80e41f4b71Sopenharmony_ci } 81e41f4b71Sopenharmony_ci }); 82e41f4b71Sopenharmony_ci } else { 83e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', '%{public}s', 'user rejected'); 84e41f4b71Sopenharmony_ci } 85e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 86e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', '%{public}s', `request permission failed, error: ${err.code} ${err.message}`); 87e41f4b71Sopenharmony_ci }) 88e41f4b71Sopenharmony_ci } catch (err) { 89e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', '%{public}s', `catch err->${err.code}, ${err.message}`); 90e41f4b71Sopenharmony_ci } 91e41f4b71Sopenharmony_ci } 92e41f4b71Sopenharmony_ci ``` 93