This guide describes how to use screen tracking with analytics.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 are navigating between different pieces of content.
Implementation
Screen hits can be sent using the send command and specifying a hitType of screenview. The send command has the following signature for the screenview hit type:
ga('send', 'screenview', [fieldsObject]);
Screen fields
| Field Name | Value Type | Required | Description |
|---|---|---|---|
screenName |
text | 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 screenName, you must also send at least the appName field.
The following table lists the app fields that can be sent to app views.
| Field Name | Value Type | Required | Description |
|---|---|---|---|
appName |
text | yes | The name of the application. |
appId |
text | no | The Id of the application. |
appVersion |
text | no | The application version. |
appInstallerId |
text | 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 Analytics Help Center.
Examples
The following command sends a screenview hit to Google Analytics for an app named "myAppName" and the screen "Home":
ga('send', 'screenview', {
'appName': 'myAppName',
'screenName': 'Home'
});
Since the appName field must be sent with all app hits, it's often best to set that field on the tracker itself using the set command:
ga('create', 'UA-XXXXX-Y', 'auto');
ga('set', 'appName', 'myAppName');
// The `appName` field is now set on the tracker, so
// screenview hits don't need to include it.
ga('send', 'screenview', {screenName: 'Home'});
Using filters for app-only or web-only views
If you send web and app data for the same property (UA-XXXXX-Y), 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.
Web view filter
Create a Custom Filter to Include only web data by setting Application? to no.
