@capawesome/capacitor-app-tracking-transparency

中文文档
0.1.2发布于 2026/09/02MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 5151

Capacitor plugin for the App Tracking Transparency framework on iOS.

原始使用文档
文档目录28 节
  1. Features
  2. Use Cases
  3. Compatibility
  4. Installation
  5. iOS
  6. Configuration
  7. Usage
  8. Check the tracking authorization status
  9. Request tracking permission
  10. Read the advertising identifier
  11. API
  12. getAdvertisingIdentifier()
  13. getStatus()
  14. requestPermission()
  15. Interfaces
  16. Type Aliases
  17. App Review Guidance
  18. FAQ
  19. How is this plugin different from other similar plugins?
  20. Does this plugin work on Android or Web?
  21. Why does the requestPermission method reject with an error?
  22. Why is the tracking authorization prompt not shown?
  23. Why does getAdvertisingIdentifier return null?
  24. Can I use this plugin with Ionic, React, Vue or Angular?
  25. Related Plugins
  26. Newsletter
  27. Changelog
  28. License

Capacitor App Tracking Transparency Plugin

Capacitor plugin for the App Tracking Transparency framework.

Features

The Capacitor App Tracking Transparency plugin is one of the most complete tracking authorization solutions for Capacitor apps. Here are some of the key features:

  • 🔒 Authorization status: Read the current tracking authorization status.
  • 🙋 Permission request: Present the system tracking authorization prompt.
  • 🆔 Advertising identifier: Read the advertising identifier (IDFA) when authorized.
  • 🤝 Compatibility: Works alongside the Permissions plugin.
  • 📦 CocoaPods & SPM: Supports CocoaPods and Swift Package Manager for iOS.
  • 🔁 Up-to-date: Always supports the latest Capacitor version.

Missing a feature? Just open an issue and we'll take a look!

Use Cases

The App Tracking Transparency plugin is typically used whenever an iOS app collects data for tracking purposes, for example:

  • Personalized ads: Request tracking permission before serving personalized ads to the user.
  • Ad attribution: Read the advertising identifier (IDFA) to attribute app installs to ad campaigns once the user has authorized tracking.
  • Conditional tracking: Check the current tracking authorization status and only enable tracking-related features when the status is authorized.
  • App Review compliance: Present the system tracking authorization prompt as required by Apple for any app that tracks users.

Compatibility

Plugin VersionCapacitor VersionStatus
0.x.x>=8.x.xActive support

Installation

You can use our AI-Assisted Setup to install the plugin. Add the Capawesome Skills to your AI tool using the following command:

npx skills add capawesome-team/skills --skill capacitor-plugins

