Track Rich Pages With Google Analytics

While Airship messaging supports tracking of rich page opens out of the box, you can also track opens and clicks within Rich PageA landing page or Message Center message in your app that can include HTML, video, etc. content with a third-party tool like Google Analytics. These directions assume you already have created a Google Analytics account.

See:

Configure Google Analytics

  1. Navigate to the Admin page in Google Analytics.
  2. In the Property column, click + Create property, and name it something like “Airship Rich Pages.”
  3. Set the Default URL to https://device-api.urbanairship.com.
  4. Click Get Tracking ID, then you will see a page displaying the tracking ID.
  5. Note the Tracking ID assigned to this property.

Track Page Opens

To track page opens you need to embed the Google Analytics JavaScript.

If you just completed creating a new property, you will already have this page open, and you can skip to step 4.

  1. Navigate to the Admin page in Google Analytics.
  2. In the Property column, select your property and click Tracking Info then Tracking Code.
  3. Copy the code from the Website tracking section.
  4. Paste the code into every page you want to track. Sample code is below. Make sure to replace YOUR TRACKING ID HERE with your actual tracking ID.
<script>
   (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
   (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
   m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
   })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

   ga('create', 'YOUR TRACKING ID HERE', 'urbanairship.com');
   ga('send', 'pageview');
</script>
 Note

It may take several hours before results appear in Google Analytics.

View Page Opens

Because Airship generates a unique URL for each page per user, you will want to first create a filter so that Google Analytics will roll up your URLs to the page level.

  1. Navigate to the Admin page in Google Analytics.
  2. In the View column, click Filters then + Create Filter.
  3. Set the filter so it looks like this:
  4. Click Save.

The filter converts URLs from this format, with user info embedded:

https://device-api.urbanairship.com/api/user/3BIi_uawQaa8HShcJJxooA/messages/message/iyHEOIqcTq-drAx78p4FYw/body/

To this, which is how message-level URLs will appear in Google Analytics reports:

/api-messages/message/iyHEOIqcTq-drAx78p4FYw/body/
  1. Paste this code into every page you want to track:
    <script>
     function sendLink(choice) {
        ga('send', 'event', 'category', 'action', choice);
        return true;
     }
    </script>
    You can modify the values of ‘category’ and ‘action’ to organize the information in Google Analytics. See Google’s documentation for more information.
  2. Wire up the event to your event, passing a unique ID to the sendLink() method:
    <a onclick="return sendLink('download');" href="http://blah.com/download">Download Now</a>

If you are tracking Link Clicks, you can view the events in the Overview or Content sections of the Google Analytics Realtime report.