How to implement Google Analytics v4 on a Project in Android Studion imported from legacy Eclipse ADT -
my legacy application project doesn't have application class. so, official document doesn't help.
don't know following code should go:
/** * enum used identify tracker needs used tracking. * * single tracker enough purposes. in case need multiple trackers, * storing them in application object helps ensure created once per * application instance. */ public enum trackername { app_tracker, // tracker used in app. global_tracker, // tracker used apps company. eg: roll-up tracking. ecommerce_tracker, // tracker used ecommerce transactions company. } hashmap<trackername, tracker> mtrackers = new hashmap<trackername, tracker>();
and these code:
synchronized tracker gettracker(trackername trackerid) { if (!mtrackers.containskey(trackerid)) { googleanalytics analytics = googleanalytics.getinstance(this); tracker t = (trackerid == trackername.app_tracker) ? analytics.newtracker(property_id) : (trackerid == trackername.global_tracker) ? analytics.newtracker(r.xml.global_tracker) : analytics.newtracker(r.xml.ecommerce_tracker); mtrackers.put(trackerid, t); } return mtrackers.get(trackerid); }
i have imported these libs of googleanalytics.
but still can't import libs this way:
import com.google.android.apps.analytics.googleanalyticstracker;
and, because using android studio 1.2 beta3, the tutorial based on eclipse not suit case.
is there simple way implement google analytics on android app? initialising in ios?
(bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { [gai sharedinstance].trackuncaughtexceptions = yes; [gai sharedinstance].dispatchinterval = 20; [[[gai sharedinstance] logger] setloglevel:kgailoglevelverbose]; [[gai sharedinstance] trackerwithtrackingid:@"ua-xxxx-y"]; }
the simples complete implementation of analytics on android requires:
- link google play services (it looks have done)
- add required network permissions in app manifest.
- extend android application class, override oncreate , set app class implementation in <android name='you_app_class'> name attribute.
- in oncreate create new tracker , keep in static var tracker = googleanalytics.getinstance(context).newtracker(); enable automatic reporting screens, exceptions, etc.
- register analyticsreceiver & analyticsservice in application manifest.
google analytics has github project simplest analytics hello world all. show bare minimum needed correct reporting on android.
Comments
Post a Comment