Skip to content

Analytics rewrite: generic provider SPI with GDPR consent and multiple backends#5266

Open
shai-almog wants to merge 5 commits into
masterfrom
analytics-spi-rewrite
Open

Analytics rewrite: generic provider SPI with GDPR consent and multiple backends#5266
shai-almog wants to merge 5 commits into
masterfrom
analytics-spi-rewrite

Conversation

@shai-almog

Copy link
Copy Markdown
Collaborator

Summary

Replaces the deprecated Google Analytics v1 AnalyticsService with a generic provider SPI. Apps register one or more AnalyticsProvider implementations with the Analytics facade, which fans screen / event / setUserProperty / crash calls out to all providers — but only after a configurable, opt-in-by-default consent gate.

Client (com.codename1.analytics)

  • Analytics facade + AnalyticsProvider SPI (AbstractAnalyticsProvider base), AnalyticsEvent, AnalyticsConsent, ConsentMode, AnalyticsContext, AnalyticsCrashReport, AnalyticsCapability.
  • GDPR/CCPA: granular consent persisted across restarts; pseudonymous, user-resettable client id (resetClientId()); no hardware identifiers.
  • Providers: CodenameOneAnalyticsProvider (first-party, batched to the cloud), GoogleAnalyticsProvider (GA4 Measurement Protocol), MatomoAnalyticsProvider (privacy-first, non-Google), FirebaseAnalyticsProvider, LoggingAnalyticsProvider.
  • The old AnalyticsService is retained, deprecated, and delegates to the new API (its init switches the facade to opt-out to preserve historical behaviour). UIBuilder analytics hook unchanged.

