Integrate Google Analytics into your Android Application

From , 3 Years ago, written in Java, viewed 229 times.
URL https://pastebin.vip/view/712a6756
  1. ** Java Code **
  2. // Google Analytics
  3.         private Tracker mGaTracker;
  4.         private GoogleAnalytics mGaInstance;
  5.  
  6.  
  7. // Call this method from onCreate()
  8.         private void initGATracker() {
  9.                 mGaInstance = GoogleAnalytics.getInstance(this);
  10.                 mGaTracker = mGaInstance.getTracker(getResources().getString(
  11.                                 R.string.ga_trackingId));
  12.  
  13.                 EasyTracker.getInstance().setContext(getApplicationContext());
  14.         }
  15.  
  16.  
  17.         @Override
  18.         protected void onStart() {
  19.                 super.onStart();
  20.  
  21.                 EasyTracker.getInstance().activityStart(this);
  22.         }
  23.  
  24.         @Override
  25.         protected void onStop() {
  26.                 super.onStop();
  27.  
  28.                 EasyTracker.getInstance().activityStop(this);
  29.         }
  30.  
  31.  
  32.         // sample to how to use it, add it where you want to track
  33.         mGaTracker.sendEvent("Category", "Action", Label, null);
  34.  
  35. ------------------------------------------------------------------------------------------------------------
  36. ** create res/values/analytics.xml **
  37. ------------------------------------------------------------------------------------------------------------
  38. <?xml version="1.0" encoding="utf-8"?>
  39. <resources xmlns:tools="https://schemas.android.com/tools" tools:ignore="TypographyDashes">
  40.  
  41.     <!-- Replace placeholder ID with your tracking ID -->
  42.     <string name="ga_trackingId">UA-XXXX</string>
  43.  
  44.     <!-- Enable automatic activity tracking -->
  45.     <bool name="ga_autoActivityTracking">true</bool>
  46.  
  47.     <!-- Enable automatic exception tracking -->
  48.     <bool name="ga_reportUncaughtExceptions">true</bool>
  49.  
  50.     <!-- The screen names that will appear in your reporting -->
  51.     <string name="package_name.MainActivity">Home Activity</string>
  52.  
  53.     <!--
  54.         The inverval of time after all the collected data
  55.                 should be sent to the server, in seconds.
  56.     -->
  57.     <integer name="ga_dispatchPeriod">30</integer>
  58.  
  59.     <!-- Enable debugging -->
  60.     <bool name="ga_debug">false</bool>
  61.  
  62.     <!-- Automatically send all uncaught exceptions in your app using EasyTracker -->
  63.     <bool name="ga_reportUncaughtExceptions">true</bool>
  64.  
  65. </resources>
  66. // see http://androidsnippets.com/google-analytics
  67. //java/8471

Reply to "Integrate Google Analytics into your Android Application"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website