-
Notifications
You must be signed in to change notification settings - Fork 29
Using Google Analytics
A. Follow the "Before you Begin" section of the Getting Started guide to setup your environment.
- Go to https://developers.google.com/analytics/devguides/collection/android/v4/
- Install the Google Play Services SDK if you haven't already, located at: https://developer.android.com/google/play-services/setup.html
- Be sure to create a Google Analytics property: https://support.google.com/analytics/answer/1042508
- Remember your Tracking ID generated in the previous step which is needed for the app to setup correctly the trackers.
- Be sure to create a view to send the data from the App and view the reports: https://support.google.com/analytics/answer/1009714
B. Get the latest release of ABaker
- Download the latest development version of ABaker: https://github.com/bakerframework/baker-android
- Open the project in Android Studio.
C. Modify the Google Analytics configuration to your needs.
The first thing you need to do is to specify the tracking ID in the "res/xml/global_tracker.xml". Use the "ga_trackingId" to set the tracking ID obtained when you created the property in Google Analytics.
The basic configuration is located at "res/values/ga_settings.xml". This file allows you to enable Google Analytics in general or different events independently such as registering Issue Download events.
The properties specified in the file are:
ga_enable
Allows you to enable/disable the Google Analytics in general. No event will be registered.
ga_register_app_open_event
Enable to register and event when the application is opened.
ga_register_issue_download_event
Enable to register the event when an issue is downloaded.
ga_register_issue_read_event
Enable to register an event when an issue is opened and viewed.
ga_register_issue_delete_event
Enable to register an event when an issue is deleted.
ga_register_page_view_event
Enable to register the event when a particular page is viewed. This property needs the page to contain a "meta" tag with the name attribute "baker-page-name" in the head of the HTML, such as:
<meta name="baker-page-name" content="this is my page name" />
If the "content" attribute is not specified, the name of the HTML file will be used, such as "page001.html".
ga_register_page_view_time_elapsed_event
Enable to register the page view event only when a certain time has elapsed. See the "ga_page_view_time_elapsed" property. If this property is true, besides registering the event, a User Timing Event is also registered with the amount of time the user took viewing the page.
ga_page_view_time_elapsed
Specify the time in milliseconds that must elapse in order to register the page view event. This is useful if you want to register those events when the user views a particular page after a certain amount of time.
Additionally, there are strings properties in "res/values/strings.xml" that work along Google Analytics to manage the events in categories and labels. You can use the values you want for any of these. The properties are:
issues_category
Category to enclose those events related to the issues, such as Issue Download, Delete or Opened. You may also want to include a "meta" tag to your page with a different value here, for example:
<meta name="baker-page-category" content="page_category_name" />
This is useful if you want to separate different pages in different categories, such as "Restaurants Pages" or "Pets Pages".
issue_open
Name of the action that the user triggered when the issue was opened.
issue_download
Name of the action that the user triggered when the issue was downloaded.
issue_delete
Name of the action that the user triggered when the issue was deleted.
issue_page_view
Name of the action that the user triggered when the issue was viewed.
Also, you have the possibility to configure your own tracker and/or implement your own functions for sending Analytics and events by adding the configurations in the "res/xml/" directory. Check the "Create a configuration XML file" section of the Getting Started Guide for the appropriate settings available in Google Analytics.
After that you will need to create your own class extending the Application class, such as the one included in ABaker in "src/main/java/com/baker/abaker/ABakerApp" to create a getTracker(String)
method where you must return a Tracker depending on the name passed as parameter. Check the "Initialize Trackers" section of the Google Analytics Getting Started Guide.
Besides, to make it simple, you might want to implement the AnalyticsEvents interface so you can access the sendEvent()
and sendTimingEvent()
methods. You must define your code implementation for sending the data in those methods.
This is useful if you want to use a different library for analytics instead of Google Analytics.
When you have your Application class defined, you must specify it on the "AndroidManifest.xml" file in order for Android to load the class and initialize the trackers.