Firebase native + builders

  • Android peer (NativeFirebaseAnalyticsImpl) via reflection (mirrors the port's FCM pattern); iOS peer as an Objective-C class (com_codename1_analytics_NativeFirebaseAnalyticsImpl) using dynamic dispatch on FIRAnalytics.
  • AndroidGradleBuilder / IPhoneBuilder inject the Firebase Gradle dep / Firebase/Analytics pod, gated on the android.firebaseAnalytics / ios.firebaseAnalytics build hints (mirrors the existing FCM/AdMob handling).

Docs + tests

  • New docs/developer-guide/Analytics.asciidoc chapter (old section replaced with a pointer); passes asciidoctor + Vale + paragraph-cap locally.
  • 25 unit tests in maven/core-unittests (consent gating, all providers, client id, capabilities, deprecated facade) — all green against a from-source core build.

Verification

  • Client tests: mvn -o -pl core-unittests -DunitTests=true -Plocal-dev-javase test -Dtest='*Analytics*' → 25/25 pass.
  • iOS native peer: full local xcodebuild -sdk iphoneos -arch arm64 of a sample app → BUILD SUCCEEDED, peer object compiled and linked.
  • Builders + plugin compile cleanly.

The BuildCloud backend (ingest, tier-gated reports, console UI) and the BuildDaemon builder twin are in separate PRs on those repos.

🤖 Generated with Claude Code

…e backends

Replace the deprecated Google Analytics v1 AnalyticsService with a generic
provider SPI. Apps register one or more AnalyticsProvider implementations with
the Analytics facade, which fans screen / event / user-property / crash calls
out to all providers after a configurable (opt-in by default) consent gate.

Providers: CodenameOneAnalyticsProvider (first-party, batched to the cloud),
GoogleAnalyticsProvider (GA4), MatomoAnalyticsProvider (privacy-first, non
Google), FirebaseAnalyticsProvider (Android + iOS native peers), and
LoggingAnalyticsProvider (simulator / tests).

The old AnalyticsService is retained, deprecated, and now delegates to the new
API. Adds GDPR features (granular consent persisted across restarts,
pseudonymous user-resettable client id), Firebase build-hint dependency
injection in the Android (android.firebaseAnalytics) and iOS
(ios.firebaseAnalytics) builders, a new developer-guide Analytics chapter, and
25 unit tests. The iOS native peer was verified with a full local arm64
xcodebuild (BUILD SUCCEEDED).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Developer Guide build artifacts are available for download from this workflow run:

Developer Guide quality checks:

  • AsciiDoc linter: No issues found (report)
  • Vale: No alerts found (report)
  • Paragraph capitalization: No paragraph capitalization issues (report)
  • LanguageTool: No grammar matches (report)
  • Image references: No unused images detected (report)

@shai-almog

shai-almog commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 129 screenshots: 129 matched.

Native Android coverage

  • 📊 Line coverage: 14.25% (8687/60957 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 11.54% (42778/370723), branch 5.10% (1780/34877), complexity 6.11% (2041/33422), method 10.56% (1649/15620), class 17.15% (378/2204)
    • Lowest covered classes
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysKt – 0.00% (0/6327 lines covered)
      • kotlin.collections.unsigned.kotlin.collections.unsigned.UArraysKt___UArraysKt – 0.00% (0/2384 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.ClassReader – 0.00% (0/1519 lines covered)
      • kotlin.collections.kotlin.collections.CollectionsKt___CollectionsKt – 0.00% (0/1148 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.MethodWriter – 0.00% (0/923 lines covered)
      • kotlin.sequences.kotlin.sequences.SequencesKt___SequencesKt – 0.00% (0/730 lines covered)
      • kotlin.text.kotlin.text.StringsKt___StringsKt – 0.00% (0/623 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.Frame – 0.00% (0/564 lines covered)
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysJvmKt – 0.00% (0/495 lines covered)
      • kotlinx.coroutines.kotlinx.coroutines.JobSupport – 0.00% (0/423 lines covered)

✅ Native Android screenshot tests passed.

Native Android coverage

  • 📊 Line coverage: 14.25% (8687/60957 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 11.54% (42778/370723), branch 5.10% (1780/34877), complexity 6.11% (2041/33422), method 10.56% (1649/15620), class 17.15% (378/2204)
    • Lowest covered classes
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysKt – 0.00% (0/6327 lines covered)
      • kotlin.collections.unsigned.kotlin.collections.unsigned.UArraysKt___UArraysKt – 0.00% (0/2384 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.ClassReader – 0.00% (0/1519 lines covered)
      • kotlin.collections.kotlin.collections.CollectionsKt___CollectionsKt – 0.00% (0/1148 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.MethodWriter – 0.00% (0/923 lines covered)
      • kotlin.sequences.kotlin.sequences.SequencesKt___SequencesKt – 0.00% (0/730 lines covered)
      • kotlin.text.kotlin.text.StringsKt___StringsKt – 0.00% (0/623 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.Frame – 0.00% (0/564 lines covered)
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysJvmKt – 0.00% (0/495 lines covered)
      • kotlinx.coroutines.kotlinx.coroutines.JobSupport – 0.00% (0/423 lines covered)

Benchmark Results

Detailed Performance Metrics

Metric Duration
SIMD kernel backend scalar fallback (no native SIMD)
SIMD int-add (64K x300) java 196ms / native 70ms = 2.8x speedup
SIMD float-mul (64K x300) java 112ms / native 89ms = 1.2x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path gated to scalar (CPU autovectorizes scalar; explicit SIMD not beneficial here)
Base64 CN1 encode 413.000 ms
Base64 CN1 decode 239.000 ms
Base64 native encode 882.000 ms
Base64 encode ratio (CN1/native) 0.468x (53.2% faster)
Base64 native decode 781.000 ms
Base64 decode ratio (CN1/native) 0.306x (69.4% faster)
Image encode benchmark status skipped (SIMD unsupported)

@shai-almog

shai-almog commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 122 screenshots: 122 matched.
✅ JavaScript-port screenshot tests passed.

@shai-almog

shai-almog commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 128 screenshots: 128 matched.
✅ Native Mac screenshot tests passed.

Benchmark Results

  • VM Translation Time: 0 seconds
  • Compilation Time: 120 seconds

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 85ms / native 10ms = 8.5x speedup
SIMD float-mul (64K x300) java 50ms / native 2ms = 25.0x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path active (NEON-accelerated)
Base64 CN1 encode 260.000 ms
Base64 CN1 decode 174.000 ms
Base64 native encode 583.000 ms
Base64 encode ratio (CN1/native) 0.446x (55.4% faster)
Base64 native decode 288.000 ms
Base64 decode ratio (CN1/native) 0.604x (39.6% faster)
Base64 SIMD encode 50.000 ms
Base64 encode ratio (SIMD/CN1) 0.192x (80.8% faster)
Base64 SIMD decode 46.000 ms
Base64 decode ratio (SIMD/CN1) 0.264x (73.6% faster)
Base64 encode ratio (SIMD/native) 0.086x (91.4% faster)
Base64 decode ratio (SIMD/native) 0.160x (84.0% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 20.000 ms
Image createMask (SIMD on) 2.000 ms
Image createMask ratio (SIMD on/off) 0.100x (90.0% faster)
Image applyMask (SIMD off) 63.000 ms
Image applyMask (SIMD on) 48.000 ms
Image applyMask ratio (SIMD on/off) 0.762x (23.8% faster)
Image modifyAlpha (SIMD off) 65.000 ms
Image modifyAlpha (SIMD on) 39.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.600x (40.0% faster)
Image modifyAlpha removeColor (SIMD off) 67.000 ms
Image modifyAlpha removeColor (SIMD on) 38.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.567x (43.3% faster)

@github-actions

Copy link
Copy Markdown
Contributor

Cloudflare Preview

@shai-almog

shai-almog commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 210 screenshots: 210 matched.
✅ Native Apple Watch (watchOS, Core Graphics) screenshot tests passed.

@shai-almog

shai-almog commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 128 screenshots: 128 matched.
✅ Native iOS Metal screenshot tests passed.

Benchmark Results

  • VM Translation Time: 0 seconds
  • Compilation Time: 253 seconds

Build and Run Timing

Metric Duration
Simulator Boot 69000 ms
Simulator Boot (Run) 1000 ms
App Install 11000 ms
App Launch 5000 ms
Test Execution 285000 ms

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 156ms / native 3ms = 52.0x speedup
SIMD float-mul (64K x300) java 335ms / native 3ms = 111.6x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path active (NEON-accelerated)
Base64 CN1 encode 586.000 ms
Base64 CN1 decode 227.000 ms
Base64 native encode 1099.000 ms
Base64 encode ratio (CN1/native) 0.533x (46.7% faster)
Base64 native decode 357.000 ms
Base64 decode ratio (CN1/native) 0.636x (36.4% faster)
Base64 SIMD encode 65.000 ms
Base64 encode ratio (SIMD/CN1) 0.111x (88.9% faster)
Base64 SIMD decode 125.000 ms
Base64 decode ratio (SIMD/CN1) 0.551x (44.9% faster)
Base64 encode ratio (SIMD/native) 0.059x (94.1% faster)
Base64 decode ratio (SIMD/native) 0.350x (65.0% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 26.000 ms
Image createMask (SIMD on) 5.000 ms
Image createMask ratio (SIMD on/off) 0.192x (80.8% faster)
Image applyMask (SIMD off) 115.000 ms
Image applyMask (SIMD on) 33.000 ms
Image applyMask ratio (SIMD on/off) 0.287x (71.3% faster)
Image modifyAlpha (SIMD off) 70.000 ms
Image modifyAlpha (SIMD on) 48.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.686x (31.4% faster)
Image modifyAlpha removeColor (SIMD off) 104.000 ms
Image modifyAlpha removeColor (SIMD on) 105.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 1.010x (1.0% slower)

@shai-almog

shai-almog commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 124 screenshots: 124 matched.
✅ Native iOS screenshot tests passed.

Benchmark Results

  • VM Translation Time: 0 seconds
  • Compilation Time: 216 seconds

Build and Run Timing

Metric Duration
Simulator Boot 67000 ms
Simulator Boot (Run) 1000 ms
App Install 11000 ms
App Launch 5000 ms
Test Execution 287000 ms

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 58ms / native 2ms = 29.0x speedup
SIMD float-mul (64K x300) java 77ms / native 3ms = 25.6x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path active (NEON-accelerated)
Base64 CN1 encode 697.000 ms
Base64 CN1 decode 301.000 ms
Base64 native encode 697.000 ms
Base64 encode ratio (CN1/native) 1.000x (0.0% slower)
Base64 native decode 383.000 ms
Base64 decode ratio (CN1/native) 0.786x (21.4% faster)
Base64 SIMD encode 118.000 ms
Base64 encode ratio (SIMD/CN1) 0.169x (83.1% faster)
Base64 SIMD decode 81.000 ms
Base64 decode ratio (SIMD/CN1) 0.269x (73.1% faster)
Base64 encode ratio (SIMD/native) 0.169x (83.1% faster)
Base64 decode ratio (SIMD/native) 0.211x (78.9% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 18.000 ms
Image createMask (SIMD on) 2.000 ms
Image createMask ratio (SIMD on/off) 0.111x (88.9% faster)
Image applyMask (SIMD off) 57.000 ms
Image applyMask (SIMD on) 44.000 ms
Image applyMask ratio (SIMD on/off) 0.772x (22.8% faster)
Image modifyAlpha (SIMD off) 92.000 ms
Image modifyAlpha (SIMD on) 58.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.630x (37.0% faster)
Image modifyAlpha removeColor (SIMD off) 52.000 ms
Image modifyAlpha removeColor (SIMD on) 33.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.635x (36.5% faster)

shai-almog and others added 3 commits June 20, 2026 17:43
The CN1 core (CodenameOne/src) compiles against the CLDC11 bootclasspath,
whose StringBuilder has no substring(int,int). Convert to String first in
GoogleAnalyticsProvider.sanitizeName so the core/CLDC11 build compiles.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The deprecated AnalyticsService now delegates to Analytics, leaving domain /
timeout / readTimeout written but never read -- SpotBugs failed the JDK 8 gate
on URF_UNREAD_FIELD. Remove the fields; the setters become documented no-ops
and the init domain parameter is retained for source compatibility only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Make Analytics final (ClassWithOnlyPrivateConstructorsShouldBeFinal) and drop
the redundant public modifiers on NativeFirebaseAnalytics interface methods
(UnnecessaryModifier). Verified against the full forbidden PMD rule set via
mvn verify -- zero forbidden violations across the analytics sources.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

✅ Continuous Quality Report

Test & Coverage

Static Analysis

  • SpotBugs [Report archive]
    • ByteCodeTranslator: 0 findings (no issues)
    • android: 0 findings (no issues)
    • codenameone-maven-plugin: 0 findings (no issues)
    • core-unittests: 0 findings (no issues)
    • ios: 0 findings (no issues)
  • PMD: 0 findings (no issues) [Report archive]
  • Checkstyle: 0 findings (no issues) [Report archive]

Generated automatically by the PR CI workflow.

CI LanguageTool (rendered-HTML gate, not runnable locally) flagged British
spellings 'behavioural'/'anonymisation' and the proper noun 'Piwik'. Switch to
US spelling (behavioral/anonymization, plus honor) and accept-list Piwik.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shai-almog shai-almog force-pushed the analytics-spi-rewrite branch from f4a7d53 to 2422a15 Compare June 20, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant