Harsha M V
Harsha M V

Reputation: 54949

Android Google Analytics Tracking

I have set up Google Analytics v2 beta on a test project as bellow

MainActivity.java

public class MainActivity extends Activity {
    Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        context = this;

        // Set Context to Google Analytics
        EasyTracker.getInstance().setContext(context);
    }

    @Override
    protected void onStart() {
        super.onStart();
        EasyTracker.getInstance().activityStart(this);

        EasyTracker.getInstance();
        Tracker myTracker = EasyTracker.getTracker();
        myTracker.sendView("harsha");
    }

    @Override
    protected void onStop() {
        super.onStop();
        EasyTracker.getInstance().activityStop(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}

analytics.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="https://schemas.android.com/tools" tools:ignore="TypographyDashes">

    <!-- Replace placeholder ID with your tracking ID -->
    <string name="ga_trackingId">UA&#8211;37418075&#8211;1</string>

    <!-- Enable automatic activity tracking -->
    <bool name="ga_autoActivityTracking">true</bool>

    <!-- Enable automatic exception tracking -->
    <bool name="ga_reportUncaughtExceptions">true</bool>
    <bool name="ga_debug">true</bool>
    <!-- The screen names that will appear in your reporting -->
    <string name="com.m7.google_analytics_v2.BaseActivity">Home</string>

</resources>

I have been trying to send the tracking to Google Analytics Server but not able to find any hits or activity of any kind. Does it take time for it to reflect ?

I find this in the Log Cat

01-13 15:16:52.360: I/GAV2(23176): Thread[GAThread,5,main]: putHit called
01-13 15:16:52.360: I/GAV2(23176): Thread[GAThread,5,main]: Sending hit to store
01-13 15:16:52.440: I/GAV2(23176): Thread[GAThread,5,main]: putHit called
01-13 15:16:52.440: I/GAV2(23176): Thread[GAThread,5,main]: Sending hit to store
01-13 15:16:53.825: I/GAV2(23176): Thread[GAThread,5,main]: putHit called
01-13 15:16:53.825: I/GAV2(23176): Thread[GAThread,5,main]: Sending hit to store
01-13 15:16:53.905: I/GAV2(23176): Thread[GAThread,5,main]: putHit called
01-13 15:16:53.905: I/GAV2(23176): Thread[GAThread,5,main]: Sending hit to store
01-13 15:16:57.840: I/GAV2(23176): Thread[GAThread,5,main]: putHit called
01-13 15:16:57.840: I/GAV2(23176): Thread[GAThread,5,main]: Sending hit to store
01-13 15:16:57.945: I/GAV2(23176): Thread[GAThread,5,main]: putHit called
01-13 15:16:57.945: I/GAV2(23176): Thread[GAThread,5,main]: Sending hit to store

Upvotes: 1

Views: 5574

Answers (2)

P.T.
P.T.

Reputation: 25177

This doesn't look good:

 <string name="ga_trackingId">UA&#8211;37418075&#8211;1</string>

&#8211; (–) is &ndash; which is a different character from the ASCII - (-) (&#45). I'm pretty sure GA just expects ASCII in the tracking Id.

Unless that was just inserted when pasting into stack overflow.

Upvotes: 3

Meghal Shah
Meghal Shah

Reputation: 405

Try create a new profile on Google Analytics under Admin and also set it as an App, it will provide you a new tracking number.

I had similar problem, for some reasons Google Analytics v2 didnt not work on my old Google Analytics project, so i created new project and a new profile, same code started reporting data after 24-36 hours. But you can also check using real time data if its hitting Google analytics server or not.

Upvotes: 1

Related Questions