Google Analytics Slows Down Android App - android

I've recently added Google Analytics to my Android app with the EasyTracker. However, I feel like my app has slowed down significantly since I added these. Is there a preferred method for dealing with this? I can't seem to find anything in the documentation for Analytics...
Here is what I put in the Activities I am tracking:
#Override
public void onStart() {
super.onStart();
EasyTracker tracker = EasyTracker.getInstance();
tracker.setContext(this);
tracker.activityStart(this);
}
#Override
public void onStop() {
super.onStop();
EasyTracker.getInstance().activityStop(this);
}
Should I just send these to an AsyncTask? If so, how would I go about doing that?
Any help would be greatly appreciated! :D

Maybe it's dispatching the results too quick.
Try setting the dispatch time to something longer, lets say 5 minutes (300 seconds).

I ended up using this guy's class: http://blog.tomgibara.com/post/5598222730/improving-android-google-analytics-performance
Hopefully this helps someone else as well!

Related

Design application using more confuse code?

Recently I had opened some real apps by using this
So I'm getting the source code from that. In those source code, I found that most of the code is designed like this
public class LockActivity extends Activity {
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
if (GlobalDataHolder.m9617e()) {
bm.m8771b(getApplicationContext(), getPackageManager());
finish();
}
}
protected void onResume() {
super.onResume();
if (GlobalDataHolder.m9617e()||this.f4719a.m9124j()) {
bm.m8771b(getApplicationContext(), getPackageManager());
finish();
return;
}
startActivity(new Intent(getApplicationContext(), LaunchActivity.class));
}
public void onPause() {
super.onPause();
}
public void onDestroy() {
super.onDestroy();
}
}
And also the java file named by Garbled text such as
aa.java
bh.java
cj.java
My question is
1) Why those developer create the function named 'm8771b','m9617e'
2) Why most of apps is designed like that?
3) Is this more secure for avoid other to copy their code?
4) Should we also design the application like that?
5) How they can remember where they put the function?
People don't write code like that... unless they are either a savant or inexperienced. Using seemingly random strings of methods/class names is something called Obfuscation, which means to hide the real meaning of something in order to make it difficult to read.
Obfuscation Wiki as it pertains to software development
There are programs out there, like ProGuard which do this for us. Its purpose is to both compact and obscure code. That way it is difficult for someone to decompile and reconstruct the project without pouring over what it does (depending on complexity) endlessly.
Since Java always compiles into bytecode, it is predictable in the way in which it can be decompiled and much more standard that a write-once compile-anywhere language. ProGuard helps protect intellectual property or proprietary software and keep people from just stealing code.

Unregistering a service in application that uses NSD

I'm making an app that uses Network Service Discovery, let's call it a "Wi-fi Chat". And at some point I want to unregister a service created earlier in order to avoid creation of countless copies of it. But the problem is, when I cal;
mNsdManager.unregisterService(mRegistrationListener);
I get "listener is not registered" error. To make sure that I have STILL THE SAME object of that listener I even initialized it in a class that extends Application class and still I get this error. So, the question is: how to unregister a service properly? Thank you in advance.
Also, I looked through "NsdChat" sample application, and it crashes at the same point with the same error!
Well, I kinda found a solution. Much thanks to this Wizard who fixed NsdChat Google example.
The solution is: in tearDown() method, inside which we call unregisterService(RegistrationListener listener) we should do this
public void tearDown() {
if (mRegistrationListener != null) {
try {
mNsdManager.unregisterService(mRegistrationListener);
} finally {
}
mRegistrationListener = null;
}
}
Though I still have no clue how actually this works, so if you have any thoughts regarding this puzzle, please post an answer

Android: Google Analytics availability in Google Play Services?

