App / Screen tracking

This guide describes how to use screen tracking with gtag.js.

Overview

Screens in Google Analytics represent content users are viewing within an app. The equivalent concept for a website is pages. Measuring screen views allows you to see which content is being viewed most by your users, and how are they navigating between different pieces of the content.

Implementation

To send a screen view to Google Analytics, use the following event command to send a screen_view event:

gtag('event', 'screen_view', [parametersObject]);

Screen fields

Field name Data type Required Description
screen_name string yes The name of the screen.

Screen data is typically sent to Google Analytics views of type "app" (rather than "web"), which means in addition to sending the screen_name, you must also send at least the app_name field.

The following table lists the app parameters that can be sent to app views:

Field name Data type Required Description
app_name string Yes The name of the application.
app_id string No The ID of the application.
app_version string No The application version.
app_installer_id string No The ID of the application installer.

For more details on the distinction between web and app views in Google Analytics, refer to the Difference between web and app views article in the Google Analytics Help Center.

Examples

The following command sends a screenview event to Google Analytics for an app named myAppName and the screen Home:

gtag('event', 'screen_view', {
  'app_name': 'myAppName',
  'screen_name': 'Home'
});

Because the app_name parameter must be sent with all app events, it's often best to add the parameter using the existing config command for the property you are sending data to.

gtag('config', 'GA_TRACKING_ID', { 'app_name': 'myAppName' });

// The app_name field is now set for the property, so
// screen_view events don't need to include it.
gtag('event', 'screen_view', { 'screen_name': 'Home'});

For more details, examples, and best practices for sending hits, see the Sending data to Google Analytics guide.

Using filters for app-only or web-only views

If you send web and app data to the same property (GA_TRACKING_ID), Google Analytics will display both sets of data in views for that property. This allows for combined app and web views.

If you want to send app and web data for the same property but maintain a separate app and/or web view you can create Filters. For example, you can have a combined view (default), a web view, and an app view.

App view filter

Create a Custom Filter to Include only app data by setting Application? to yes.

The Google Analytics create filter form. The filter name field is set to 'App View', 'Custom Filter' type is selected, 'Include' is selected, Filter Field dropdown is set to 'Application?', Filter Pattern is set to 'yes', and Case Sensitive is set to 'No'.
Figure 1: Filter settings for an App View.

Web view filter

Create a Custom Filter to Include only web data by setting Application? to no.

The Google Analytics create filter form. The filter name field is set to 'Web View', 'Custom Filter' type is selected, 'Include' is selected, Filter Field dropdown is set to 'Application?', Filter Pattern is set to 'no', and Case Sensitive is set to 'No'.
Figure 2: Filter settings for a Web View.