Google Analytics v4 API Android

Implementing Google Analytics v4 API Android, Google Analytics provides powerful digital analytics for anyone with a web presence, large or small. It’s one of the most powerful digital analytics solutions available – and it’s free for anyone to use.
I will show you the step by step methods to Implementing Google Analytics v4 API Android.

Step 1 : The Application Class File, Google Analytics v4 API Android.

Create a class with name (you can create a class with any name, Here I am using this). And put the below code

Step 2 : Configuration files,Google Analytics v4 API Android.

Create two files in the xml folder under res folder (res/xml).



Step 3 : AndroidManifest, Google Analytics v4 API Android.

Add this code to your manifest file in the application section and permissions.

Important : Don’t forget to call the application with the class file we created first.

Your manifest file will look like

Step 4 : MainActivity, Google Analytics v4 API Android.

At last import the class and add some actual hit tracking code to our activity. MainActivity will look like,

Important : replace  all UX-XXXXXXXX-Y with your app property ID.

Step 5 : Up and Run, Google Analytics v4 API Android.

Finally compile and run.

If you are logged in to your Analytics account you will see:

Google Analytics v4 in Android
Online user in analytics