Courtesy: GitHub

Google Analytics Quickstart

Google Analytics Android Quickstart app demonstrates collecting app usage analytics via Tracker available in Google Play Services. HitBuilders.ScreenViewBuilder is used to send screen view analytics.

Introduction

Getting Started

  • Follow the quickstart guide to set up your project in Android Studio.
    • Make sure to replace ga_trackingId in res/xml/global_tracker.xml with your Google Analytics tracking ID.
  • Run the sample on your Android device or emulator.
  • Swipe between images to register screen views.
  • View collected analytics via Google Analytics.

Screenshots

Screenshot

Support

If you've found an error in this sample, please file an issue: https://github.com/googlesamples/google-services/issues

Patches are encouraged, and may be submitted by forking this project and submitting a pull request through GitHub.

License

Copyright 2015 Google, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

compileSdkVersion 25

applicationId "com.google.samples.quickstart.analytics"

minSdkVersion 14

targetSdkVersion 25

versionCode 1

versionName "1.0"

compile 'com.android.support:appcompat-v7:25.3.1'

compile 'com.android.support:design:25.3.1'

compile 'com.android.support:support-v4:25.3.1'

compile 'com.google.android.gms:play-services-analytics:11.6.0'

package com.google.samples.quickstart.analytics

uses-permission

  • android.permission.INTERNET
  • android.permission.ACCESS_NETWORK_STATE

application .AnalyticsApplication

MainActivity

Activity which displays numerous background images that may be viewed. These background images are shown via {@link ImageFragment}.

The {@link android.support.v4.view.PagerAdapter} that will provide fragments for each image. This uses a {@link FragmentPagerAdapter}, which keeps every loaded fragment in memory.

The {@link ViewPager} that will host the patterns.

The {@link Tracker} used to record screen views.

Return the title of the currently displayed image. @return title of image

Record a screen view hit for the visible {@link ImageFragment} displayed inside {@link FragmentPagerAdapter}.

Check to make sure global_tracker.xml was configured correctly (this function only needed for sample apps).

A {@link FragmentPagerAdapter} that returns a fragment corresponding to one of the sections/tabs/pages.