Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungWhy Claude Code keeps writing shell commands that fail on your Mac(20.09.2026 um 21:06 Uhr)
Sichere Programmierungllms.txt v2: What the Spec Says, and What 137,000 Domains Show(20.09.2026 um 21:17 Uhr)
Sicherheitslücken (CVE)NiceTryGPT: Less pattern matching. More actual hacking.(20.09.2026 um 21:19 Uhr)
IT Security VideoActivities BoF (kde2026)(20.09.2026 um 00:00 Uhr)
IT Security Toolsirdoc-app(20.09.2026 um 20:33 Uhr)
Sichere ProgrammierungWhy Claude Code keeps writing shell commands that fail on your Mac(20.09.2026 um 21:06 Uhr)
Sichere Programmierungllms.txt v2: What the Spec Says, and What 137,000 Domains Show(20.09.2026 um 21:17 Uhr)
Sicherheitslücken (CVE)NiceTryGPT: Less pattern matching. More actual hacking.(20.09.2026 um 21:19 Uhr)
IT Security VideoActivities BoF (kde2026)(20.09.2026 um 00:00 Uhr)
IT Security Toolsirdoc-app(20.09.2026 um 20:33 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Bridging the Gap: Unified Google Analytics for Web and Capacitor Apps

Reagiere als Erste:r — dein Feedback zählt!

Developers building hybrid applications with Capacitor often face a split-brain problem when it comes to user tracking: web applications rely on standard Google Analytics (GA4) and Google Tag Manager (GTM), while native iOS and Android applications require Firebase Analytics. To solve this fragmented tracking experience, developer Arpad Kish (@arpad1337) created analytics-web-capacitor, an open-source extension designed to unify Google Analytics across both Web and Capacitor application environments.

Here is a deep dive into how this elegant solution works under the hood.

The Core Architecture

At the heart of the extension is the analytics.ts file, which exports an Analytics class that requires both an Analytics ID and a Tag Manager ID for initialization. When loadAnalytics() is called, the script determines if the app is running in a standard web browser or within a native Capacitor environment by checking if the window.location.origin includes ://app-symbol.

Because native webviews often place strict limitations on standard script tag injections, the tool bypasses this by fetching gtm.js and tracking.js directly via XMLHttpRequest. Once successfully fetched, the tracking scripts are executed using eval() to ensure they load reliably regardless of the Capacitor routing scheme.

Intercepting the Data Layer

To make standard web tracking code work natively, the extension relies on a clever TypeScript implementation called DataLayerArray.

  • Extending the Standard Array: DataLayerArray extends the native JavaScript Array and overrides the push method.
  • Global Assignment: The global window.dataLayer is then replaced with this custom DataLayerArray.
  • Standard Compatibility: window.gtag commands are mapped to simply push their arguments into this array, maintaining complete compatibility with typical web implementations.

Bridging Web Events to Native Firebase

For Capacitor apps running on native devices, the extension bridges web events to native Firebase Analytics using @capacitor-community/firebase-analytics.

It accomplishes this via the setFirebaseBridgedTrackingProxy method, which acts as a middleware for the dataLayer. Whenever an event is pushed to the dataLayer, the proxy intercepts it, appends native OS data via Capacitor.getPlatform(), and programmatically forwards the event and its parameters to FirebaseAnalytics.logEvent(). This allows developers to write web-based tracking code once and trust that it will automatically translate to native SDK calls on iOS and Android.

Handling Single Page Application (SPA) Routing

Single Page Applications often break standard pageview tracking because the browser doesn't undergo a full page refresh. analytics-web-capacitor handles this natively via the setGTMHistoryChangeEventProxy method.

  • History Change Listener: The proxy watches the data layer for Google Tag Manager's gtm.historyChange-v2 events.
  • Virtual URLs: Upon detecting a route change, it strips protocols to calculate the new and old "virtual" paths.
  • Manual Page Views: It then automatically triggers a custom page_view event containing the virtual_page_location and virtual_page_referrer parameters.

Usage and Availability

By integrating this setup, developers can rely on standard, unified tracking syntax throughout their application:

  window['gtag']('event', 'custom_event', {
    page_title: document.title,
    page_location: document.location.href,
    virtual_page_location: path,
    ...
  });

The analytics-web-capacitor software is provided "AS IS" and is freely available under the MIT License, copyrighted by Arpad K. in 2025.

https://github.com/arpad1337/analytics-web-capacitor

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Bridging the Gap: Unified Google Analytics for Web and Capacitor Apps

Thematisch verwandte Begriffe: Bridging, Unified, Google, Analytics · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-93956 | A flaw has been found in olivier-ls PHP-FTS up to 1.1.2. Affected by thi…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick