Updated 27 September 2023
In this blog,
I have shown, How to track your android Application by a great and free analytics tool.
There are many analytics tools which can be used the like Segment.io, MixPanel, Localytics, Amazon Mobile Analytics etc. But They are not totally free and easily understandable.
So, here I am showing how to implement Google Analytics v4 in your application with a lot of key features like create multiple views according to different countries times, real-time users, bug report, active users and many more.
This is absolutely free of cost and easy to implement.
The Screen-shot of the real time users of Mobikul-OC-Demo App.
There are some easy steps to setup the google analytics to your app
Step 1: Add permission to your manifest.xml
1 2 3 4 5 6 7 8 9 10 |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mobikul.analytics"> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <application android:name="MobikulApplication"> ... </application> </manifest> |
Step 2: Add a plugin to your project in your top-level build.gradle
and your app-level build.gradle
files as follows:
build.gradle
:
1 |
classpath 'com.google.gms:google-services:1.5.0-beta2' |
build.gradle
:
1 |
apply plugin: 'com.google.gms.google-services' |
build.gradle
add:
1 |
compile 'com.google.android.gms:play-services-analytics:8.3.0' |
Step 3: Get a configuration file by this link.
Step 4: Copy the google-services.json
file into your app/
or mobile/
directory of your Android Studio project.
There is some block of code to track your application’s current activity
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
public class MobikulApplication extends Application { private Tracker mTracker; synchronized public Tracker getDefaultTracker() { if (mTracker == null) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG mTracker = analytics.newTracker(R.xml.global_tracker); } return mTracker; } public void trackException(Exception e) { if (e != null) { mTracker.send(new HitBuilders.ExceptionBuilder() .setDescription( new StandardExceptionParser(this, null) .getDescription(Thread.currentThread().getName(), e)) .setFatal(false) .build() ); } } } |
1 2 |
MobikulApplication mMobikulApplication = (MobikulApplication) getApplication(); mTracker = mMobikulApplication.getDefaultTracker(); |
1 2 3 |
String name = this.getClass().getName(); mTracker.setScreenName("" + name); mTracker.send(new HitBuilders.ScreenViewBuilder().build()); |
Sources:
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
2 comments