Google Analytics has been announced to become part of the rolling out Google Play Services 4.3, however it is not yet included in the Google Play Services packages list:
http://developer.android.com/reference/gms-packages.html
Any idea when it will become available, and will it be safe to be used straight away, or will it be better to wait for some time to make sure every user has Google Play Services 4.3 already installed?
I've noticed some other differences.
Tracker
To get a new Tracker, use the newTracker() method (accepts both a String value and an int value [for XML configuration]):
googleTracker = gaInstance.getTracker(GA_KEY); // OLD
googleTracker = gaInstance.newTracker(GA_KEY); // NEW
EasyTracker
EasyTracker has now disappeared, so we will have to use GoogleAnalytics.getInstance(this).reportActivityStart(this) as reported by Paito.
Setters
The googleTracker.set() method is no longer available. It has been replaced with more specialised methods, for example:
googleTracker.set(Fields.SCREEN_NAME, null); // OLD
googleTracker.setScreenName(null); // NEW
Event creation
The googleTracker.send() method has also seen some changes.
googleTracker.send(MapBuilder
.createEvent(category, action, label, value)
.build()); // OLD
googleTracker.send(new HitBuilders.EventBuilder()
.setCategory(category)
.setAction(action)
.setLabel(label)
.setValue(value)
.build()); // NEW
AppView
It now becomes
googleTracker.send(MapBuilder.createAppView().build()); // OLD
googleTracker.send(new HitBuilders.AppViewBuilder().build()); // NEW
AppViewBuilder
AppViewBuilder has now been deprecated, replaced by the new ScreenViewBuilder class. (thanks Hai Phong for the tip!)
For those who are running into (or have already dealt with) the Dalvik's 64K methods limit, there are now 3K methods that you will be able to get rid of in your application, thanks to this integration.
It's part of the package list now.
I think the basic functionality works something like this...
import com.google.android.gms.analytics.GoogleAnalytics;
#Override
protected void onStart() {
super.onStart();
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
#Override
protected void onStop() {
super.onStop();
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
As per conversation in order to use Easytracker replacement with
GoogleAnalytics.getInstance(this).reportActivityStart(this);
GoogleAnalytics.getInstance(this).reportActivityStop(this);
You need to add your config to AndroidManifest like
<meta-data android:name="com.google.android.gms.analytics.globalConfigResource" android:resource="#xml/analytics_global_config" />
I'm still having to get instance of Tracker to send Events, may be somebody else would have better luck at replacing
EasyTracker.getInstance(mContext).send(MapBuilder....)
The documentation for Google Analytics SDK v4 (now part of Google Play Services) has just been published!
https://developers.google.com/analytics/devguides/collection/android/v4/

Realtime android Google analytics without EasyTracker

I'm trying to figure out how to track page views in real time without using the EasyTracker singleton.
I have the following code:
/**
* This how I create the tracker instance...
*/
private void createTracker() {
if (tracker != null)
return;
tracker = googleAnalytics.getTracker(googleAnalyticsSiteId);
tracker.setAnonymizeIp(trackingLevel.isAnonymous());
tracker.setAppInstallerId(configuration.getInstallationUUID());
tracker.setSampleRate(dispatchIntervalInSeconds);
trackUpgradedApp();
}
...
void someOtherMethod(Activity activity){
tracker.sendView((String) activity.getTitle());
// EasyTracker.getInstance().activityStart(cyborgScreen.getActivity());
}
While I uncomment the EasyTracker line, I can track the pages visited in realtime, but only after adding the analytics.xml to the project (obviously).
Once commenting the line, I do not receive the realtime information...
If following the code here, it should have done the trick.
Am I missing the obvious, or there is a bug?
Thanks,
Adam.
Well, after tones of playing around deleting, coping, changing things, I've found that this:
GAServiceManager.getInstance().setDispatchPeriod(dispatchIntervalInSeconds);
was missing, and that is why I could not see the realtime screen event without using the EasyTracker!
Hope this helps someone...
The answer is you call:
tracker.sendView((String) activity.getTitle());
but it can take time until you see it!

Monitoring errors with Sentry - Android

I need to implement Sentry for my android app, I try to find an example about how I have to implement this, but I can't find it.
I saw the Sentry documentation in http://sentry.readthedocs.org/en/latest/developer/client/index.html#server_name
But I have some questions.
If my app crash, the exception will be captured?
Should I put this code line into my try/catch?
var $resultId = myClient->captureException($myException); (in android code)
If somebody has a sample in android I will be grateful.
Thank you!
I am a little late but I just recently released a Sentry client for Android. It's in its early stages so feel free to pull request any changes that you see.
https://github.com/joshdholtz/Sentry-Android
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Sentry will look for uncaught exceptions from previous runs and send them
Sentry.init(this, "YOUR-SENTRY-DSN");
}
}
Maybe try using something like BugSense? http://www.bugsense.com/
If it definitely has to be Sentry, then look at this example: https://stackoverflow.com/a/755151/349012
It shows you how to set your own uncaught exception handler so you can try and upload to Sentry.

Categories

Resources