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
Introduce the mtracker of CDN version directly. When the mtracker is introduced,
Tracker
object is injected in the globalwindow
.In case of any messy code in the downloaded mtracker JS file, you can still use the JS file normally because that will not affect the tracking configuration. The messy code may be caused by the difference between the file encoding format and the encoding format interpreted by the browser.
Initialize configuration. Inject corresponding information in the HTML5 tracking JS file according to different situations:
For the apps integrated with mPaaS HTML5 container
<script> window._to = { bizScenario: 'alipay', mtrDebug: true, }; </script>
Parameter
Description
bizScenario
Channel source, optional. It is empty by default.
mtrDebug
Whether to enable the debug mode for mtracker. In debug mode, the reported log will be printed, it defaults to "false".
For the apps not integrated with mPaaS HTML5 container or browser-side apps
<script> window._to = { server: 'https://cn-hangzhou-mas-log.cloud.alipay.com/loggw/webLog.do', appId: 'xxxxxxxxxx', workspaceId: 'default', h5version: '1.0.0', userId: '1234567890', bizScenario: 'alipay', mtrDebug: true, extendParams: { test: 111 } }; </script>
Parameter
Description
server
The service address that accepts the tracking.
appId
App's unique identifier.
workspaceId
Workspace identifier.
h5version
App version or HTML5 page version, optional.
userId
User ID, optional.
bizScenario
Channel source, optional. It is empty by default.
mtrDebug
Whether to enable the debug mode for mtracker. In debug mode, the reported log will be printed, it defaults to false.
extendParams
Global extended parameters, supported in mtracker 1.2.0 and later versions. It is empty by default.
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:Add the following code in front of the location where the JS file is introduced to prohibit automatic initialization.
window.notInitTrackerOnStart = true;
Add initialization code.
window.initTracker();
The global extended parameters can be modified since mtracker 1.2.0. If your mtracker version is lower than 1.2.0, please upgrade it first.
Modify the global extension parameters as needed. By setting the extendParams
in window._to
, the extended parameters you set can be added in subsequent tracking logs. In case that duplicate attributes exist in the ext
parameter set in the click
or expo
method, the value in the click
or expo
method shall prevail.
You can call the following code to change the extendParams
, and the newly set object will overwrite all the previously set extendParams
values.
window.changeTrackerExtendParams({ newValue: 11111 });
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.