Android google analytics not working

Here is my code snippet. I do not know why it does not work. When I open the application on my Android phone (S3). Information is not displayed in real time.

public class MainActivity extends Activity { GoogleAnalyticsTracker analyticsTracker; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); analyticsTracker = GoogleAnalyticsTracker.getInstance(); analyticsTracker.startNewSession("UA-XXXXXXX-X", 5, this); analyticsTracker.trackPageView("/HomeScreen"); setContentView(R.layout.activity_main); ; } public void one(View view) { analyticsTracker.trackEvent("OneCategory", // Category "OneAction", // Action "One", // Label 77); // Value analyticsTracker.trackPageView("/HomeScreen"); } public void two(View view) { analyticsTracker.trackEvent("TwoCategory", // Category "TwoAction", // Action "Two", // Label 77); // Value analyticsTracker.trackPageView("/HomeScreen"); } public void three(View view) { analyticsTracker.trackEvent("ThreeCategory", // Category "ThreeAction", // Action "Three", // Label 77); // Value analyticsTracker.trackPageView("/HomeScreen"); } public void dispatch(View view) { analyticsTracker.dispatch(); } @Override protected void onDestroy() { analyticsTracker.stopSession(); super.onDestroy(); } 

The manifest also includes the necessary permissions.

  <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
+4
source share
1 answer

You tried to look at the logs when using the emulator. May be helpful. Otherwise, you can try below.

I also had some problems installing GATracker. The latest library includes EasyTracker , which saves you from overhead.

- Add a res/values/analytics.xml file containing analytics profile configuration information.

 <?xml version="1.0" encoding="utf-8" ?> <resources> <!--Replace placeholder ID with your tracking ID--> <string name="ga_trackingId">UA-XXXX-Y</string> <!--Enable automatic activity tracking--> <bool name="ga_autoActivityTracking">true</bool> <!--Enable automatic exception tracking--> <bool name="ga_reportUncaughtExceptions">true</bool> </resources> 

- Set the context for EasyTracker in their activities using the following

 EasyTracker.getInstance().setContext(this); 

- Now you can make EasyTracker call

 @Override public void onStart() { super.onStart(); ... // The rest of your onStart() code. EasyTracker.getInstance().activityStart(this); // Add this method. } @Override public void onStop() { super.onStop(); ... // The rest of your onStop() code. EasyTracker.getInstance().activityStop(this); // Add this method. } 

- Other event calls can be made like,

 EasyTracker.getInstance().sendEvent(String category, String action, String label, long value); 

Hope this helps. More detailed documentation can be found here.

0
source

Source: https://habr.com/ru/post/1479298/


All Articles