Skip to content

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

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

Analytics rewrite: generic provider SPI with GDPR consent and multiple backends#5266
shai-almog wants to merge 7 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.27% (8700/60961 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 11.55% (42824/370749), branch 5.11% (1783/34881), complexity 6.11% (2041/33424), method 10.56% (1650/15620), class 17.20% (379/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.27% (8700/60961 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 11.55% (42824/370749), branch 5.11% (1783/34881), complexity 6.11% (2041/33424), method 10.56% (1650/15620), class 17.20% (379/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 165ms / native 231ms = 0.7x speedup
SIMD float-mul (64K x300) java 196ms / native 135ms = 1.4x 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 222.000 ms
Base64 CN1 decode 233.000 ms
Base64 native encode 779.000 ms
Base64 encode ratio (CN1/native) 0.285x (71.5% faster)
Base64 native decode 851.000 ms
Base64 decode ratio (CN1/native) 0.274x (72.6% 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 129 screenshots: 129 matched.
✅ Native Mac screenshot tests passed.

Benchmark Results

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

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 84ms / native 12ms = 7.0x speedup
SIMD float-mul (64K x300) java 49ms / native 2ms = 24.5x 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 269.000 ms
Base64 CN1 decode 190.000 ms
Base64 native encode 508.000 ms
Base64 encode ratio (CN1/native) 0.530x (47.0% faster)
Base64 native decode 264.000 ms
Base64 decode ratio (CN1/native) 0.720x (28.0% faster)
Base64 SIMD encode 56.000 ms
Base64 encode ratio (SIMD/CN1) 0.208x (79.2% faster)
Base64 SIMD decode 47.000 ms
Base64 decode ratio (SIMD/CN1) 0.247x (75.3% faster)
Base64 encode ratio (SIMD/native) 0.110x (89.0% faster)
Base64 decode ratio (SIMD/native) 0.178x (82.2% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 17.000 ms
Image createMask (SIMD on) 1.000 ms
Image createMask ratio (SIMD on/off) 0.059x (94.1% faster)
Image applyMask (SIMD off) 61.000 ms
Image applyMask (SIMD on) 40.000 ms
Image applyMask ratio (SIMD on/off) 0.656x (34.4% faster)
Image modifyAlpha (SIMD off) 57.000 ms
Image modifyAlpha (SIMD on) 42.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.737x (26.3% faster)
Image modifyAlpha removeColor (SIMD off) 70.000 ms
Image modifyAlpha removeColor (SIMD on) 42.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.600x (40.0% 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 129 screenshots: 129 matched.
✅ Native iOS Metal screenshot tests passed.

Benchmark Results

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

Build and Run Timing

Metric Duration
Simulator Boot 73000 ms
Simulator Boot (Run) 1000 ms
App Install 16000 ms
App Launch 17000 ms
Test Execution 264000 ms

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 126ms / native 3ms = 42.0x speedup
SIMD float-mul (64K x300) java 182ms / native 2ms = 91.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 923.000 ms
Base64 CN1 decode 317.000 ms
Base64 native encode 980.000 ms
Base64 encode ratio (CN1/native) 0.942x (5.8% faster)
Base64 native decode 274.000 ms
Base64 decode ratio (CN1/native) 1.157x (15.7% slower)
Base64 SIMD encode 55.000 ms
Base64 encode ratio (SIMD/CN1) 0.060x (94.0% faster)
Base64 SIMD decode 105.000 ms
Base64 decode ratio (SIMD/CN1) 0.331x (66.9% faster)
Base64 encode ratio (SIMD/native) 0.056x (94.4% faster)
Base64 decode ratio (SIMD/native) 0.383x (61.7% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 21.000 ms
Image createMask (SIMD on) 1.000 ms
Image createMask ratio (SIMD on/off) 0.048x (95.2% faster)
Image applyMask (SIMD off) 56.000 ms
Image applyMask (SIMD on) 49.000 ms
Image applyMask ratio (SIMD on/off) 0.875x (12.5% faster)
Image modifyAlpha (SIMD off) 93.000 ms
Image modifyAlpha (SIMD on) 41.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.441x (55.9% faster)
Image modifyAlpha removeColor (SIMD off) 95.000 ms
Image modifyAlpha removeColor (SIMD on) 105.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 1.105x (10.5% slower)

@shai-almog

shai-almog commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator Author

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

Benchmark Results

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

Build and Run Timing

Metric Duration
Simulator Boot 62000 ms
Simulator Boot (Run) 1000 ms
App Install 16000 ms
App Launch 12000 ms
Test Execution 354000 ms

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 86ms / native 4ms = 21.5x speedup
SIMD float-mul (64K x300) java 70ms / native 2ms = 35.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 370.000 ms
Base64 CN1 decode 300.000 ms
Base64 native encode 971.000 ms
Base64 encode ratio (CN1/native) 0.381x (61.9% faster)
Base64 native decode 463.000 ms
Base64 decode ratio (CN1/native) 0.648x (35.2% faster)
Base64 SIMD encode 67.000 ms
Base64 encode ratio (SIMD/CN1) 0.181x (81.9% faster)
Base64 SIMD decode 100.000 ms
Base64 decode ratio (SIMD/CN1) 0.333x (66.7% faster)
Base64 encode ratio (SIMD/native) 0.069x (93.1% faster)
Base64 decode ratio (SIMD/native) 0.216x (78.4% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 36.000 ms
Image createMask (SIMD on) 27.000 ms
Image createMask ratio (SIMD on/off) 0.750x (25.0% faster)
Image applyMask (SIMD off) 83.000 ms
Image applyMask (SIMD on) 116.000 ms
Image applyMask ratio (SIMD on/off) 1.398x (39.8% slower)
Image modifyAlpha (SIMD off) 113.000 ms
Image modifyAlpha (SIMD on) 39.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.345x (65.5% faster)
Image modifyAlpha removeColor (SIMD off) 121.000 ms
Image modifyAlpha removeColor (SIMD on) 62.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.512x (48.8% 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
shai-almog and others added 2 commits June 21, 2026 07:55
The CodenameOneAnalyticsProvider batch now carries a per-run sessionId and
device segmentation fields (deviceModel, deviceManufacturer, formFactor,
density, screenWidth/Height, network, language) so the cloud console can do
Google-Analytics-style segmentation, sessions and screen-flow without any
hardware identifier. Values are read defensively; the model is the public
hardware string, never the user-assigned device name.

Ports expose a privacy-safe hardware model via a new DeviceHardwareModel
property: iOS adds native getDeviceHardwareModel() (sysctlbyname hw.machine,
with a simulator fallback) -- distinct from getDeviceName() which returns the
PII device name; Android maps it to Build.MODEL and adds DeviceManufacturer
(Build.MANUFACTURER).

Adds provider tests for the enriched wire format and stable per-run session id.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…nted Purchase/share

- Analytics.setDimension/clearDimension/getDimensions: app-defined custom
  segmentation dimensions, persisted via Preferences and sent in the batch as
  a dimensions{} object. Plus browser (coarse label from User-Agent on web)
  and osName in the batch.
- Analytics.autoEvent(): consent-gated, no-op when no providers, never throws.
  Purchase.postReceipt emits 'purchase'(commerce, sku); Display.share emits
  'share'(engagement, type) -- goals can bind to these out of the box.
- Tests for dimensions round-trip/persistence, batch dimensions+browser, and
  autoEvent fan-out/no-op.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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