Git Product home page Git Product logo

android-ga-tracker's Introduction

Google Analytics Android Extension

An Android extension that proxies Google Analytics events as Urban Airship custom events. GoogleAnalyticsTracker will generate custom events, including all Google Analytics event fields and a pre-defined subset of Tracker fields, which may then be further customized by implementing an Extender. Any of the non-deprecated HitBuilders event types may be used, where the event type will be set as the custom event name.

Installation

ga-tracker is available through Bintray. To install it, simply add the following lines to your build.gradle:

repositories {
   maven {
      url  "https://urbanairship.bintray.com/android"
   }
}

dependencies {
   compile 'com.urbanairship.android:ga-tracker:1.2.+'
}

Usage

Following the pattern provided in the Google Analytics guide, first create a GoogleAnalyticsTracker instance in your Application class

public class YourApplication extends Application {
  private GoogleAnalyticsTracker uaTracker;

  synchronized public GoogleAnalyticsTracker getDefaultTracker() {
    if (uaTracker == null) {
      // Create a Tracker instance and wrap it in a GoogleAnalyticsTracker instance
      GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
      Tracker tracker = analytics.newTracker(R.xml.global_tracker);
      uaTracker = new GoogleAnalyticsTracker(tracker);

      // The proxy settings can be easily configured to prevent forwarding events to either Urban Airship or Google Analytics.
      // Enable GA tracker (enabled by default)
      uaTracker.setGoogleAnalyticsEnabled(true);

      // Enable UA tracker (enabled by default)
      uaTracker.setUrbanAirshipEnabled(true);

      // Add an Extender to add properties to the generated customEvent
      Extender extender = new Extender() {
          @Override
          public void extend(CustomEvent.Builder builder, Map<String, String> json, GoogleAnalyticsTracker tracker) {
              builder.addProperty("propertyName", "propertyValue");
          }
      };
      uaTracker.addExtender(extender);

    }
    return uaTracker;
  }

In your Activity or Fragment, you can then retrieve the tracker to create events

// Obtain the shared Tracker instance.
AnalyticsApplication application = (AnalyticsApplication) getApplication();
uaTracker = application.getDefaultTracker();

// Create events
uaTracker.setScreenName("HomeScreen");
uaTracker.send(new HitBuilders.ScreenViewBuilder().build());
uaTracker.send(new HitBuilders.EventBuilder().setAction("action").setCategory("category").setLabel("label").setValue(5).build());
uaTracker.send(new HitBuilders.TimingBuilder().setCategory("category").setLabel("label").setValue(5).setVariable("variable").build());
uaTracker.send(new HitBuilders.ExceptionBuilder().setFatal(false).setDescription("description").build());
uaTracker.send(new HitBuilders.SocialBuilder().setTarget("target").setNetwork("network").setAction("action").build());

##Contributing Code

We accept pull requests! If you would like to submit a pull request, please fill out and submit a Code Contribution Agreement (http://docs.urbanairship.com/contribution-agreement.html).

android-ga-tracker's People

Contributors

z0br0wn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.