Configure general instrumentation

更新时间:
复制 MD 格式

Configure a unified H5 instrumentation solution for PC and mobile H5 pages using the mtracker library.

About this task

Choose an instrumentation type based on your business scenario. General instrumentation types.

Procedure

  1. Import the CDN version of mtracker. This injects a Tracker object into the global window object.

    If Chinese characters in the downloaded JS file appear garbled, you can still use the file. The garbling is caused by an encoding mismatch and does not affect instrumentation.

  2. Initialize the configuration based on your scenario.

    • An app in the mPaaS container has integrated the mPaaS H5 container.

      Sample code:

      <script>
      window._to = {
        bizScenario: 'alipay',   // Optional. The channel source. Default: empty.
        mtrDebug: true,         // Optional. Default: false.
      };
      </script>

      Parameter

      Description

      bizScenario

      Optional. The channel source. Default: empty.

      mtrDebug

      Optional. Enables mtracker debug mode, which prints reported logs. Default: false.

    • For an app that has not integrated the mPaaS H5 container, or for pages running in a browser:

      Sample code:

      <script>
      window._to = {
        server: 'https://cn-hangzhou-mas-log.cloud.alipay.com/loggw/webLog.do', // Required. The service endpoint that receives instrumentation data.
        appId: 'xxxxxxxxxx', // Required. The unique identifier of the app.
        workspaceId: 'default', // Required. The environment identifier.
        h5version: '1.0.0',    // Required. The version of the client app or H5 page.
        userId: '1234567890',      // Optional. Default: empty.
        bizScenario: 'alipay',   // Optional. The channel source. Default: empty.
        mtrDebug: true,         // Optional. Default: false.
        extendParams: { test: 111 } // Optional. Global extension parameters. Default: empty. Supported in mtracker 1.2.0 and later.
      };
      </script>

      Parameter

      Description

      server

      The service endpoint that receives instrumentation data.

      appId

      The unique identifier of the app.

      workspaceId

      The environment identifier.

      h5version

      The version of the client app or H5 page.

      userId

      Optional. The user ID. Default: empty.

      bizScenario

      Optional. The channel source. Default: empty.

      mtrDebug

      Optional. Enables mtracker debug mode, which prints reported logs. Default: false.

      extendParams

      Optional. Global extension parameters. Default: empty. Requires mtracker 1.2.0 or later.

  3. Initialize the mtracker object.

    By default, mtracker auto-initializes after the JS file is imported. To initialize manually:

    1. Before the JS import line, add the following code to disable auto-initialization.

      window.notInitTrackerOnStart = true;
    2. Add the initialization code.

      window.initTracker();
Note

Global extension parameters require mtracker 1.2.0 or later.

Set extendParams in window._to to include extension parameters in all subsequent reports. If a property in the ext parameter of a click or expo call shares a name with a global extension parameter, the method-level value takes precedence.

To update extendParams at runtime, call the following code. The new object overwrites all previous values.

window.changeTrackerExtendParams({ newValue: 11111 });

What to do next

Use the custom analysis page in the Mobile Analysis console to view H5 instrumentation data. Analyze general instrumentation.