Skip to content

Commit b197298

Browse files
JAVATECHIGJAVATECHIG
JAVATECHIG
authored and
JAVATECHIG
committed
Added Google Analytics Sample
1 parent 2ea116f commit b197298

File tree

19 files changed

+238
-0
lines changed

19 files changed

+238
-0
lines changed
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.javatechig.ganalytics"
4+
android:versionCode="1"
5+
android:versionName="1.0" >
6+
7+
<uses-sdk
8+
android:minSdkVersion="8"
9+
android:targetSdkVersion="17" />
10+
11+
<uses-permission android:name="android.permission.INTERNET" />
12+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
13+
14+
<application
15+
android:allowBackup="true"
16+
android:icon="@drawable/ic_launcher"
17+
android:label="@string/app_name"
18+
android:theme="@style/AppTheme" >
19+
<activity
20+
android:name="com.javatechig.ganalytics.MainActivity"
21+
android:label="@string/app_name" >
22+
<intent-filter>
23+
<action android:name="android.intent.action.MAIN" />
24+
25+
<category android:name="android.intent.category.LAUNCHER" />
26+
</intent-filter>
27+
</activity>
28+
</application>
29+
30+
</manifest>
Binary file not shown.
Binary file not shown.
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system edit
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
#
10+
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11+
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12+
13+
# Project target.
14+
target=android-17
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical"
6+
android:padding="@dimen/activity_vertical_margin"
7+
tools:context=".MainActivity" >
8+
9+
<TextView
10+
android:id="@+id/textView1"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:text="@string/info" />
14+
15+
<Button
16+
android:id="@+id/trackEvent"
17+
android:layout_width="wrap_content"
18+
android:layout_height="wrap_content"
19+
android:text="Track Event" />
20+
21+
<Button
22+
android:id="@+id/trackCrash"
23+
android:layout_width="wrap_content"
24+
android:layout_height="wrap_content"
25+
android:text="Track Crash" />
26+
27+
</LinearLayout>

GoogleAnalyticsDemo/res/menu/main.xml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
2+
3+
<item
4+
android:id="@+id/action_settings"
5+
android:orderInCategory="100"
6+
android:showAsAction="never"
7+
android:title="@string/action_settings"/>
8+
9+
</menu>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<resources>
2+
3+
<!--
4+
Customize dimensions originally defined in res/values/dimens.xml (such as
5+
screen margins) for sw600dp devices (e.g. 7" tablets) here.
6+
-->
7+
8+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<resources>
2+
3+
<!--
4+
Customize dimensions originally defined in res/values/dimens.xml (such as
5+
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
6+
-->
7+
<dimen name="activity_horizontal_margin">128dp</dimen>
8+
9+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 11+. This theme completely replaces
5+
AppBaseTheme from res/values/styles.xml on API 11+ devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
8+
<!-- API 11 theme customizations can go here. -->
9+
</style>
10+
11+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 14+. This theme completely replaces
5+
AppBaseTheme from BOTH res/values/styles.xml and
6+
res/values-v11/styles.xml on API 14+ devices.
7+
-->
8+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
9+
<!-- API 14 theme customizations can go here. -->
10+
</style>
11+
12+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<!-- Replace placeholder ID with your tracking ID -->
5+
<string name="ga_trackingId">UA-xxxxxxxxxx</string>
6+
7+
<!-- Enable automatic activity tracking -->
8+
<bool name="ga_autoActivityTracking">true</bool>
9+
10+
<!-- Enable automatic exception tracking -->
11+
<bool name="ga_reportUncaughtExceptions">true</bool>
12+
13+
14+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<resources>
2+
3+
<!-- Default screen margins, per the Android Design guidelines. -->
4+
<dimen name="activity_horizontal_margin">16dp</dimen>
5+
<dimen name="activity_vertical_margin">16dp</dimen>
6+
7+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<string name="app_name">AnalyticsDemo</string>
5+
<string name="action_settings">Settings</string>
6+
<string name="info">Hello! Welcome to Google Analytics Demo.</string>
7+
<string name="button">Track Event</string>
8+
9+
</resources>
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme, dependent on API level. This theme is replaced
5+
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Light">
8+
<!--
9+
Theme customizations available in newer API levels can go in
10+
res/values-vXX/styles.xml, while customizations related to
11+
backward-compatibility can go here.
12+
-->
13+
</style>
14+
15+
<!-- Application theme. -->
16+
<style name="AppTheme" parent="AppBaseTheme">
17+
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
18+
</style>
19+
20+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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

Comments
 (0)