I set up a helper class which reports events and screens to Google Analytics
, via the EasyTracker
, for an unknown reason each time I relaunch the app, it reports all the screen and the events as a new user.I checked the gaClientId
file, which store a unique ID.but each time I relaunch the app, the ID stored in this file changes, compared to other apps where is stays the same.
here is the code I use in my helper class, note that I've tried using ApplicationContext context as well.I tried disabling the instant dispatch (and yes I know its not good practice reporting it immediately)
private static String mLastView = "";
public static void sendView(String view,Context ctx) {
// Don't report screen twice in a row
if(view.equals(mLastView)) return;
mLastView = view;
EasyTracker.getInstance().setContext(ctx);
EasyTracker.getTracker().sendView(view);
EasyTracker.getInstance().dispatch();
}
public static void sendEvent(Context ctx,String category,String action,String label,long value){
EasyTracker.getInstance().setContext(ctx);
EasyTracker.getTracker().sendEvent(category, action, label, value);
EasyTracker.getInstance().dispatch();
}
Update:
I've tried using the GoogleAnalytics class without the easy tracker,but still doesn't work.I guess there some sort of read permission issue (but can write it?), the file located at data/data/com.my.app/files/gaClientId
Update:
I've tried anything, I can read the gaClientId
file manually, no problem whatsoever, tired reporting with and without helper class, still create a new ClientID each launch of the app.
Guess what? the file which stores the ClientID located at data/data/com.my.app/files/gaClientId
, and the app download file to this folder as well.. each launch of the app I ran over the folder and deleted its contents.thus, when the analytics was initilized, it couldn't find the gaClientId file, and created a new one which created a new user
TIP Don't store anything at the root of files
I'm using the easy tracker and i don't get that problem. Here is how i do it: In the onCreate() of your activity just put:
gaInstance = GoogleAnalytics.getInstance(this);
tracker = gaInstance.getDefaultTracker()
gaInstance & tracker are global fields.
Then in the onStart() you simply call it like:
tracker.sendView("/youractivity");
That for the view. The event as well is just a :
tracker.sendEvent("String",
"String",
"String",
"long");
The last thing to do is change the default value for the session timeout in the analytics.xml file. By default is 30 seconds, in the example below is 30 minutes
<integer name="ga_sessionTimeout">1800</integer>
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