ANALYTICS

Tracking Android In-App visits in Google Analytics


David Vallejo
Share

This is going to be a quick post about how to track in-app visits from Android devices.

When an Android App opens a website in a webview ( in-app visit ), the visit usually comes with an special referrer, It does start with "android-app" referrer string, here you can see a log line about how the referrers comes up.

77.XXX.XXX.XXX - - [20/Mar/2020:11:20:10 +0000] "GET /in-app-test HTTP/1.0" 200 1580 "android-app://org.telegram.messenger" "Mozilla/5.0 (Linux; Android 10; GM1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Mobile Safari/537.36"

Since this is a non standard referrer format (it doesn't start with http), we could easily detect these visit with these rules:

  • It doesn't start with "http"
  • It isn't an empty value

Refer to the following trigger for Google Tag Manager:

This will only fire on the landing page ( subsequents pageviews will have a referrer starting with http ),then we'll just have an event per session, We could for example fire a non-interactional event to Google Analytics.


And, then the events will start showing up in the real-time reports,


We could also calculate this within a Custom Variable in Google Tag Manager , and use it to force the visit attribution if needed, since Google Analytics will ignore the non-standard referrers and reports them as Direct Traffic.

function(){
  if (!document.referrer.match(/^http.*/) && !document.referrer.match(/^$/)){
      return document.referrer;
  }  
}

Before someone asks it's not possible to detect the in-app visits from iOS afaik, and this won't help on tagging these apps that open up a link into an standalone browser (like Whatsapp does).

Also I'm not 100% sure that all Android versions/apps will report thing the same way, but it seems to be common on latests android versions and major apps.