All Products
Search
Document Center

Configure common tracking

Last Updated: Aug 19, 2021

You can use a unified HTML5 tracking solution in PC and mobile HTML5 pages. By configuring tracking, you can realize unified HTML5 tracking.

About this task

You can configure different HTML5 common tracking in different business scenarios. To learn the specific business scenarios and corresponding tracking types, see Common tracking types.

Procedure

  1. Introduce the HTML5 tracking JS. You can introduce the mTracker of CDN version directly. When the mTracker is introduced, Tracker object is injected in the global window.
  2. Initialize configuration. Manually inject the following information:

    • For the Apps integrated with mPaaS HTML5 container, you don’t need to perform configuration initialization. The configurable items are:

      • bizScenario: Channel source, optional. It is empty be default.
      • mtrDebug: Whether to enable the debug mode for mTracker. In debug mode, the reported log will be printed, it defaults to “false”.

        For example:

               
        1. <script>
        2. window._to = {
        3. bizScenario: 'alipay', // Optional, it is empty by default.
        4. mtrDebug: false, // Optional, it is false by default.
        5. };
        6. </script>
        7. <script src="https://gw.alipayobjects.com/os/lib/alipay/mpaas-mtracker/1.1.3/dist/index.min.js"></script>
    • For the Apps not integrated with mPaaS HTML5 container or browser-side Apps, you need to complete the following configurations:

      • server: The service address that accepts the tracking.
      • appId: App’s unique identifier.
      • workspaceId: Workspace identifier.
      • h5version: HTML5 page version, optional.
      • userId: User ID, optional.
      • bizScenario: Channel source, optional. It is empty be default.
      • autoStart: Whether to enable mTracker automatically, optional. It is “true” by default. If it is set as “false”, the mTracker reporting function is only available after Tracker.start () is called. The PV event of the current page will be reported when mtracker is enabled.
      • mtrDebug: Whether to enable the debug mode for mTracker. In debug mode, the reported log will be printed, it defaults to false.

        For example:

               
        1. <script>
        2. window._to = {
        3. server: 'https://cn-hangzhou-mas-log.cloud.alipay.com/loggw/webLog.do',
        4. appId: 'xxxxxxxxxx',
        5. workspaceId: 'test',
        6. h5version: '0.1.1.1',
        7. userId: '12312323', // Optional, empty by default
        8. bizScenario: 'alipay', // Optional, empty by default
        9. mtrDebug: false, // Optional, false by default
        10. };
        11. </script>
        12. <script src="https://gw.alipayobjects.com/os/lib/alipay/mpaas-mtracker/1.1.3/dist/index.min.js"></script>
  3. Initialize mTracker objects.

    By default, mTracker is automatically initialized and injected into the window object after the JS file is introduced. If manual initialization is required in some scenarios, you should complete the initialization the performing the steps below:

    1. Add the following code in front of the location where the JS file is introduced to prohibit automatic initialization.
           
      1. window.notInitTrackerOnStart = true;
    2. Add initialization code.
           
      1. window.initTracker();

What to do next

Log in to the Mobile Analysis Service console, you can analyze the HTML5 common tracking logs reported by mTracker on the custom analysis page. See Analyze common tracking logs for more information.