All Products
Search
Document Center

Automation log

Last Updated: Jan 21, 2022

Automation logs are used to record page switching and control click events. You can analyze the page view (PV) and unique visitor (UV) data on app functions or operating pages based on automation logs.

Initialize

Call the following method to initialize automation log tracking events.

  MPLogger.enableAutoLog();
  • For Portal & Bundle projects, you are suggested to call the method in the postInit() method of MockLauncherActivityAgent.

  • For mPaaS Inside and AAR projects, you are suggested to call the method in the onCreate method in Application.

Configure Activity

Activity records the PV of a page from onResume to onPause, with the page name identified by the Activity class name.

  • Activities inheriting the class BaseActivity, BaseFragmentActivity, or BaseAppCompatActivity from mPaaS framework are automatically recorded.

  • If not to inherit the base classes from mPaaS framework, you can add the life cycle monitoring code in BaseActivity as follows.

      public class BaseActivity extends Activity {
    
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          MPTracker.onActivityCreate(this);
      }
    
      @Override
      public void onWindowFocusChanged(boolean hasFocus) {
          super.onWindowFocusChanged(hasFocus);
          MPTracker.onActivityWindowFocusChanged(this, hasFocus);
      }
    
      @Override
      protected void onResume() {
          super.onResume();
          MPTracker.onActivityResume(this);
      }
    
      @Override
      protected void onPause() {
          super.onPause();
          MPTracker.onActivityPause(this);
      }
    
      @Override
      protected void onDestroy() {
          super.onDestroy();
          MPTracker.onActivityDestroy(this);
      }
    }

Configure Fragment

  • If you use the com.mpaas.mas.adapter.api.BaseFragment provided by mPaaS framework, just inherit the class.

  • If you use Fragment in the official library support-v4, you should enable BaseFragment to implement the TrackPageConfig interface, and add the life cycle monitoring configuration as follows.

      public class BaseFragment extends Fragment implements TrackPageConfig {
    
      /**
       * Page ID, it is generally the class name
       * If not passed in, the page analysis data may not be presented on the console 
       */
      @Override
      public String getPageSpmId() {
          return this.getClass().getName();
      }
    
      @Override
      public Map<String, String> getExtParam() {
          return null;
      }
    
      @Override
      public boolean isTrackPage() {
          return true;
      }
    
      @Override
      public void onResume() {
          super.onResume();
          MPTracker.onFragmentResume(this);
      }
    
      @Override
      public void onPause() {
          super.onPause();
          MPTracker.onFragmentPause(this);
      }
    
      @Override
      public void onHiddenChanged(boolean hidden) {
          super.onHiddenChanged(hidden);
          MPTracker.onFragmentHiddenChanged(this, hidden);
      }
    
      @Override
      public void setUserVisibleHint(boolean isVisibleToUser) {
          super.setUserVisibleHint(isVisibleToUser);
          MPTracker.onFragmentSetUserVisibleHint(this, isVisibleToUser);
      }
    
      @Override
      public void onDestroy() {
          super.onDestroy();
          MPTracker.onFragmentDestroy(this);
      }
    }