AMP Android SDK: Google Analytics Integration

Document created by Jason Gamboa Employee on Jan 6, 2017Last modified by Herberth Alvarado on Apr 9, 2017
Version 5Show Document
  • View in full screen mode

The Google Analytics module is a library that enables the option of tracking the events in the player using the Google Analytics platform. It’s part of the Premier Package of AMP SDK for Android.


  • It reports a variety of events related to playback (start, stop, resume, pause, buffering, etc.)

  •  It offers a set of methods for the customers to report other events when they need it (subtitles enabled or disabled, scrolling events, font and color changes, etc.).



The rest of this guide assumes you have successfully integrated AMP's Core (you are able to play back a video). 


Getting started

To integrate the plugin into your app, you need to:


1) Add the amp-analytics-google-analytics.jar and libGoogleAnalyticsServices.jar to your project's /libs folder.

2) Add the following in the AndroidManifest.xml file:

<!-- Optionally, register AnalyticsReceiver and AnalyticsService to support background dispatching on non-Google Play devices -->
<receiver android:name="" android:enabled="true">

<action android:name="" />

</intent-filter> </receiver>

<service android:name=""android:enabled="true" android:exported="false"/>

<! -- Optionally, register CampaignTrackingReceiver and CampaignTrackingService to enable installation campaign reporting -->

<receiver android:name="" android:exported="true"> <intent-filter>

<action android:name="" /> </intent-filter>

<service android:name="" />


3) Create an instance of a GoogleAnalyticsTracker object in the onResourceReady() callback, and configure it as follows:

GoogleAnalyticsTracker gaTracker = new GoogleAnalyticsTracker();


gaTracker.enableReporting(TRUE | FALSE);


Sidenote: If the playback is started using a configuration file, the TrackingId for the analytics must be added there. The SDK then will know where to obtain the value. But, the TrackingId can also be set manually by using the next Constructor for the Tracker:


GoogleAnalyticsTracker gaTracker = new GoogleAnalyticsTracker (TRACKING_ID);


Methods available

init(Context owner)

Initialize the tracker to send the event. It receives a reference of the Activity Context in which the Module is being implemented.

enableReporting(Boolean enable)

It allows enabling or disabling the action of sending the events for reports.


It reports if the option of sending events is enabled or disabled.


Methods for Manual Reports

These methods send specific events to the Google Analytics platform, but they are not linked to any action inside the SDK. If the customer wants to also track these events, they have to call them manually.


trackTextSizeChanged(int newTextSize)

trackScreenPositionChanges(String newScreenPosition)

trackTextStyleChanges(String newTextStyle)

trackFontChanges(String newFontName)

trackScrollingChanges(String newScrollingType)

trackWindowColorChanges(int newWindowColor)

trackBackgroundColorChanges(int newBackgroundColor)

trackFontColorChanges(int newFontColor)

trackPresentChanges(String newPresentType)


1 person found this helpful