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
.
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
, orBaseAppCompatActivity
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 librarysupport-v4
, you should enable BaseFragment to implement theTrackPageConfig
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); } }
Add custom parameters
In baseline 10.1.68.44 and later versions, it is supported to add custom parameters in the automation log by using the following method.
MPLogger.addAutoLogCustomParam("test_key1", "test_value1");
MPLogger.addAutoLogCustomParam("test_key2", "test_value2");
Map<String, String> params = new HashMap<>();
params.put("test_key3", "test_value3");
params.put("test_key4", "test_value4");
MPLogger.addAutoLogCustomParams(params);