I have a problem with using GoogleAnalytics EasyTracker on Android.
The setup I have made for this question is simple:
- new Android project
- add GA and ET libs
- add GoogleAnalytics.xml:
<resources>
<string name="ga_api_key">UA-2912-1</string>
<bool name="ga_debug">true</bool>
<bool name="ga_dryRun">true</bool>
<bool name="ga_auto_activity_tracking">true</bool>
<integer name="ga_dispatchPeriod">10</integer>
</resources>
extend activity with TrackedActivity instead of Activity:
package test.testing.ez;
import android.os.Bundle;
import com.google.android.apps.analytics.easytracking.TrackedActivity;
public class TestEZActivity extends TrackedActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
At the end, after running my simple application on emulator or device, something like this appears in my LogCat after switching orientation twice.
02-11 14:39:27.245: I/GoogleAnalyticsTracker(219): Host: www.google-analytics.com
02-11 14:39:27.245: I/GoogleAnalyticsTracker(219): User-Agent: GoogleAnalytics/1.4.2 (Linux; U; Android 2.1-update1; en-us; sdk Build/ECLAIR)
02-11 14:39:27.245: I/GoogleAnalyticsTracker(219): GET /__utm.gif?utmwv=4.8.1ma&utmn=1604828210&utmt=event&utme=5(**)(0)&utmcs=UTF-8&utmsr=480x320&utmul=en-US&utmac=UA-2912-1&utmcc=__utma%3D1.659024508.1328970962.1328970962.1328971039.2%3B&utmht=1328971157185&utmqt=10064 HTTP/1.1
02-11 14:39:27.294: I/GoogleAnalyticsTracker(219): Host: www.google-analytics.com
02-11 14:39:27.294: I/GoogleAnalyticsTracker(219): User-Agent: GoogleAnalytics/1.4.2 (Linux; U; Android 2.1-update1; en-us; sdk Build/ECLAIR)
02-11 14:39:27.294: I/GoogleAnalyticsTracker(219): GET /__utm.gif?utmwv=4.8.1ma&utmn=1061578751&utmt=event&utme=5(**)(0)&utmcs=UTF-8&utmsr=480x320&utmul=en-US&utmac=UA-2912-1&utmcc=__utma%3D1.659024508.1328970962.1328970962.1328971039.2%3B&utmht=1328971161689&utmqt=5611 HTTP/1.1
02-11 14:39:27.314: I/GoogleAnalyticsTracker(219): Host: www.google-analytics.com
02-11 14:39:27.314: I/GoogleAnalyticsTracker(219): User-Agent: GoogleAnalytics/1.4.2 (Linux; U; Android 2.1-update1; en-us; sdk Build/ECLAIR)
02-11 14:39:27.314: I/GoogleAnalyticsTracker(219): GET /__utm.gif?utmwv=4.8.1ma&utmn=1061578751&utmt=event&utme=5(**)(0)&utmcs=UTF-8&utmsr=480x320&utmul=en-US&utmac=UA-2912-1&utmcc=__utma%3D1.659024508.1328970962.1328970962.1328971039.2%3B&utmht=1328971161689&utmqt=5623 HTTP/1.1
02-11 14:39:27.324: I/GoogleAnalyticsTracker(219): Host: www.google-analytics.com
02-11 14:39:27.324: I/GoogleAnalyticsTracker(219): User-Agent: GoogleAnalytics/1.4.2 (Linux; U; Android 2.1-update1; en-us; sdk Build/ECLAIR)
02-11 14:39:27.324: I/GoogleAnalyticsTracker(219): GET /__utm.gif?utmwv=4.8.1ma&utmn=1210083032&utmcs=UTF-8&utmsr=480x320&utmul=en-US&utmp=%2Ftest.testing.ez.TestEZActivity&utmac=UA-2912-1&utmcc=__utma%3D1.659024508.1328970962.1328970962.1328971039.2%3B&utmht=1328971161800&utmqt=5524 HTTP/1.1
First three are empty events (utme=5(**)(0)) and last is pageView (utmp=%2Ftest.testing.ez.TestEZActivity).
The correct behaviour should be empty event, pageView, emptyEvent, pageView (from onStop
, onStart
, onStop
and onStart
).
This is also wrong when tracking more than one event (with EasyTracker.getTracker().trackEvent
) during one dispatch.
Anybody had similar problems?
It turned out to be a bug in libGoogleAnalytics.jar 1.4.2
In function AsyncDispatchTask.dispatchSomePendingHits
in NetworkDispatcher.DispatcherThread
in the for loop requesterCallBacks.requestSent()
is called, which removes elements from the hits list.
This is the case mostly for dry mode, but can sometimes happen in normal mode (when hit string lenght is bigger than 8k), but you will get warned if that happens with:
Log.w("GoogleAnalyticsTracker", "Hit too long (> 8192 bytes)--not sent");
so just make sure your events and pageViews are not too long.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With