Let us create a new property to track in Google Analytics.Open up analytics.google.com.Goto Admin.Goto property settings and create a new property there.Make sure that you pretend like you are tracking a website and not an app.The App functionality will not work for J2ME. Give the address of your own website or blog if you have any.It doesnt matter what site you give.
Once you create a property, you will now get a tracking ID something like this : UA-3*****4-1
Now Download the latest Google Analytics JAR from here
Add this to your project.I am now attaching a sample code below
This sample code will generate an event called New User whenever a user uses an app for the first time.Subsequent uses will generate an event called Old User. The Page view instance is just an example.
Tracker tc = Tracker.getInstance(m, id);// m is the MIDlet instance and id is the Tracking ID
tc.addToQueue(new Event("New User", "Opening App", m.getAppProperty("MIDlet-Name"), null));
tc.addToQueue(new Event("Old User", "Opening App", m.getAppProperty("MIDlet-Name"), null));
// Adding a Page View here just as an example
tc.addToQueue(new PageView(m.getAppProperty("MIDlet-Name"), "/mainPage"));
The sample code makes use of LWUIT-IO package which has the Storage class.It is only used to check whether we are running the app for the first time or not. Kindly note how I am making use of events and page views alone for understanding purpose.
I will put this as a Wiki article pretty soon.