Then use the following prompt:

 Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-app-tracking-transparency` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capawesome/capacitor-app-tracking-transparency
npx cap sync

This plugin is only available on iOS. On Android and Web, all methods reject as unimplemented.

iOS

Privacy Descriptions

The NSUserTrackingUsageDescription key must be added to the Info.plist file of your app. Otherwise, the requestPermission(...) method will reject with an error.

<key>NSUserTrackingUsageDescription</key>
<string>Your data will be used to deliver personalized ads to you.</string>

The purpose string must clearly explain why your app is requesting permission to track the user. See the Apple documentation for more information.

Configuration

No configuration required for this plugin.

Usage

The following examples show how to check the tracking authorization status, request tracking permission, and read the advertising identifier.

Check the tracking authorization status

Read the current tracking authorization status, for example to decide whether tracking-related features should be enabled. Only available on iOS:

import { AppTrackingTransparency } from '@capawesome/capacitor-app-tracking-transparency';

const getStatus = async () => {
  const { status } = await AppTrackingTransparency.getStatus();
  return status;
};

Request tracking permission

Present the system tracking authorization prompt. The prompt is only shown once per install while the status is notDetermined; afterwards, the method resolves with the existing status. Only available on iOS:

import { AppTrackingTransparency } from '@capawesome/capacitor-app-tracking-transparency';

const requestPermission = async () => {
  const { status } = await AppTrackingTransparency.requestPermission();
  return status;
};

Read the advertising identifier

Read the advertising identifier (IDFA) of the device. It is only available if the tracking authorization status is authorized; otherwise, null is returned. Only available on iOS:

import { AppTrackingTransparency } from '@capawesome/capacitor-app-tracking-transparency';

const getAdvertisingIdentifier = async () => {
  const { advertisingIdentifier } =
    await AppTrackingTransparency.getAdvertisingIdentifier();
  return advertisingIdentifier;
};

API

getAdvertisingIdentifier()

getAdvertisingIdentifier() => Promise<GetAdvertisingIdentifierResult>

Get the advertising identifier (IDFA) of the device.

The advertising identifier is only available if the tracking authorization status is authorized. Otherwise, null is returned.

Note: The iOS Simulator always returns null, even if the tracking authorization status is authorized. Use a real device to test this method.

Only available on iOS.

Returns: Promise<GetAdvertisingIdentifierResult>

Since: 0.1.0


getStatus()

getStatus() => Promise<GetStatusResult>

Get the current tracking authorization status.

Only available on iOS.

Returns: Promise<GetStatusResult>

Since: 0.1.0


requestPermission()

requestPermission() => Promise<RequestPermissionResult>

Request permission to track the user.

This will present the system tracking authorization prompt if the status has not been determined yet. The prompt is only shown once per install.

The NSUserTrackingUsageDescription key must be added to the Info.plist file of your app.

Only available on iOS.

Returns: Promise<RequestPermissionResult>

Since: 0.1.0


Interfaces

GetAdvertisingIdentifierResult

PropTypeDescriptionSince
advertisingIdentifierstring | nullThe advertising identifier (IDFA) of the device. Returns null if the tracking authorization status is not authorized or if no advertising identifier is available, which is always the case on the iOS Simulator.0.1.0

GetStatusResult

PropTypeDescriptionSince
statusTrackingStatusThe current tracking authorization status.0.1.0

RequestPermissionResult

PropTypeDescriptionSince
statusTrackingStatusThe tracking authorization status after the request.0.1.0

Type Aliases

TrackingStatus

The tracking authorization status.

  • authorized: The user authorized access to app-related data for tracking.
  • denied: The user denied access to app-related data for tracking.
  • notDetermined: The user has not yet received a tracking authorization request.
  • restricted: Tracking authorization is restricted and cannot be changed by the user.

'authorized' | 'denied' | 'notDetermined' | 'restricted'

App Review Guidance

Apple requires that any app that tracks users requests permission via the App Tracking Transparency framework. Keep the following guidelines in mind to avoid App Review rejections:

  • Prompt timing: Call requestPermission(...) only when the user is in a context where tracking makes sense. The system prompt is only shown once per install while the status is notDetermined. Calling the method again afterwards resolves with the existing status without showing the prompt.
  • Purpose string: The NSUserTrackingUsageDescription purpose string must accurately describe how the collected data is used. Vague or misleading descriptions are a common reason for rejection.
  • Advertising identifier: The advertising identifier (IDFA) is only available while the status is authorized. In all other cases, getAdvertisingIdentifier(...) returns null.
  • Simulator: The iOS Simulator never provides an advertising identifier, so getAdvertisingIdentifier(...) always returns null there, even if the status is authorized. Use a real device to test the advertising identifier.

FAQ

How is this plugin different from other similar plugins?

It wraps Apple's App Tracking Transparency framework in a small, fully typed API: read the current authorization status, present the system prompt, and read the advertising identifier (IDFA) once the user has authorized tracking. It also ships focused App Review guidance on prompt timing, purpose strings, and simulator behavior — the details that most often decide whether a tracking-enabled app is approved. It supports CocoaPods and Swift Package Manager and is actively maintained against the latest Capacitor version.

Does this plugin work on Android or Web?

No, the App Tracking Transparency framework is an iOS-only concept. The plugin is only available on iOS; on Android and Web, all methods reject as unimplemented.

Why does the requestPermission method reject with an error?

The most common reason is a missing NSUserTrackingUsageDescription key in your app's Info.plist file. This key is required for the system tracking authorization prompt and its purpose string must clearly explain why your app is requesting permission to track the user. See the Installation section for details.

Why is the tracking authorization prompt not shown?

The system prompt is only shown once per install while the tracking authorization status is notDetermined. If the user has already responded to the prompt, calling requestPermission() again resolves with the existing status without showing the prompt. To test the prompt again, reinstall the app.

Why does getAdvertisingIdentifier return null?

The advertising identifier (IDFA) is only available if the tracking authorization status is authorized; in all other cases, null is returned. Additionally, the iOS Simulator never provides an advertising identifier, even if the status is authorized, so use a real device to test this method.

Can I use this plugin with Ionic, React, Vue or Angular?

Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.

  • Permissions: Check and request device permissions with a unified API.
  • Privacy Screen: Hide sensitive app content in the app switcher and block screenshots.

Newsletter

Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.

Changelog

See CHANGELOG.md.

License

See LICENSE.

版本与发布记录

@capawesome/capacitor-app-tracking-transparency 共发布 4 个版本,首次发布于 2026/07/07;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.2latest2026/09/022 个月前
0.1.12026/07/153 个月前
0.1.02026/07/143 个月前
0.0.12026/07/074 个月前

关于 @capawesome/capacitor-app-tracking-transparency 的常见问题

@capawesome/capacitor-app-tracking-transparency 是什么?

Capacitor plugin for the App Tracking Transparency framework on iOS.

如何安装 @capawesome/capacitor-app-tracking-transparency?

在项目目录运行 npm install @capawesome/capacitor-app-tracking-transparency,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capawesome/capacitor-app-tracking-transparency 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capawesome/capacitor-app-tracking-transparency 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capawesome/capacitor-app-tracking-transparency 可以商用吗?

@capawesome/capacitor-app-tracking-transparency 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@capawesome/capacitor-app-tracking-transparency 的下载量有多少?

根据 npm 官方下载统计,@capawesome/capacitor-app-tracking-transparency 在 2026/10/09 – 2026/11/07 这 30 天内被下载 5,151 次,日均约 172 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capawesome/capacitor-app-tracking-transparency 还在维护吗?

最新版本 0.1.2 发布于 2026/09/02(2 个月前);至今共发布 4 个版本,其中过去 12 个月发布了 4 个;首次发布于 2026/07/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。