Tutorial
Track Android TWA Traffic Separately in GA4
November 7, 2026 · 6 min read
When you convert a Progressive Web App (PWA) into an Android app using a Trusted Web Activity (TWA), the underlying technology shares the user browser state, cookies, and cache with Google Chrome. While this provides a seamless single-sign-on experience for your users, it presents a distinct challenge for web analytics. By default, Google Analytics 4 (GA4) cannot differentiate between a user visiting your website through a standard mobile browser and a user navigating your application through the installed Google Play app.
To make informed product decisions, you must isolate your TWA traffic. Understanding how app users behave compared to standard web visitors helps you measure retention, track conversion rates, and assess the value of your Google Play Store presence. This guide outlines how to configure your TWA, modify your web code, and set up Google Analytics 4 to track your Android app sessions independently.
The Core Challenge of TWA Analytics
Because a Trusted Web Activity runs inside a specialised browser instance, standard browser APIs and user-agent strings remain nearly identical to normal Chrome sessions. Traditional analytics libraries register the platform as web, the browser as Chrome, and the operating system as Android. If you look at your GA4 dashboard without any custom configuration, your TWA users are mixed into your mobile web traffic.
To separate this traffic, you must pass a unique identifier from your native Android wrapper to your web application, capture that identifier in your JavaScript runtime, and forward it to GA4 as a custom dimension or event parameter.
Method 1: Query Parameters via Launch Intent
The most reliable way to identify TWA traffic is to append specific query parameters to the launch URL of your Android application. When your TWA launches, it loads your web app start URL. By modifying this URL in your Android build configuration, you can inject tracking flags directly into the landing page session.
We recommend appending industry-standard Urchin Tracking Module (UTM) parameters to your start URL. This automatically categorises the traffic source in GA4 without requiring custom tag modifications. For example, instead of launching your base URL directly, configure your TWA to launch with query parameters attached:
https://example.com/?utm_source=play_store&utm_medium=twa&utm_campaign=android_app
When a user opens your app, GA4 automatically processes these parameters. It assigns the session source to play_store and the session medium to twa. This allows you to immediately filter reports, build comparison segments, and evaluate user engagement metrics specifically for your app users.
Method 2: Custom User-Agent Suffixes
While query parameters are excellent for marking the entry point of a session, they can sometimes be lost if a user navigates to external authentication providers and returns, or if your web routing logic strips URL parameters. To ensure persistent tracking throughout the entire app experience, you can append a custom suffix to the User-Agent header within your TWA configuration.
By default, the TWA uses the system Chrome User-Agent. However, during the compilation of your Android package, you can configure your Android manifest or build variables to append a custom string such as TWA-Android-App to the end of the browser agent string. Once implemented, the user-agent string seen by your servers and web application will resemble the following:
Mozilla/5.0 (Linux; Android 13; Pixel 6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36 TWA-Android-App
Within your web application, you can execute a simple JavaScript check to detect this suffix and write a flag to your analytics layer. Let us look at a simple implementation:
const isTWA = navigator.userAgent.includes('TWA-Android-App'); if (isTWA) { window.gtag('config', 'G-XXXXXXXXXX', { 'app_platform': 'TWA Android' }); }
Configuring Custom Dimensions in GA4
Once you are passing either a custom query parameter or detecting the custom user-agent suffix, you must tell Google Analytics 4 how to store and report on this data. You do this by creating a Custom Dimension within your Google Play linked GA4 property.
Follow these steps to register your custom dimension:
- Navigate to your Google Analytics 4 property and click on Admin.
- Under the Property settings menu, select Custom definitions and click on Custom dimensions.
- Click the button to Create custom dimensions.
- Set the Dimension name to App Platform.
- Set the Scope to Session or User, depending on how persistently you wish to track the user history.
- Set the User property or Event parameter to app_platform.
- Click Save.
By mapping your custom JavaScript detection to this parameter, GA4 begins populating this dimension for every incoming hit. You can then use the GA4 Explore interface to build custom reports comparing user retention, session duration, and goal completions between web and TWA visitors.
Comparing Tracking Methods
Choosing the correct method depends on your technical constraints and marketing setup. The table below outlines the primary advantages and drawbacks of each approach:
| Method | Implementation Complexity | Persistence | Best For |
|---|---|---|---|
| UTM Query Parameters | Very Low | Medium (can be lost on session reset) | Quick setup, standard acquisition reports |
| User-Agent Suffix | Medium | High (persists across all page loads) | Deep functional testing, persistent segmentation |
| Custom Header injection | High | High | Enterprise-level secure tracking |
Filtering TWA Traffic in GA4 Reports
With your tracking variables configured, you can build dedicated reports to monitor app performance. In your GA4 console, navigate to the Reports section and create a new comparison filter. Set your dimension to App Platform or Session source and define the match criteria to match play_store or your custom user-agent flag.
Using this filtered view, you can check whether your Android app users show higher engagement rates than your standard mobile browser visitors. TWA users typically display higher loyalty and conversion rates because they have committed to installing your brand on their home screen.
Verifying Your Analytics Integration
To verify that your setup functions correctly before shipping your build to Google Play, utilise the GA4 DebugView tool. Install your compiled TWA APK onto a local testing device or emulator connected to your machine.
Launch the application and browse several pages. Open the Google Analytics 4 Realtime report or the DebugView console. Verify that your incoming page views contain your custom campaign variables or the custom app_platform user property. If the custom parameters appear alongside your testing IP address, your configuration is successful and ready for public release.
Ready to build for Android and iOS?
€49.99 once includes unlimited Android APK and AAB plus iOS IPA builds, all from one dashboard.
Build my app