|
| 1 | +package com.javatechig.ganalytics; |
| 2 | + |
| 3 | +import android.app.Activity; |
| 4 | +import android.os.Bundle; |
| 5 | +import android.view.Menu; |
| 6 | +import android.view.View; |
| 7 | +import android.view.View.OnClickListener; |
| 8 | +import com.google.analytics.tracking.android.EasyTracker; |
| 9 | +import com.google.analytics.tracking.android.MapBuilder; |
| 10 | +import com.google.analytics.tracking.android.StandardExceptionParser; |
| 11 | + |
| 12 | +public class MainActivity extends Activity { |
| 13 | + |
| 14 | + private EasyTracker easyTracker = null; |
| 15 | + |
| 16 | + @Override |
| 17 | + protected void onCreate(Bundle savedInstanceState) { |
| 18 | + super.onCreate(savedInstanceState); |
| 19 | + setContentView(R.layout.activity_main); |
| 20 | + |
| 21 | + easyTracker = EasyTracker.getInstance(MainActivity.this); |
| 22 | + |
| 23 | + findViewById(R.id.trackEvent).setOnClickListener(new OnClickListener() { |
| 24 | + |
| 25 | + @Override |
| 26 | + public void onClick(View view) { |
| 27 | + easyTracker.send(MapBuilder.createEvent("your_action", |
| 28 | + "envet_name", "button_name/id", null).build()); |
| 29 | + } |
| 30 | + }); |
| 31 | + |
| 32 | + findViewById(R.id.trackCrash).setOnClickListener(new OnClickListener() { |
| 33 | + |
| 34 | + @Override |
| 35 | + public void onClick(View view) { |
| 36 | + |
| 37 | + try { |
| 38 | + int a[] = new int[2]; |
| 39 | + int num = a[4]; |
| 40 | + } catch (ArrayIndexOutOfBoundsException e) { |
| 41 | + easyTracker.send(MapBuilder.createException( |
| 42 | + new StandardExceptionParser(MainActivity.this, null) |
| 43 | + .getDescription(Thread.currentThread().getName(), e), false).build()); |
| 44 | + } |
| 45 | + |
| 46 | + } |
| 47 | + }); |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public void onStart() { |
| 52 | + super.onStart(); |
| 53 | + EasyTracker.getInstance(this).activityStart(this); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public void onStop() { |
| 58 | + super.onStop(); |
| 59 | + EasyTracker.getInstance(this).activityStop(this); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public boolean onCreateOptionsMenu(Menu menu) { |
| 64 | + getMenuInflater().inflate(R.menu.main, menu); |
| 65 | + return true; |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments