5

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.

Kirill Kulakov
  • 10,035
  • 9
  • 50
  • 67
  • 1. Which GA SDK are you using? 2. did you test on other devices / emulators? – Raanan Apr 18 '13 at 13:00
  • Yes, I've tested it in the emulator and on more than 10 devices.I'm using the latest release of GA V2 Beta 5 – Kirill Kulakov Apr 18 '13 at 15:01
  • Beta 5 was released 8 days ago, did you try changing to beta 4? This feels like a env/setup issue, I would suggest setting up a small simple test project. – Raanan Apr 18 '13 at 15:20

2 Answers2

4

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

Kirill Kulakov
  • 10,035
  • 9
  • 50
  • 67
1

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>
MonkeyDroid
  • 637
  • 7
  • 14