I am developing an Android app. I am trying to integrate Google Analytics with my Android app. I am tracking page visited of my application. But data is not sent from app to Google Analytics Console/Dashboard. Here is what I have done:
I have already integrated Firebase Push Notification to my app. So I no need to add json file.
I registered my app from Firebase to Google Analytics and I got a Unique Track ID.
Then in my application class, I created tracker instance like this.
public class MApplication extends Application {
public static final String GOOGLE_TRACK_ID ="MY-TRACK-ID";
public static GoogleAnalytics analytics;
public static Tracker tracker;
@Override
public void onCreate() {
super.onCreate();
analytics = GoogleAnalytics.getInstance(this);
analytics.setLocalDispatchPeriod(1800);
tracker = analytics.newTracker(GOOGLE_TRACK_ID);
tracker.enableExceptionReporting(true);
tracker.enableAdvertisingIdCollection(true);
tracker.enableAutoActivityTracking(true);
}
}
I initiate tracker like this because I cannot find XML file. So I found this solution - Android Google Analytics xml file. This is why I instantiate like that.
- Then in the page I want to track, I send data like this.
mApplication.tracker.setScreenName("Articles Page");
mApplication.tracker.send(new HitBuilders.ScreenViewBuilder().build());
This is my manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.football.waiyanhein.tonightfootballreport">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name="com.football.waiyanhein.model.MApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<activity android:name="com.football.waiyanhein.tonightfootballreport.StartActivity"
android:configChanges="orientation|screenSize"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
//Other activities go here
<provider android:authorities="com.facebook.app.FacebookContentProvider1864111377153297"
android:name="com.facebook.FacebookContentProvider"
android:exported="true"/>
<receiver android:name="com.football.waiyanhein.receiver.NotificationReceiver">
<intent-filter>
<action android:name="com.tonightfootball.waiyanhein.receiver.NotificationReceiver"></action>
</intent-filter>
</receiver>
<receiver android:name="com.football.waiyanhein.receiver.MemeCreateReceiver">
<intent-filter>
<action android:name="com.tonightfootball.waiyanhein.receiver.MemeCreateReceiver"></action>
</intent-filter>
</receiver>
<service android:name="com.football.waiyanhein.service.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name="com.football.waiyanhein.service.FirebaseIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
</application>
</manifest>
No data is sent as you can see here.
When I check Analytics Dashboard, there is no user data, there is nothing sent in Analytics Dashboard. Why it is not working?
