All Products
Search
Document Center

Automation log

Last Updated: Jan 18, 2021

Automation logs record page switching events. Based on automation logs, you can analyze the page views (PV), unique visitors (UV) and other indicators of the functions or marketing pages of an App.

Tracking

Initialize tracking

Call the following method to initialize automated tracking.

 
  1. MPLogger.enableAutoLog();
  • For Portal & Bundle projects, it is suggested to call the method in the postInit() method of MockLauncherActivityAgent:
  • For mPaaS Inside and AAR projects, it is suggested to call the method in the onCreate method of Application after mPaaS framework initialization.

Configure Activity

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

  • The Activity inherits the class BaseActivity, BaseFragmentActivity, or BaseAppCompatActivity of the mPaaS framework records PV automatically.
  • For the Activity not inheriting mPaaS base class, you can add the life cycle monitoring code in the BaseActivity class to record PV:

       
    1. public class BaseActivity extends Activity {
    2. @Override
    3. protected void onCreate(Bundle savedInstanceState) {
    4. super.onCreate(savedInstanceState);
    5. MPTracker.onActivityCreate(this);
    6. }
    7. @Override
    8. public void onWindowFocusChanged(boolean hasFocus) {
    9. super.onWindowFocusChanged(hasFocus);
    10. MPTracker.onActivityWindowFocusChanged(this, hasFocus);
    11. }
    12. @Override
    13. protected void onResume() {
    14. super.onResume();
    15. MPTracker.onActivityResume(this);
    16. }
    17. @Override
    18. protected void onPause() {
    19. super.onPause();
    20. MPTracker.onActivityPause(this);
    21. }
    22. @Override
    23. protected void onDestroy() {
    24. super.onDestroy();
    25. MPTracker.onActivityDestroy(this);
    26. }
    27. }

Configure Fragment

  • For the Fragment in the support-v4 library provided by mPaaS, implement the TrackPageConfig API in the BaseFragment class.

       
    1. public class BaseFragment extends Fragment implements TrackPageConfig {
    2. /**
    3. * Page identifier, it is usually the class name.
    4. * If no page identifier is passed in, no page information is displayed for page analysis in the console.
    5. */
    6. @Override
    7. public String getPageSpmId() {
    8. return this.getClass().getName();
    9. }
    10. @Override
    11. public Map<String, String> getExtParam() {
    12. return null;
    13. }
    14. @Override
    15. public boolean isTrackPage() {
    16. return true;
    17. }
    18. }
  • For the Fragment in the support-v4 library provided in the native project, implement the TrackPageConfig API in the BaseFragment class and add the following life cycle monitoring code:

       
    1. public class BaseFragment extends Fragment implements TrackPageConfig {
    2. /**
    3. * Page identifier, it is usually the class name.
    4. * If no page identifier is passed in, no page information is displayed for page analysis in the console.
    5. */
    6. @Override
    7. public String getPageSpmId() {
    8. return this.getClass().getName();
    9. }
    10. @Override
    11. public Map<String, String> getExtParam() {
    12. return null;
    13. }
    14. @Override
    15. public boolean isTrackPage() {
    16. return true;
    17. }
    18. @Override
    19. public void onResume() {
    20. super.onResume();
    21. MPTracker.onFragmentResume(this);
    22. }
    23. @Override
    24. public void onPause() {
    25. super.onPause();
    26. MPTracker.onFragmentPause(this);
    27. }
    28. @Override
    29. public void onHiddenChanged(boolean hidden) {
    30. super.onHiddenChanged(hidden);
    31. MPTracker.onFragmentHiddenChanged(this, hidden);
    32. }
    33. @Override
    34. public void setUserVisibleHint(boolean isVisibleToUser) {
    35. super.setUserVisibleHint(isVisibleToUser);
    36. MPTracker.onFragmentSetUserVisibleHint(this, isVisibleToUser);
    37. }
    38. @Override
    39. public void onDestroy() {
    40. super.onDestroy();
    41. MPTracker.onFragmentDestory(this);
    42. }
    43. }