在Android应用中实施GoogleAnalytics

时间:2015-08-31 10:41:26

标签: android eclipse google-analytics

我正在使用eclipse在Android应用中实施Google Analytics。经过大量的研究,我实施了它。这是我的代码:

import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


import com.google.analytics.tracking.android.EasyTracker;
import com.google.analytics.tracking.android.MapBuilder;
import com.google.analytics.tracking.android.StandardExceptionParser;


public class MainActivity extends Activity {

    private EasyTracker easyTracker = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        easyTracker = EasyTracker.getInstance(MainActivity.this);

     Button btn1 = (Button) findViewById(R.id.button1);   
     Button btn2 = (Button) findViewById(R.id.button2);   

    btn1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                easyTracker.send(MapBuilder.createEvent("your_action",
                        "envet_name", "button_name/id", null).build());
            }
        });



    btn2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {

            try {
                int a[] = new int[2];
                int num = a[4];
            } catch (ArrayIndexOutOfBoundsException e) {
                easyTracker.send(MapBuilder.createException(
                                new StandardExceptionParser(MainActivity.this, null)
                                        .getDescription(Thread.currentThread().getName(), e), false).build());
            }

        }
    });


    }


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

    @Override
    public void onStop() {
        super.onStop();
        EasyTracker.getInstance(this).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.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

代码编译成功,但我遇到的问题是它没有在GoogleAnalytics帐户中发送任何信息。我​​没有在Google Analytics中收到任何信息部分。

0 个答案:

没有答案