diff --git a/CHANGELOG.md b/CHANGELOG.md index 59631b6..9c7c756 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Alle nennenswerten Änderungen an diesem Projekt. Format nach - (app) HUD blieb auf dem Initialwert (100 HP), weil `onLoad` waehrend des ersten Builds publizierte ### Added +- (ads) UMP-Consent-Flow vor SDK-Init, Fail-Safe ohne Zustimmung, Einstellungen-Sheet mit „Datenschutz-Optionen“ - (ads) AdMob App ID im Manifest, `google_mobile_ads`, `AdsService` mit Rewarded/Interstitial und Frequenz-Caps - (ui) Rewarded-Testbutton; Interstitial nach Matchende (ab Match 4, jeder 2.) - (build) Release-Skript mit ABI-abhängigem Alignment-Check, native-debug-symbols.zip, AAB diff --git a/app/lib/main.dart b/app/lib/main.dart index c3bd41c..4acdde1 100644 --- a/app/lib/main.dart +++ b/app/lib/main.dart @@ -1,4 +1,5 @@ import 'package:flame/game.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -117,7 +118,52 @@ class _MatchScreenState extends State { _toast('Replay läuft'); } + /// Settings sheet: privacy options (UMP requirement) and ad status. + void _openSettings() { + showModalBottomSheet( + context: context, + backgroundColor: const Color(0xFF0B1220), + builder: (sheetContext) => SafeArea( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + ListTile( + leading: const Icon(Icons.privacy_tip_outlined), + title: const Text('Datenschutz-Optionen'), + subtitle: Text(_ads.consentLabel), + onTap: () async { + Navigator.pop(sheetContext); + await _ads.showPrivacyOptions(); + if (mounted) _toast('Consent: ${_ads.consentLabel}'); + }, + ), + ListTile( + leading: const Icon(Icons.campaign_outlined), + title: const Text('Werbe-Status'), + subtitle: Text(_ads.statusLabel), + ), + if (kDebugMode) + ListTile( + leading: const Icon(Icons.restart_alt), + title: const Text('Consent zuruecksetzen (Debug)'), + onTap: () async { + Navigator.pop(sheetContext); + await _ads.resetConsent(); + if (mounted) _toast('Consent zurueckgesetzt - App neu starten'); + }, + ), + const SizedBox(height: 8), + ], + ), + ), + ); + } + Future _showRewardedAd() async { + if (!_ads.isAdsAllowed) { + _toast('Anzeigen erst nach Zustimmung'); + return; + } final reward = await _ads.showRewarded(); if (!mounted) return; _toast(reward == null ? 'Keine Anzeige verfügbar' : 'Belohnung: +$reward'); @@ -163,7 +209,8 @@ class _MatchScreenState extends State { const SizedBox(height: 6), AnimatedBuilder( animation: _session, - builder: (context, _) => StatusBar(session: _session), + builder: (context, _) => + StatusBar(session: _session, onSettings: _openSettings), ), ], ), diff --git a/app/lib/src/ads/ads_service.dart b/app/lib/src/ads/ads_service.dart index bdbebb7..3731d68 100644 --- a/app/lib/src/ads/ads_service.dart +++ b/app/lib/src/ads/ads_service.dart @@ -1,14 +1,13 @@ +import 'dart:async'; + import 'package:flutter/foundation.dart'; import 'package:google_mobile_ads/google_mobile_ads.dart'; -/// AdMob integration. +/// AdMob integration with UMP consent. /// -/// The **application id** lives in `AndroidManifest.xml` -/// (`ca-app-pub-3909261635234286~8769927442`). -/// -/// Until real ad units exist, Google's official **test units** are used on -/// purpose: showing live ads during development produces invalid traffic and can -/// get the AdMob account suspended. +/// Order matters (Google policy): consent is gathered **before** the Mobile Ads +/// SDK is initialised and before any ad request. Without consent, no ads are +/// requested at all — the UI simply reports "not available". class AdsService { /// Official Google test unit for rewarded video. static const String rewardedUnitId = @@ -18,6 +17,9 @@ class AdsService { static const String interstitialUnitId = 'ca-app-pub-3940256099942544/1033173712'; + /// Hashed id of the test device (MD5 of the Android ID, upper case). + static const String _testDeviceHashedId = '8FE2A5A74DC63E67AB86EE55E600589C'; + /// Never show an interstitial during the first matches (retention). static const int skipFirstMatches = 3; @@ -26,23 +28,128 @@ class AdsService { RewardedAd? _rewarded; InterstitialAd? _interstitial; - bool _initialized = false; + bool _started = false; + bool _adsAllowed = false; int _matchesFinished = 0; - bool get isInitialized => _initialized; - bool get isRewardedReady => _rewarded != null; - int get matchesFinished => _matchesFinished; + ConsentStatus _consentStatus = ConsentStatus.unknown; + bool _privacyOptionsRequired = false; - /// Initialises the SDK once and preloads both formats. + bool get isInitialized => _started; + bool get isRewardedReady => _rewarded != null; + bool get isAdsAllowed => _adsAllowed; + int get matchesFinished => _matchesFinished; + bool get privacyOptionsRequired => _privacyOptionsRequired; + + String get consentLabel => switch (_consentStatus) { + ConsentStatus.obtained => 'Zustimmung erteilt', + ConsentStatus.required => 'Zustimmung erforderlich', + ConsentStatus.notRequired => 'Nicht erforderlich', + ConsentStatus.unknown => 'Unbekannt', + }; + + String get statusLabel => + 'Consent: $consentLabel · Ads: ${_adsAllowed ? 'aktiv' : 'inaktiv'}' + ' · Rewarded: ${isRewardedReady ? 'geladen' : 'nicht geladen'}'; + + /// Gathers consent, then initialises the SDK only if ads may be requested. Future initialize() async { - if (_initialized) return; + if (_started) return; + _started = true; + + await _gatherConsent(); + + _adsAllowed = await ConsentInformation.instance.canRequestAds(); + if (!_adsAllowed) { + debugPrint('ads: no consent - SDK stays idle'); + return; + } + await MobileAds.instance.initialize(); - _initialized = true; debugPrint('ads: SDK initialised'); _loadRewarded(); _loadInterstitial(); } + Future _gatherConsent() async { + final params = ConsentRequestParameters( + consentDebugSettings: kDebugMode + ? ConsentDebugSettings( + debugGeography: DebugGeography.debugGeographyEea, + testIdentifiers: const [_testDeviceHashedId], + ) + : null, + ); + + final done = Completer(); + ConsentInformation.instance.requestConsentInfoUpdate( + params, + () async { + try { + if (await ConsentInformation.instance.isConsentFormAvailable()) { + await ConsentForm.loadAndShowConsentFormIfRequired( + (FormError? error) { + if (error != null) { + debugPrint('ads: consent form dismissed with error ${error.message}'); + } else { + debugPrint('ads: consent form handled'); + } + }, + ); + } else { + debugPrint('ads: no consent form available'); + } + } catch (error) { + debugPrint('ads: consent form error $error'); + } finally { + if (!done.isCompleted) done.complete(); + } + }, + (error) { + debugPrint('ads: consent update failed (${error.errorCode}) ${error.message}'); + if (!done.isCompleted) done.complete(); + }, + ); + await done.future; + + _consentStatus = await ConsentInformation.instance.getConsentStatus(); + _privacyOptionsRequired = + (await ConsentInformation.instance.getPrivacyOptionsRequirementStatus()) == + PrivacyOptionsRequirementStatus.required; + debugPrint( + 'ads: consent=$_consentStatus privacyOptionsRequired=$_privacyOptionsRequired', + ); + } + + /// Shows the UMP privacy options ("Datenschutz-Optionen") if required. + Future showPrivacyOptions() async { + try { + await ConsentForm.showPrivacyOptionsForm((FormError? error) { + if (error != null) { + debugPrint('ads: privacy options error ${error.message}'); + } + }); + _consentStatus = await ConsentInformation.instance.getConsentStatus(); + _adsAllowed = await ConsentInformation.instance.canRequestAds(); + debugPrint('ads: privacy options closed, consent=$_consentStatus'); + if (_adsAllowed && _rewarded == null) _loadRewarded(); + } catch (error) { + debugPrint('ads: privacy options error $error'); + } + } + + /// Debug helper: forgets the stored consent and re-runs the flow next start. + Future resetConsent() async { + await ConsentInformation.instance.reset(); + _consentStatus = ConsentStatus.unknown; + _adsAllowed = false; + _rewarded?.dispose(); + _rewarded = null; + _interstitial?.dispose(); + _interstitial = null; + debugPrint('ads: consent reset'); + } + void _loadRewarded() { RewardedAd.load( adUnitId: rewardedUnitId, @@ -80,6 +187,7 @@ class AdsService { /// Shows a rewarded video and returns the granted amount, or null if none was /// available (the caller must not grant a reward in that case). Future showRewarded() async { + if (!_adsAllowed) return null; final ad = _rewarded; if (ad == null) { _loadRewarded(); @@ -107,6 +215,7 @@ class AdsService { /// Called when a match ends; applies the frequency caps from the GDD. void onMatchFinished() { + if (!_adsAllowed) return; _matchesFinished++; if (_matchesFinished <= skipFirstMatches) return; if (_matchesFinished % everyNthMatch != 0) return; diff --git a/app/lib/src/ui/widgets.dart b/app/lib/src/ui/widgets.dart index 865e398..5b2fd52 100644 --- a/app/lib/src/ui/widgets.dart +++ b/app/lib/src/ui/widgets.dart @@ -53,9 +53,10 @@ class Hud extends StatelessWidget { /// Connection state and pending-replay counter. class StatusBar extends StatelessWidget { - const StatusBar({super.key, required this.session}); + const StatusBar({super.key, required this.session, required this.onSettings}); final MatchSession session; + final VoidCallback onSettings; @override Widget build(BuildContext context) { @@ -82,6 +83,15 @@ class StatusBar extends StatelessWidget { const SizedBox(width: 8), Text('· ${session.queued} pending', style: const TextStyle(fontSize: 11, color: Color(0xFFFFC107))), + const SizedBox(width: 4), + InkWell( + onTap: onSettings, + borderRadius: BorderRadius.circular(12), + child: const Padding( + padding: EdgeInsets.all(4), + child: Icon(Icons.tune, size: 16, color: Color(0xFF90A4AE)), + ), + ), ], ], ); diff --git a/docs/compliance-play-store.md b/docs/compliance-play-store.md index dca6e4b..0000d7b 100644 --- a/docs/compliance-play-store.md +++ b/docs/compliance-play-store.md @@ -110,3 +110,6 @@ Ein Release ist **nicht** erlaubt, wenn einer dieser Punkte offen ist: 3. Keine `native-debug-symbols.zip` im Upload. 4. Data-Safety-Formular unvollständig. 5. Account-Löschung nicht implementiert. +6. **Keine Datenschutz-Nachricht in AdMob konfiguriert** (UMP liefert dann `unknown` und + `canRequestAds()==true` → Werbung ohne Einwilligung in der EU). Nachweis: `ads: consent update failed (3)` + im Logcat, solange die Nachricht fehlt. Schritt-für-Schritt in [monetization.md](monetization.md#7b-ump-consent-m7b-umgesetzt). diff --git a/docs/monetization.md b/docs/monetization.md index 959f4dc..bc69c45 100644 --- a/docs/monetization.md +++ b/docs/monetization.md @@ -111,8 +111,36 @@ Jeder Test: mind. 7 Tage, eine Variable, Entscheidung nach ARPDAU **und** D7 (ni | Rewarded | Test-Button im UI, Belohnung wird quittiert | | **Offen** | echte Ad-Unit-IDs, **UMP-Consent (Pflicht vor Live-Ads in der EU)**, „Remove Ads"-IAP | -**Wichtig:** Live-Ads dürfen erst nach dem UMP-Consent-Flow (TCF v2.2) ausgeliefert werden. -Bis dahin bleiben die Test-Units aktiv; sie erzeugen keinen Invalid Traffic. +## 7b. UMP-Consent (M7b, umgesetzt) + +| Punkt | Umsetzung | +|---|---| +| Ablauf | `requestConsentInfoUpdate` → `loadAndShowConsentFormIfRequired` → **erst danach** `MobileAds.initialize()` | +| Gate | Ohne `canRequestAds() == true` werden **keine** Ads geladen (fail-safe) | +| Einstiegspunkt | Zahnrad in der Statusleiste → „Datenschutz-Optionen“ (`showPrivacyOptionsForm`) | +| Debug | `ConsentDebugSettings` mit EEA-Geografie + Testgerät `8FE2A5A74DC63E67AB86EE55E600589C` | +| Statusanzeige | „Consent: … · Ads: aktiv/inaktiv · Rewarded: geladen“ | + +### Ergebnis des Gerätetests (2026-10-24) + +``` +ads: consent update failed (3) Publisher misconfiguration: no form(s) configured + for the input app ID ca-app-pub-3909261635234286~8769927442 +ads: consent=ConsentStatus.unknown privacyOptionsRequired=false +ads: SDK initialised +``` + +**Das ist erwartet:** Im AdMob-Konto ist noch **keine Datenschutz-Nachricht** angelegt. Ohne sie +liefert UMP `unknown` und `canRequestAds()` gibt `true` zurück – die App würde in der EU also +**ohne Einwilligung** werben. Deshalb ist das ein harter Release-Blocker: + +1. AdMob → **Privacy & messaging** → **GDPR** → *Create message* (Deutsch + Englisch) +2. Nachricht der App `Iron Arc` zuordnen, Zielregionen EEA/UK/CH +3. **Consent Management Platform**: Google (UMP) als CMP bestätigen +4. App neu starten → Formular erscheint auf EEA-Testgeräten, `consent=obtained`, danach erst Ads + +**Wichtig:** Bis das erledigt ist, bleiben Test-Units aktiv (kein Invalid Traffic) und es gehen +keine echten Anzeigen live. ## 8. Offene Punkte