Track app data in Google Analytics

If you are using Google Tag Manager (GTM) on your website, check our Google Analytics with Google Tag Manager guide instead.

Tracking the performance of your app is key to make sure your goals are achieved, in this guide you will learn how to adjust your website Google Analytics integration to allow you to track your app separately from your website.

Configure Google Analytics Tracking Code

Your existing Google Analytics tracking code should look like this:


    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', 'G-XXXXXXXXX');

We will add a few lines of code that will add an extra user property to users who view your website through the MobiLoud app.

Here is the code that you will need to add:


	var isApp = navigator.userAgent.toLowerCase().indexOf('canvas') > -1;
    if(isApp) {
      gtag('set', {'app_session': 'true'})
    } else {
      gtag('set', {'app_session': 'false'})
    }

Your final Google Analytics tracking code will look like this after the changes:


      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-XXXXXXXXX');
			var isApp = navigator.userAgent.toLowerCase().indexOf('canvas') > -1;
      if(isApp) {
        gtag('set', {'app_session': 'true'})
      } else {
        gtag('set', {'app_session': 'false'})
      }

That's it for the first part, now let's jump into your Google Analytics Dashboard.

Create a Custom Dimension

Under your Google Analytics Dashboard you will need to create a custom dimension.

Click the "Gear" icon located on the bottom left area of your screen:

Click "Custom definitions" in the "Property" column:

Click the "Create custom dimension" button:

Fill the details as follows:

  • Dimension name: app_session
  • Scope: user
  • Description: Determines if the user is viewing the website on the browser or through the app
  • User property: app_session

Save your custom dimension, and you are done!

You Need to Wait

Once you have created the custom dimension you will need to wait until a few users have opened your app, and for the data to be processed by Google Analytics, which usually takes 24 hours at least.

To clarify, you will not be able to see segment your users immediately, you will need to wait 24 hours before doing so.

Thank you! We'll be in touch within 48 hours :)
Oops! Something went wrong while submitting the form.
Preview My App
Preview My App