Skip to content

feat(audience-sdk): add Android GAID collection (SDK-309)#755

Merged
nattb8 merged 1 commit into
mainfrom
feat/sdk-309-android-gaid
May 8, 2026
Merged

feat(audience-sdk): add Android GAID collection (SDK-309)#755
nattb8 merged 1 commit into
mainfrom
feat/sdk-309-android-gaid

Conversation

@nattb8

@nattb8 nattb8 commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds Google Advertising ID (GAID) collection on Android. Studios who opt in get gaid and gaidLimitAdTracking shipped on game_launch events, useful for paid user-acquisition attribution and ads measurement.

What is GAID? A Google-issued advertising identifier (UUID, e.g. abcdef01-2345-...) that's the Android equivalent of iOS IDFA. It lets ad networks correlate clicks to installs without using cross-app PII. Users can reset it or opt out (Settings → Privacy → Ads). Adjust, AppsFlyer, Singular, Firebase Analytics all collect it for the same purpose.

How it works

  • JNI call to AdvertisingIdClient.getAdvertisingIdInfo() on a dedicated worker thread (Google requires off-main; Unity 2021 ThreadPool isn't auto-attached to the JVM).
  • Cached to disk; first launch ships nothing, launch # 2+ ships the previous value.
  • Reuses MobileAttributionContextProvider — no new provider field.
  • Soft-fails if the Maven dep isn't present: logs once, gaid doesn't ship, no crash.

Three independent gates

Skipping any one disables GAID without affecting other features:

Gate Controls
AUDIENCE_MOBILE_ATTRIBUTION define Compiles in JNI paths + reads cache
AudienceConfig.EnableMobileAttribution Runtime providers fire
play-services-ads-identifier Maven dep AdvertisingIdClient class + AD_ID permission (via AGP manifest merge)

Sample app

examples/audience/Assets/Plugins/Android/mainTemplate.gradle demonstrates the studio-side setup — line commented out by default with a comment block explaining when to uncomment.

Test plan

  • Editor unit tests (GAIDBridgeTests, ImmutableAudienceTests GAID cases)
  • Real device, define ON + dep present: gaid ships on launch feat: use local html file to load passport #2
  • Real device, define ON + dep absent: no crash, one ClassNotFoundException warning, no gaid shipped
  • APK inspection both states: AD_ID + AdvertisingIdClient present iff dep is present
  • R8 fullMode release build (proguard keep rules)

🤖 Generated with Claude Code


Note

High Risk
Adds new Android advertising identifier (GAID) collection via JNI/background threading and persists identifier-related data to disk, which is privacy- and platform-integration-sensitive. Incorrect gating or dependency/proguard/manifest interactions could cause missing data, Play Store permission mismatches, or Android runtime failures in some build configurations.

Overview
Adds opt-in Android GAID attribution so game_launch can include gaid and gaidLimitAdTracking when mobile attribution is enabled.

Introduces a new GAIDBridge that fetches GAID off the main thread via JNI, caches results to disk for subsequent launches, and ensures opted-out users never ship or persist the raw identifier; AttributionContext and Unity hooks are updated to read/emit this cached context only when AUDIENCE_MOBILE_ATTRIBUTION is defined.

Updates Android build guidance and hardening: adds Proguard keep rules for AdvertisingIdClient, clarifies manifest post-processing (no AD_ID injection), and updates the Unity sample project to use a custom Gradle template with a documented (commented) Play Services dependency. Adds unit tests covering GAID caching/emission and game_launch payload behavior.

Reviewed by Cursor Bugbot for commit 55d25a1. Bugbot is set up for automated code reviews on this repo. Configure here.

@nattb8 nattb8 requested review from a team as code owners May 8, 2026 02:25

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment

Comment thread src/Packages/Audience/Runtime/Unity/AudienceUnityHooks.cs

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c38a3ef. Configure here.

Comment thread examples/audience/Assets/Plugins/Android/mainTemplate.gradle Outdated
Comment thread src/Packages/Audience/Runtime/Unity/Mobile/AttributionContext.cs
@nattb8 nattb8 force-pushed the feat/sdk-309-android-gaid branch 2 times, most recently from d8f5d30 to b2fd9d3 Compare May 8, 2026 02:42

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment

Comment thread src/Packages/Audience/Runtime/Unity/Mobile/GAIDBridge.cs Outdated
Capture the Google Advertising ID and limitAdTracking flag via JNI to
AdvertisingIdClient. Ships on game_launch when AUDIENCE_MOBILE_ATTRIBUTION
is defined, EnableMobileAttribution is on, and the studio has added
play-services-ads-identifier to their gradle dependencies. Async fetch
runs on a dedicated worker thread; first launch ships nothing, launch #2
onwards ships the previously cached value.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@nattb8 nattb8 force-pushed the feat/sdk-309-android-gaid branch from b2fd9d3 to 55d25a1 Compare May 8, 2026 02:53
@nattb8 nattb8 merged commit 396c324 into main May 8, 2026
57 of 58 checks passed
@nattb8 nattb8 deleted the feat/sdk-309-android-gaid branch May 8, 2026 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants