For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /api/angular-lynx/accounts/tracking.md.

LynxTracking

Asks whether your app may track the person across other companies' apps and websites, and says what they answered. An ad or install-attribution SDK then reads the advertising ID only once they've allowed it. import { LynxTracking } from '@blotch/angular-lynx';

Turn it on

Add tracking to permissions in the build target's options in angular.json, with the reason iOS shows when it asks:

angular.json
"options": {
  "permissions": { "tracking": "Shows you ads that match your interests" }
}

What it adds:

  • iOS: NSUserTrackingUsageDescription in Info.plist, and the native code behind App Tracking Transparency's prompt. It doesn't declare tracking in the app's privacy manifest (PrivacyInfo.xcprivacy): Apple requires NSPrivacyTracking to come with the domains the app tracks with, which the build doesn't know. If your app connects to tracking domains, eject the iOS project and add both keys to ios/App/PrivacyInfo.xcprivacy. From iOS 17, requests to a listed domain fail until the person allows tracking.
  • Android: the com.google.android.gms.permission.AD_ID permission in the manifest, the native code, and Google Play services' advertising ID library.

Without it, the native code is left out of both apps, and the advertising ID library out of the Android one. That's because iOS ends an app that shows the prompt without a reason. Nothing rejects: status() becomes unsupported, and requestPermission() resolves with it.

See Turn on device features for every setting.

Usage

import { Component, inject } from '@angular/core';
import { LYNX_ELEMENTS, LynxTracking } from '@blotch/angular-lynx';
import { Ads } from './ads';

@Component({
  selector: 'app-feed',
  imports: [LYNX_ELEMENTS],
  template: `<text>Your feed</text>`,
})
export class Feed {
  readonly #ads = inject(Ads);
  readonly #tracking = inject(LynxTracking);

  async ngOnInit() {
    // Shows the prompt the first time, and answers at once after that.
    const status = await this.#tracking.requestPermission();
    this.#ads.start({ personalized: status === 'authorized' });
  }
}

Ads stands for the app's own wrapper around its ad SDK.

Ask when the person can see why, such as when they first open a screen with ads, rather than as the app launches.

  • iOS shows the prompt only once per install, and only to an app in the foreground.
  • A request made while the app isn't active waits until it is.

What the stores require

Both stores require this of an app that tracks:

  • iOS: since iOS 14.5, the advertising ID reads as zeros until the person allows tracking in App Tracking Transparency's prompt. App Review rejects an app that tracks without asking (guideline 5.1.2).
  • Android: Google Play gives an app that targets Android 13 or later the advertising ID only when it declares the AD_ID permission. There's no prompt, but the person can opt out of personalized ads, or delete the ID, in Settings. Play's policy says to respect it.

API

LynxTracking

@Injectable({ providedIn: 'root' })
class LynxTracking {
  readonly status: Signal<TrackingStatus>;
  requestPermission(): Promise<TrackingStatus>;
}

status

Whether the app may track the person, as a signal. It's read when the service is created, and again each time the app comes back to the foreground, since the person can change it in Settings meanwhile. Until the first answer, a moment after the service is created, it's notDetermined.

requestPermission()

Shows App Tracking Transparency's prompt on iOS, if the person hasn't been asked yet, and resolves with their answer, which status then holds too. Anywhere else, and once the person has answered, it resolves with the status without showing anything. It never rejects.

TrackingStatus

ValueMeans
authorizedThe app may track. On iOS the person allowed it; on Android they haven't opted out of personalized ads
deniedIt may not. On iOS the person declined, or turned off "Allow Apps to Request to Track"; on Android they opted out or deleted the advertising ID, which then reads as zeros
restrictediOS only. The phone doesn't let the person choose, as under parental controls, and the app may not track
notDeterminediOS only. The person hasn't been asked yet, so requestPermission() shows the prompt
unsupportedThere's no advertising ID to track with
PlatformAnswer
iOSApp Tracking Transparency's (ATTrackingManager): the prompt shows once per install
AndroidGoogle Play services' advertising ID: authorized, denied once the person opted out, unsupported without Play services
Web previewunsupported
Unit tests with the testing libraryWhat setTrackingStatus() sets, notDetermined by default
Lynx Explorerunsupported

LynxTracking doesn't read the advertising ID itself: the ad or attribution SDK does, once the status is authorized.

Testing

Each test starts where a fresh install on an iPhone does, notDetermined, and the prompt allows tracking. setTrackingStatus() sets the status, setTrackingAnswer() what the prompt answers, and trackingPrompts() counts the prompts shown:

import {
  render,
  setTrackingAnswer,
  trackingPrompts,
} from '@blotch/angular-lynx-testing-library';

setTrackingAnswer('denied');
await render(Feed);
expect(trackingPrompts()).toBe(1);