Skip to main content
When your website runs inside a Median-built native app, it behaves differently than it does in a standard browser. Detecting whether a user is on the native app or a browser lets you:
  • Enable JavaScript Bridge commands (which are only available inside the app)
  • Customize your UI and UX (for example, hiding a website nav bar in favor of a native navigation menu, or hiding a footer to create a cleaner app interface)
  • Track analytics separately for app vs. browser sessions
  • Restrict which pages or features are accessible within the app
Median supports three detection strategies. Use whichever best suits your architecture, or combine them.

Detection strategies

Strategy 1: Detect the custom user agent

Every HTTP request made by your Median app appends a custom string to the device’s default user agent. This is the most common detection method and works on both the frontend and backend.

Default user-agent strings

You can change this string in the Web Overrides tab. See Custom user agent for details, and confirm the configured user agent using the device info function in your live app. Detecting the user agent: frontend (JavaScript) Use navigator.userAgent to check for the median string on the client side.
Detecting the user agent: backend (for example, Node.js) You can read the User-Agent header on the server to serve different content or responses based on context.
This pattern works in any server-side language. Look for the median string in the User-Agent HTTP header.

JavaScript helper functions

We recommend creating helper functions to simplify complex integrations and to reduce the code that needs to be added throughout your web environment. In the examples below, you call logAnalyticsEvent() and the event would be transmitted as either a web analytics event or app analytics event by way of the helper function. Analytics using the Google Firebase Analytics plugin for native app analytics:
Analytics using only web-based Google Analytics, with an additional parameter to filter web versus app events:

Strategy 2: Set custom HTTP headers

Instead of (or in addition to) user-agent detection, you can configure your app to send a custom HTTP header with every request. This can be a cleaner signal than parsing the user-agent string, especially on the backend. Configure custom headers in App Studio under Web Overrides → Custom Headers.
Custom Headers settings under Web Overrides in App Studio

Web Overrides → Custom Headers

Example: adding an X-App-Platform: median-ios header on the iOS app, then reading it server-side:
See Custom headers for full configuration details.

Strategy 3: Use a dedicated app URL

The simplest approach is to serve a completely separate version of your site at a dedicated subdomain configured as your app’s URL: https://app.yoursite.com Because only your Median app points to this URL, any request to it is by definition from the app. No user-agent parsing or header inspection is required. This strategy works well when the app and browser experiences differ significantly. It is recommended when the app version omits marketing pages, sign-up flows, or navigation elements that only make sense in a browser context.

Choosing a strategy

For most projects, user-agent detection in JavaScript is the quickest starting point. Add a helper function early so detection logic stays centralized as your codebase grows.
Last modified on November 7, 2026