Index: project.properties
===================================================================
--- project.properties (revision 9)
+++ project.properties (working copy)
@@ -1,12 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system use,
-# "ant.properties", and override values to adapt the script to your
-# project structure.
-
-# Project target.
-target=android-3
-android.library=true
Index: AndroidManifest.xml
===================================================================
--- AndroidManifest.xml (revision 9)
+++ AndroidManifest.xml (working copy)
@@ -1,9 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
Index: src/com/google/android/apps/analytics/easytracking/TrackedListActivity.java
===================================================================
--- src/com/google/android/apps/analytics/easytracking/TrackedListActivity.java (revision 9)
+++ src/com/google/android/apps/analytics/easytracking/TrackedListActivity.java (working copy)
@@ -1,84 +0,0 @@
-// Copyright 2011 Google Inc. All Rights Reserved.
-//
-// Licensed 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.
-
-package com.google.android.apps.analytics.easytracking;
-
-import android.app.ListActivity;
-import android.os.Bundle;
-
-/**
- * Extend this class instead of ListActivity to enable Google Analytics Tracking
- * for a ListActivity. Note that for accurate application-level tracking,
- * all Activities in an application must either extend one of the
- * TrackedActivity classes (i.e. TrackedActivity, TrackedListActivity) or
- * implement the calls found in this class. This is necessary as the
- * EasyTracking library maintains a count of active Activities in order to
- * determine when a session starts and ends and relies on the fact that a new
- * Activity's onStart method is called before the old Activity's onStop method
- * is called.
- *
- * The one exception to this flow is when an Activity is being restarted because
- * of a configuration change (i.e. orientation change) where the
- * onRetainNonConfigurationInstance method is called after the Activity's onStop
- * method is called and before the new Activity's onStart is called.
- *
- * See the file ReadMe.txt for details on setting up tracking using the
- * EasyTracker library.
- */
-public class TrackedListActivity extends ListActivity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Only one call to setContext is needed, but additional calls don't hurt
- // anything, so we'll always make the call to ensure EasyTracker gets
- // setup properly.
- EasyTracker.getTracker().setContext(this);
- }
-
- @Override
- public void onStart() {
- super.onStart();
-
- // This call will ensure that the Activity in question is tracked properly,
- // based on the setting of ga_auto_activity_tracking parameter. It will
- // also ensure that startNewSession is called appropriately.
- EasyTracker.getTracker().trackActivityStart(this);
- }
-
- /**
- * This method is deprecated in Android 3.0 (Honeycomb) and later, but
- * GoogleAnalytics support goes back to Android 1.5 and therefore cannot use
- * the Fragment API.
- */
- @Override
- public Object onRetainNonConfigurationInstance() {
- Object o = super.onRetainNonConfigurationInstance();
-
- // This call is needed to ensure that configuration changes (like
- // orientation) don't result in new sessions. Remove this line if you want
- // configuration changes to for a new session in Google Analytics.
- EasyTracker.getTracker().trackActivityRetainNonConfigurationInstance();
- return o;
- }
-
- @Override
- public void onStop() {
- super.onStop();
-
- // This call is needed to ensure time spent in an Activity and an
- // Application are measured accurately.
- EasyTracker.getTracker().trackActivityStop(this);
- }
-}
Index: src/com/google/android/apps/analytics/easytracking/ParameterLoader.java
===================================================================
--- src/com/google/android/apps/analytics/easytracking/ParameterLoader.java (revision 9)
+++ src/com/google/android/apps/analytics/easytracking/ParameterLoader.java (working copy)
@@ -1,50 +0,0 @@
-// Copyright 2011 Google Inc. All Rights Reserved.
-//
-// Licensed 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.
-
-package com.google.android.apps.analytics.easytracking;
-
-
-/**
- * Interface for loading parameters used by the EasyTracker library.
- */
-interface ParameterLoader {
-
- /**
- * Look up the string value for the resource whose name is key.
- *
- * @param key the key for the string resource we're seeking
- * @return the string value, or null if not found
- */
- String getString(String key);
-
- /**
- * Look up the boolean value represented by the string resource whose name is
- * key.
- *
- * @param key the key for the string resource we're seeking
- * @return true if the key is found and is a string 'true'. Case is ignored.
- */
- boolean getBoolean(String key);
-
- /**
- * Look up the integer value represented by the string resource whose name is
- * key.
- *
- * @param key the key for the string resource we're seeking
- * @param defaultValue the value to return if the key isn't found
- * @return the int value found, or the defaultValue if the key wasn't found
- * or couldn't be parsed into an int.
- */
- int getInt(String key, int defaultValue);
-}
Index: src/com/google/android/apps/analytics/easytracking/ParameterLoaderImpl.java
===================================================================
--- src/com/google/android/apps/analytics/easytracking/ParameterLoaderImpl.java (revision 9)
+++ src/com/google/android/apps/analytics/easytracking/ParameterLoaderImpl.java (working copy)
@@ -1,87 +0,0 @@
-// Copyright 2011 Google Inc. All Rights Reserved.
-//
-// Licensed 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.
-
-package com.google.android.apps.analytics.easytracking;
-
-import android.content.Context;
-import android.util.Log;
-
-/**
- * This class implements the ParameterLoader interface by loading parameters
- * from the Application's resources.
- */
-public class ParameterLoaderImpl implements ParameterLoader {
-
- private final Context ctx;
-
- public ParameterLoaderImpl(Context ctx) {
- if (ctx == null) {
- throw new NullPointerException("Context cannot be null");
- }
- this.ctx = ctx;
- }
-
- /**
- * Look up the resource id for the given type in the package identified by
- * gaContext. The lookup is done by key instead of id as presence of these
- * parameters are optional. Some or all may not be present. If gaContext is
- * null, return 0.
- *
- * @param key the key for the string resource we're seeking
- * @param type the type (string, bool or integer)
- * @return resource id of the given string resource, or 0 if not found
- */
- private int getResourceIdForType(String key, String type) {
- if (ctx == null) {
- return 0;
- }
- return ctx.getResources().getIdentifier(key, type, ctx.getPackageName());
- }
-
- @Override
- public String getString(String key) {
- int id = getResourceIdForType(key, "string");
- if (id == 0) {
- return null;
- } else {
- return ctx.getString(id);
- }
- }
-
- @Override
- public boolean getBoolean(String key) {
- int id = getResourceIdForType(key, "bool");
- if (id == 0) {
- return false;
- } else {
- return "true".equalsIgnoreCase(ctx.getString(id));
- }
- }
-
- @Override
- public int getInt(String key, int defaultValue) {
- int id = getResourceIdForType(key, "integer");
- if (id == 0) {
- return defaultValue;
- } else {
- try {
- return Integer.parseInt(ctx.getString(id));
- } catch (NumberFormatException e) {
- Log.w(EasyTracker.LOG_TAG, "NumberFormatException parsing " + ctx.getString(id));
- return defaultValue;
- }
- }
- }
-
-}
Index: src/com/google/android/apps/analytics/easytracking/TrackedActivity.java
===================================================================
--- src/com/google/android/apps/analytics/easytracking/TrackedActivity.java (revision 9)
+++ src/com/google/android/apps/analytics/easytracking/TrackedActivity.java (working copy)
@@ -1,84 +0,0 @@
-// Copyright 2011 Google Inc. All Rights Reserved.
-//
-// Licensed 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.
-
-package com.google.android.apps.analytics.easytracking;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-/**
- * Extend this class instead of Activity to enable Google Analytics Tracking for
- * an Activity. Note that for accurate application-level tracking,
- * all Activities in an application must either extend one of the
- * TrackedActivity classes (i.e. TrackedActivity, TrackedListActivity) or
- * implement the calls found in this class. This is necessary as the
- * EasyTracking library maintains a count of active Activities in order to
- * determine when a session starts and ends and relies on the fact that a new
- * Activity's onStart method is called before the old Activity's onStop method
- * is called.
- *
- * The one exception to this flow is when an Activity is being restarted because
- * of a configuration change (i.e. orientation change) where the
- * onRetainNonConfigurationInstance method is called after the Activity's onStop
- * method is called and before the new Activity's onStart is called.
- *
- * See the file ReadMe.txt for details on setting up tracking using the
- * EasyTracker library.
- */
-public class TrackedActivity extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Only one call to setContext is needed, but additional calls don't hurt
- // anything, so we'll always make the call to ensure EasyTracker gets
- // setup properly.
- EasyTracker.getTracker().setContext(this);
- }
-
- @Override
- public void onStart() {
- super.onStart();
-
- // This call will ensure that the Activity in question is tracked properly,
- // based on the setting of ga_auto_activity_tracking parameter. It will
- // also ensure that startNewSession is called appropriately.
- EasyTracker.getTracker().trackActivityStart(this);
- }
-
- /**
- * This method is deprecated in Android 3.0 (Honeycomb) and later, but
- * GoogleAnalytics support goes back to Android 1.5 and therefore cannot use
- * the Fragment API.
- */
- @Override
- public Object onRetainNonConfigurationInstance() {
- Object o = super.onRetainNonConfigurationInstance();
-
- // This call is needed to ensure that configuration changes (like
- // orientation) don't result in new sessions. Remove this line if you want
- // configuration changes to for a new session in Google Analytics.
- EasyTracker.getTracker().trackActivityRetainNonConfigurationInstance();
- return o;
- }
-
- @Override
- public void onStop() {
- super.onStop();
-
- // This call is needed to ensure time spent in an Activity and an
- // Application are measured accurately.
- EasyTracker.getTracker().trackActivityStop(this);
- }
-}
\ No newline at end of file
Index: src/com/google/android/apps/analytics/easytracking/GoogleAnalyticsTrackerDelegate.java
===================================================================
--- src/com/google/android/apps/analytics/easytracking/GoogleAnalyticsTrackerDelegate.java (revision 9)
+++ src/com/google/android/apps/analytics/easytracking/GoogleAnalyticsTrackerDelegate.java (working copy)
@@ -1,62 +0,0 @@
-// Copyright 2011 Google Inc. All Rights Reserved.
-//
-// Licensed 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.
-
-package com.google.android.apps.analytics.easytracking;
-
-import com.google.android.apps.analytics.Item;
-import com.google.android.apps.analytics.Transaction;
-
-import android.content.Context;
-
-/**
- * Delegate for GoogleAnalyticsTracker. This interface allows for mocking
- * GoogleAnalyticsTracker. GoogleAnalyticsTracker is a singleton with a
- * private constructor, so cannot be extended. Note that this delegate will
- * only expose those public methods of GoogleAnalyticsTracker that are used
- * by EasyTracker.
- */
-public interface GoogleAnalyticsTrackerDelegate {
-
- public void startNewSession(String accountId, int dispatchPeriod, Context ctx);
-
- public void trackEvent(String category, String action, String label, int value);
-
- public void trackPageView(String pageUrl);
-
- public boolean dispatch();
-
- public void stopSession();
-
- public boolean setCustomVar(int index, String name, String value, int scope);
-
- public boolean setCustomVar(int index, String name, String value);
-
- public void addTransaction(Transaction transaction);
-
- public void addItem(Item item);
-
- public void trackTransactions();
-
- public void clearTransactions();
-
- public void setAnonymizeIp(boolean anonymizeIp);
-
- public void setSampleRate(int sampleRate);
-
- public boolean setReferrer(String referrer);
-
- public void setDebug(boolean debug);
-
- public void setDryRun(boolean dryRun);
-}
Index: src/com/google/android/apps/analytics/easytracking/GoogleAnalyticsTrackerDelegateImpl.java
===================================================================
--- src/com/google/android/apps/analytics/easytracking/GoogleAnalyticsTrackerDelegateImpl.java (revision 9)
+++ src/com/google/android/apps/analytics/easytracking/GoogleAnalyticsTrackerDelegateImpl.java (working copy)
@@ -1,106 +0,0 @@
-// Copyright 2011 Google Inc. All Rights Reserved.
-//
-// Licensed 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.
-
-package com.google.android.apps.analytics.easytracking;
-
-import com.google.android.apps.analytics.GoogleAnalyticsTracker;
-import com.google.android.apps.analytics.Item;
-import com.google.android.apps.analytics.Transaction;
-
-import android.content.Context;
-
-public class GoogleAnalyticsTrackerDelegateImpl implements GoogleAnalyticsTrackerDelegate {
-
- private GoogleAnalyticsTracker tracker = GoogleAnalyticsTracker.getInstance();
-
- @Override
- public void startNewSession(String accountId, int dispatchPeriod, Context ctx) {
- tracker.startNewSession(accountId, dispatchPeriod, ctx);
- }
-
- @Override
- public void trackEvent(String category, String action, String label, int value) {
- tracker.trackEvent(category, action, label, value);
- }
-
- @Override
- public void trackPageView(String pageUrl) {
- tracker.trackPageView(pageUrl);
- }
-
- @Override
- public boolean dispatch() {
- return tracker.dispatch();
- }
-
- @Override
- public void stopSession() {
- tracker.stopSession();
- }
-
- @Override
- public boolean setCustomVar(int index, String name, String value, int scope) {
- return tracker.setCustomVar(index, name, value, scope);
- }
-
- @Override
- public boolean setCustomVar(int index, String name, String value) {
- return tracker.setCustomVar(index, name, value);
- }
-
- @Override
- public void addTransaction(Transaction transaction) {
- tracker.addTransaction(transaction);
- }
-
- @Override
- public void addItem(Item item) {
- tracker.addItem(item);
- }
-
- @Override
- public void trackTransactions() {
- tracker.trackTransactions();
- }
-
- @Override
- public void clearTransactions() {
- tracker.clearTransactions();
- }
-
- @Override
- public void setAnonymizeIp(boolean anonymizeIp) {
- tracker.setAnonymizeIp(anonymizeIp);
- }
-
- @Override
- public void setSampleRate(int sampleRate) {
- tracker.setSampleRate(sampleRate);
- }
-
- @Override
- public boolean setReferrer(String referrer) {
- return tracker.setReferrer(referrer);
- }
-
- @Override
- public void setDebug(boolean debug) {
- tracker.setDebug(debug);
- }
-
- @Override
- public void setDryRun(boolean dryRun) {
- tracker.setDryRun(dryRun);
- }
-}
Index: src/com/google/android/apps/analytics/easytracking/EasyTracker.java
===================================================================
--- src/com/google/android/apps/analytics/easytracking/EasyTracker.java (revision 9)
+++ src/com/google/android/apps/analytics/easytracking/EasyTracker.java (working copy)
@@ -1,550 +0,0 @@
-// Copyright 2011 Google Inc. All Rights Reserved.
-//
-// Licensed 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.
-
-package com.google.android.apps.analytics.easytracking;
-
-import com.google.android.apps.analytics.Item;
-import com.google.android.apps.analytics.Transaction;
-
-import android.app.Activity;
-import android.content.Context;
-import android.util.Log;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.LinkedBlockingQueue;
-
-/**
- * EasyTracker is a class designed to easy the burden of adding tracking code
- * to your application. Simply add this class to your application and extend
- * TrackedActivity instead of Activity for each Activity in your application.
- *
- * This class is designed to be used from a single Thread. Use on the Main UI
- * Thread is acceptable.
- *
- * Note that all of your Activities must extend TrackedActivity (or an
- * equivalent Activity, like TrackedListActivity instead of ListActivity) for
- * this Class to properly track application usage and time. If you have an
- * Activity Class that doesn't extend one provided in this package, you can
- * create one by copying TrackedActivity and having it extend the Activity you
- * want. For example, if you have an Activity subclass called FragmentActivity,
- * simply create a class called TrackedFragmentActivity and have your classes
- * extend that instead of FragmentActivity. The code for
- * TrackedFragmentActivity should be the same as the code in TrackedActivity.
- *
- * You can turn on tracking by providing a String resource of the name
- * ga_api_key with a value of your account id (form UA-12345-6). You can
- * provide various parameters as String, Bool or Integer resources (such as
- * sampleRate) as well. Just use the proper type for the parameter (String for
- * String, Bool for boolean and Integer for int).
- *
- * If you want to track your Activities as well as the application, you can add
- * the Bool resource ga_auto_activity_tracking and give it a value of "true".
- */
-public class EasyTracker {
-
- public static final String LOG_TAG = "EZTracker";
-
- // EasyTracker is a singleton. Don't let other classes create one.
- private EasyTracker() {
- }
-
- private static EasyTracker instance;
-
- public static EasyTracker getTracker() {
- if (instance == null) {
- instance = new EasyTracker();
- }
- return instance;
- }
-
- // If true, tracking is turned on.
- private boolean gaEnabled = false;
-
- // The account id to be used for tracking. It should take the form of
- // 'UA-12345-6'.
- private String gaAccountId;
-
- // The dispatch period, in seconds. A value of 0 will turn off automatic
- // dispatching.
- private int gaDispatchPeriod = 60;
-
- // If true, debug mode will be set in GoogleAnalyticsTracker. This will
- // cause debug messages to be logged in the Android log, viewable with the
- // 'adb logcat' command.
- private boolean gaDebug;
-
- // If true, hits will be generated normally, but will not actually be sent to
- // Google Analytics. Useful for testing tracking code.
- private boolean gaDryRun;
-
- // The sample rate determines what precentage of application installs will
- // actually report to Google Analytics. A value of 100 means that all
- // application installs will report while a value of 0 means none will report.
- private int gaSampleRate = 100;
-
- // If true, the Google Analytics servers will be told to strip off the last
- // octet of the Ip Address of the sender prior to logging the hit.
- private boolean gaAnonymizeIp;
-
- // If true, each Activity will be tracked with a Pageview when the Activity
- // is started (via the trackActivityStart method) and an empty event when the
- // Activity is stopped (via the trackActivityStop method). If false, the
- // Pageview will not be tracked.
- private boolean autoActivityTracking = false;
-
- // The number of Activities that have had their onStart method called but not
- // their corresponding onStop method. This value is used in determining when
- // a new session should be started.
- private int activitiesActive = 0;
-
- // Controls whether the next call to trackActivityStart will start a new
- // session. We always start out needing a new session.
- private boolean sessionNeeded = true;
-
- private Context gaContext;
-
- private Map activityNameMap = new HashMap();
-
- private GoogleAnalyticsTrackerDelegate tracker = null;
-
- private ParameterLoader parameterFetcher;
-
- /**
- * Set the various parameters of the GoogleAnaltyicsTracker instance.
- */
- private void initializeTracker() {
- queueToTrackerThreadIfEnabled(new Runnable() {
- @Override
- public void run() {
- tracker.setDebug(gaDebug);
- tracker.setDryRun(gaDryRun);
- tracker.setSampleRate(gaSampleRate);
- tracker.setAnonymizeIp(gaAnonymizeIp);
- }
- });
- }
-
- /**
- * Lazily get and initialize the GoogleAnalyticsTracker object.
- *
- * @return the GoogleAnalyticsTrackerDelegate object, or null if tracking is
- * disabled
- */
- private GoogleAnalyticsTrackerDelegate getGoogleAnalyticsTracker() {
- if (tracker == null) {
- if (gaEnabled) {
- tracker = new GoogleAnalyticsTrackerDelegateImpl();
- initializeTracker();
- }
- }
- return tracker;
- }
-
- /**
- * For testing only.
- *
- * @param d the delegate class to use
- */
- void setTrackerDelegate(GoogleAnalyticsTrackerDelegate d) {
- if (gaEnabled) {
- tracker = d;
- initializeTracker();
- }
- }
-
- /**
- * For testing only.
- */
- static void clearTracker() {
- instance = null;
- }
-
- /**
- * Load the parameters to be used, starting the trackerThread if necessary.
- */
- private void loadParameters() {
- gaAccountId = parameterFetcher.getString("ga_api_key");
- if (gaAccountId != null) {
- gaEnabled = true;
- gaDebug = parameterFetcher.getBoolean("ga_debug");
- gaDryRun = parameterFetcher.getBoolean("ga_dryRun");
- gaSampleRate = parameterFetcher.getInt("ga_sampleRate", 100);
- gaDispatchPeriod = parameterFetcher.getInt("ga_dispatchPeriod", 20);
- autoActivityTracking =
- parameterFetcher.getBoolean("ga_auto_activity_tracking");
- gaAnonymizeIp = parameterFetcher.getBoolean("ga_anonymizeIp");
- if (trackerThread == null) {
- trackerThread = new TrackerThread();
- trackerThread.start();
- }
- }
- }
-
- /**
- * Sets the context to use to the applicationContext of the Context ctx.
- * If the input is not null, this method will then go on to initialize the
- * EasyTracker Class with parameters from the resource files. If there is
- * an accountId specified, this method will enable Google Analytics tracking
- * and start up the database Thread. If not, it will leave tracking disabled.
- *
- * @param ctx the Context to use to fetch the applicationContext
- */
- public void setContext(Context ctx) {
- if (ctx == null) {
- Log.e(LOG_TAG, "Context cannot be null");
- }
- if (gaContext == null) {
- gaContext = ctx.getApplicationContext();
- parameterFetcher = new ParameterLoaderImpl(gaContext);
- loadParameters();
- }
- }
-
- /**
- * Used in testing to allow injection of a mock ParameterLoader.
- *
- * @param ctx the Context to use to fetch the applicationContext
- * @param parameterLoader the ParamterLoader to use
- */
- void setContext(Context ctx, ParameterLoader parameterLoader) {
- if (ctx == null) {
- Log.e(LOG_TAG, "Context cannot be null");
- }
- if (gaContext == null) {
- gaContext = ctx.getApplicationContext();
- parameterFetcher = parameterLoader;
- loadParameters();
- }
- }
-
- /**
- * Track the start of an Activity, but only if autoActivityTracking is true.
- * This method will start a new session if necessary, and will send an empty
- * event to Google Analytics if autoActivityTracking is false to ensure proper
- * application-level tracking. Developers should not call this method
- * directly. Extend TrackedActivity (or its other cousins) instead of
- * Activity to use this method. Note that this method should be called from
- * the Activity's onStart method.
- *
- * @param activity the Activity that is to be tracked
- */
- public void trackActivityStart(final Activity activity) {
- activitiesActive++;
- final boolean startASession = sessionNeeded;
- sessionNeeded = false;
- queueToTrackerThreadIfEnabled(new Runnable() {
- @Override
- public void run() {
- if (startASession) {
- getGoogleAnalyticsTracker().startNewSession(gaAccountId, gaDispatchPeriod, gaContext);
- if (!autoActivityTracking) {
- // We send an empty event so we get accurate time-on-site info.
- getGoogleAnalyticsTracker().trackEvent("", "", "", 0);
- }
- }
- if (autoActivityTracking) {
- getGoogleAnalyticsTracker().trackPageView(getActivityName(activity));
- }
- }
- });
- }
-
- /**
- * Track Activity restarts due to configuration changes (i.e. orientation
- * change). There is no need to start a new session in this case. Note that
- * this method should be called from the Activity's
- * onRetainNonConfigurationInstance callback.
- *
- * Note that the GoogleAnalytics SDK supports Android versions back to 1.5.
- * The onRetainNonConfigurationInstance method is deprecated in Android 3.0,
- * but its replacement is only supported in Android 2.1 and beyond.
- */
- public void trackActivityRetainNonConfigurationInstance() {
- sessionNeeded = false;
- }
-
- /**
- * Track the end of an Activity and/or application. This is done by sending
- * an empty event to Google Analytics. Note that this method should be called
- * from the Activity's onStop callback.
- *
- * @param activity the Activity that is to be tracked
- */
- public void trackActivityStop(final Activity activity) {
- activitiesActive--;
- sessionNeeded = activitiesActive == 0;
- final boolean sendEvent = sessionNeeded;
- queueToTrackerThreadIfEnabled(new Runnable() {
- @Override
- public void run() {
- if (sendEvent) {
- // We send an empty event so we get accurate time-on-page/site info.
- getGoogleAnalyticsTracker().trackEvent("", "", "", 0);
- }
- }
- });
- }
-
- /**
- * Look up the Activity's display name (as defined in a String resource named
- * for the Activity's canonicalName).
- *
- * @param activity the Activity Class to look up
- * @return the defined display name or the canonicalName if the display name
- * is not found
- */
- private String getActivityName(Activity activity) {
- String canonicalName = activity.getClass().getCanonicalName();
- if (activityNameMap.containsKey(canonicalName)) {
- return activityNameMap.get(canonicalName);
- } else {
- String name = parameterFetcher.getString(canonicalName);
- if (name == null) {
- name = canonicalName;
- }
- activityNameMap.put(canonicalName, name);
- return name;
- }
- }
-
- // The following methods are simple pass-through methods for
- // GoogleAnalyticsTracker with the exception that they all are run on a single
- // Thread created to keep database access off the UI Thread.
-
- /**
- * Adds an Item to the Transaction identified by Item.orderId. A new
- * Transaction will be created if one doesn't already exist. This call will
- * overwrite an existing Item object with the same orderId and itemSKU.
- *
- * @param item the Item to add
- */
- public void addItem(final Item item) {
- queueToTrackerThreadIfEnabled(new Runnable() {
-
- @Override
- public void run() {
- getGoogleAnalyticsTracker().addItem(item);
- }
-
- });
- }
-
- /**
- * Adds a Transaction to be sent to Google Analytics. If a Transaction with
- * the same orderId already exists, it will be replaced with this Transaction.
- *
- * @param transaction the Transaction to add
- */
- public void addTransaction(final Transaction transaction) {
- queueToTrackerThreadIfEnabled(new Runnable() {
-
- @Override
- public void run() {
- getGoogleAnalyticsTracker().addTransaction(transaction);
- }
-
- });
- }
-
- /**
- * Clears all pending Transactions and Items from the internal queue. This
- * method will not affect Transactions and Items already sent with the
- * trackTransactions() call.
- */
- public void clearTransactions() {
- queueToTrackerThreadIfEnabled(new Runnable() {
-
- @Override
- public void run() {
- getGoogleAnalyticsTracker().clearTransactions();
- }
-
- });
- }
-
- /**
- * Dispatch up to 30 queued hits to the Google Analytics servers, but only if
- * another dispatch is not in progress.
- */
- public void dispatch() {
- queueToTrackerThreadIfEnabled(new Runnable() {
-
- @Override
- public void run() {
- getGoogleAnalyticsTracker().dispatch();
- }
-
- });
- }
-
- /**
- * Set the campaign referral to the values in the input. If the input is
- * not valid, the method fails. If the input is valid, the referrer
- * information is changed and a new session is started. Each hit after
- * a successful call to setReferrer will have the referrer information
- * attached.
- *
- * @param referrer the campaign referral information to set
- */
- public void setReferrer(final String referrer) {
- queueToTrackerThreadIfEnabled(new Runnable() {
-
- @Override
- public void run() {
- getGoogleAnalyticsTracker().setReferrer(referrer);
- }
-
- });
- }
-
- /**
- * Start a new session using the parameters stored in the EasyTracker Class.
- * This method flags GoogleAnalyticsTracker to start a new session with the
- * next hit it generates. As such, calling this multiple times in a row will
- * have the same effect of calling it once.
- */
- public void startNewSession() {
- queueToTrackerThreadIfEnabled(new Runnable() {
- @Override
- public void run() {
- // If this gets run, we know that gaAccountId and gaContext are not null
- // as the method queueToDbThreadIfEnabled will check the gaEnabled flag
- // before queuing anything. That flag, in turn is set to true only if
- // gaContext and getAccountId are both non-null.
- getGoogleAnalyticsTracker().startNewSession(gaAccountId, gaDispatchPeriod, gaContext);
- }
- });
- }
-
- /**
- * Stops the automatic dispatch from continuing to run.
- */
- public void stopSession() {
- queueToTrackerThreadIfEnabled(new Runnable() {
- @Override
- public void run() {
- getGoogleAnalyticsTracker().stopSession();
- }
- });
- }
-
- /**
- * Track an Event.
- *
- * @param category the category of the event
- * @param action the action of the event
- * @param label the label of the event, can be null
- * @param value the value of the event
- */
- public void trackEvent(final String category, final String action, final String label,
- final int value) {
- queueToTrackerThreadIfEnabled(new Runnable() {
-
- @Override
- public void run() {
- getGoogleAnalyticsTracker().trackEvent(category, action, label, value);
- }
-
- });
- }
-
- /**
- * Track a pageview, which is analogous to an Activity. If null is passed
- * in as input, no pageview will be tracked.
- *
- * @param name The name of the Activity or view to be tracked.
- */
- public void trackPageView(final String name) {
- queueToTrackerThreadIfEnabled(new Runnable() {
-
- @Override
- public void run() {
- getGoogleAnalyticsTracker().trackPageView(name);
- }
-
- });
- }
-
- /**
- * Sends all the pending Transactions and Items to dispatch. Once this method
- * is called, all the Transactions and Items added previously will not be
- * cleared by a clearTransactions call and will eventually be dispatched to
- * the GoogleAnalytics servers.
- */
- public void trackTransactions() {
- queueToTrackerThreadIfEnabled(new Runnable() {
-
- @Override
- public void run() {
- getGoogleAnalyticsTracker().trackTransactions();
- }
-
- });
- }
-
- // This section defines variables and methods used to manage the Thread for
- // GoogleAnalyticsTracker calls.
-
- private final LinkedBlockingQueue trackerQueue =
- new LinkedBlockingQueue();
-
- private TrackerThread trackerThread;
-
- private Object lock = new Object();
-
- /**
- * Queue the GoogleAnalytics call to the database thread, but only if
- * GoogleAnalytics has been enabled.
- *
- * @param r the Runnable to execute
- */
- private void queueToTrackerThreadIfEnabled(Runnable r) {
- if (gaEnabled) {
- synchronized (lock) {
- trackerQueue.add(r);
- }
- }
- }
-
- /**
- * All Access to GoogleAnalyticsTracker methods are done on this Thread. This
- * is done as GoogleAnalyticsTracker makes database calls which should be done
- * off the Main UI Thread. It's also done in order to preserve the order of
- * those calls.
- */
- private class TrackerThread extends Thread {
-
- TrackerThread() {
- super("TrackerThread");
- }
-
- /**
- * Simply pull Runnables from the Queue trackerQueue and call their run
- * methods, blocking until there is something in the Queue.
- */
- @Override
- public void run() {
- while (true) {
- Runnable r;
- try {
- r = trackerQueue.take();
- r.run();
- } catch (InterruptedException e) {
- Log.i(LOG_TAG, e.toString());
- }
- }
- }
- }
-}
Index: COPYING
===================================================================
--- COPYING (revision 9)
+++ COPYING (working copy)
@@ -1,202 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed 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.
\ No newline at end of file
Index: ReadMe.txt
===================================================================
--- ReadMe.txt (revision 9)
+++ ReadMe.txt (working copy)
@@ -1,42 +0,0 @@
-EasyTracker
-
-Version 1.0
-
-You can use EasyTracker to track application usage using Google Analytics with
-very little effort.
-
-If you got the complete source for this project, simply build this project,
-include it in your application, and extend the TrackedActivity classes provided
-here instead of the standard Activity classes.
-
-If you downloaded the pre-compiled jar, you can skip the build step.
-
-You can control the Google Analytics library through parameters provided as
-resource values. The complete list of parameters are as follows:
-
-ga_api_key (String) - the account ID used for tracking. You need this set for
- EasyTracker to start tracking your application.
-
-ga_debug (Bool) - Set to true if you wish to see debug messages from the
- GoogleAnalytics library in the Android log. Default is false.
-
-ga_dryRun (Bool) - Set to true if you want to test your tracking code without
- actually sending data to Google Analytics. Default is false.
-
-ga_anonymizeIp (Bool) - Set to true to remove the last octet of the device's IP
- Address from tracking data. Default is false.
-
-ga_sampleRate(Integer) - Set to a number between 0 and 100, inclusive. Zero
- will turn off all tracking while 100 will have every
- application instance track. Any number in between will
- limit the number of application instances that actually
- send tracking data to approximately that percentage.
- Default is 100.
-
-ga_dispatchPeriod (Integer) - Set to the time period in seconds to wait between
- dispatches. Setting to zero will turn off
- automatic dispatching. Default is 60.
-
-ga_auto_activity_tracking (Bool) - Set to true to track time spent in each
- Activity. Set to false to track application-
- level information only. Default is false.