Cross-platform application user behavior automatic tracking method and system
By adopting a unified track-id system and standardized event protocol, combined with a Mock data interception mechanism, the problems of cross-platform consistency, control uniqueness, replay accuracy, and data obfuscation in cross-platform user behavior analysis are solved. This enables unified collection and replay across mini-programs, native apps, and the web, improving replay accuracy and system robustness.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- XIAOHUA (SHANGHAI) INTERNET TECH CO LTD
- Filing Date
- 2026-04-07
- Publication Date
- 2026-07-21
AI Technical Summary
Existing technologies for user behavior analysis and session replay suffer from cross-platform consistency issues, difficulties in maintaining control uniqueness, poor replay accuracy, data confusion, and challenges in controlling side effects. In particular, it is impossible to achieve uniformity in the collection and replay of user behavior data across different platforms.
By adopting a unified track-id system and event standardization protocol, combined with a Mock data interception mechanism, a unique cross-platform identifier is generated for interactive controls during compilation or runtime. User behavior events are monitored, collected, and processed into a standardized data structure. The data is then stored and replayed separately on the server side. The business environment is restored using an H5 mirror page, thus achieving unified collection and playback across platforms.
It achieves unified data collection and playback across mini-programs, native apps, and the web, improving playback accuracy, avoiding impact on real business operations, reducing maintenance costs, enhancing system robustness, and ensuring data security and independence.
Smart Images

Figure CN122431978A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of front-end engineering and application performance monitoring technology, specifically a method and system for automatically tracking user behavior in cross-platform applications. Background Technology
[0002] User behavior analysis and session replay technology are key technologies used in internet products to collect product usage data and user behavior data. They can provide scientific, intuitive, and flexible data guidance for operations and development personnel, helping them to upgrade and iterate products and adjust operational strategies in a timely manner.
[0003] Existing user behavior analysis and session replay technologies mainly employ the following implementation methods: Single-end playback solutions: such as rrweb on the web and screen recording in native apps; video recording solutions: directly recording screen video; DOM snapshot solutions: recording changes in the DOM tree. However, these implementation methods have the following shortcomings: 1. Cross-platform consistency issues: The identification methods of controls are not consistent across different platforms (mini-programs, apps, web), and the event types and parameters vary greatly across different platforms (tap / click, touch / gesture, etc.), making it impossible to establish a unified cross-platform control mapping relationship.
[0004] 2. Difficulty in maintaining the uniqueness of controls: Dynamically rendered controls are difficult to identify with stable unique identifiers, controls generated in cycles cannot be distinguished, and historical data after page structure changes cannot be accurately replayed.
[0005] 3. Replay accuracy issues: Inconsistent environments between the data acquisition and playback ends, changes in interface data leading to playback failures, and inability to accurately recreate historical operations after page version updates.
[0006] 4. Data confusion issue: Replay data and event tracking data are mixed together, affecting the original data analysis system, and the data structure is not suitable for playback requirements.
[0007] 5. Side effect control issues: Replay may trigger real business operations, and the API calls cannot be isolated, thus posing a risk of data pollution.
[0008] Based on the above reasons, this invention designs a cross-platform application user behavior automatic tracking method and system. Through a unified track-id system and event standardization protocol, it realizes unified collection and playback of mini-programs, native apps and web, solves the cross-platform consistency problem, and uses a Mock data interception mechanism and independent data structure design to avoid impact on real business and confusion with event tracking data. Summary of the Invention
[0009] The purpose of this invention is to overcome the shortcomings of the prior art and provide a cross-platform application user behavior automatic tracking method and system. Through a unified track-id system and event standardization protocol, it realizes unified collection and playback of mini-programs, native apps and web. Through a Mock data interception mechanism and independent data structure design, it avoids the impact on real business and confusion with the event tracking data.
[0010] To achieve the above objectives, the present invention provides a method for automatically tracking user behavior in cross-platform applications, comprising the following steps: S1, Data Acquisition Phase: S1-1 automatically generates a unique cross-platform identifier track-id for interactive controls during application compilation or runtime. It adopts the naming rule of page name_component context_control semantics and extracts semantic information from control attributes, event handling function names, and control types through intelligent semantic inference. It automatically adds an incrementing index to the same type of controls that are rendered in a loop to ensure uniqueness. S1-2, Install an event listener and use an event delegation mechanism to listen to user interactions at the global level. After capturing user behavior events, extract the unique identifier track-id, timestamp, and key information of event parameters. Perform automatic desensitization processing on sensitive information, encapsulate it into a standardized data structure and add it to the memory queue. S1-3 uses a distributed tracing architecture to collect interface data: S1-3-1 injects the session identifier (sessionId) and the unique trace identifier (traceId) into each HTTP request header through a request interceptor, thereby enabling context propagation of the trace identifier. S1-3-2, At the same time, the request initiation behavior is reported as an event point, and the server records the complete request and response data through structured log output and associates it with the unique trace identifier traceId; S1-3-3, During the replay phase, the session identifier sessionId and the unique trace identifier traceId are used to query the server-side log system to obtain the interface's Mock data, which is used to separate the lightweight collection of the front end from the centralized log management of the server. S1-4, Collect initial state information of the collection page to establish a complete session context; S1-5, the collected event data is compressed and then reported to the server through an independent channel according to the batch strategy; S2, Server-side processing stage: S2-1: After receiving the reported data, the server decompresses and verifies the format. Based on the data type, it distributes the data to a dedicated playback database in a way that isolates it from traditional data tracking. The event stream is stored in a time-series database. A unique session identifier (sessionId) is created for each session, and a multi-dimensional index is built to support fast querying. S2-2, The server also runs an independent log collection service, which collects the interface logs of business services in real time through a structured log pipeline; S2-3, each time the server builds and releases a version, it synchronously generates the corresponding version of the H5 image page. The image page retains the DOM structure and control identification system of the business page, removes unnecessary business logic code, and injects the replay SDK and Mock interceptor. It extracts all the unique identifier track-id to generate a manifest file for consistency verification. The image page and manifest file are organized by version number and uploaded to CDN. The version information is registered in the version management database to support precise version query and compatible version query. S3, Replay Phase: S3-1, Mirror Page Loading and Environment Preparation: S3-1-1, Query the version of the corresponding mirror page based on the application version number and page name in the session data, and use the precise version query matching strategy to find a mirror page with the same version number. If it does not exist, start the version downgrade strategy to find the compatible version or the latest version. S3-1-2, Load the resources of the mirror page in an independent iframe or new window, inject the playback SDK and load the event stream of the session and the data of the initial state of the page from the server, perform a consistency check to check whether all the unique identifiers track-id in the event stream exist in the mirror page, and generate an exception report to mark missing controls; S3-1-3, Install a Mock interceptor to hijack the page's network request API. When the page makes a request, based on the unique trace identifier traceId recorded in the event stream, query the API through the server log to obtain the corresponding interface response data, prevent the real request from being sent, and directly return the historical response data recorded in the log. At the same time, inject the page's initial state to restore global variables, state manager state, stored data, and routing parameters to ensure that the page presents the same initial state as when it was collected. S3-2, Core replay mechanism implementation: S3-2-1 constructs an event stream object by sorting the event array in ascending order of timestamps and establishes a multi-dimensional index of event ID, page name, and event type to support fast querying; S3-2-2 adopts a loop mode of event-by-event processing to achieve precise control of the timeline. The target control is located by the unique tracking identifier track-id. If the element does not exist, a retry mechanism is started to wait for the element to be rendered asynchronously. If the retry fails, XPath positioning or fuzzy matching of similar semantic controls is attempted as a fallback strategy. After successful positioning, the target control is selectively highlighted to facilitate observation of the playback progress. S3-2-3, Event dispatch executes different simulation operations based on the event type: Click events dispatch the mousedown, mouseup, and click DOM events sequentially, carrying coordinate parameters; input events directly set the element's value property and dispatch the input and change events; scroll events set the element's scrollTop property and dispatch the scroll event; page navigation events call the routing API to switch pages; after each event is dispatched, a double requestAnimationFrame is used to wait for the DOM to update completely, ensuring that the browser has finished re-rendering, before continuing to the next event; S3-2-4, the playback process supports full time control capabilities: including play / pause, speed up playback, jump to a specified time point, and single-step execution. Users can operate these control functions in real time through the playback control panel. S3-3, Cross-Platform Page Stack Simulation Mechanism: For playback data collected from mini-programs and native apps, a virtual page stack mechanism is implemented in the H5 environment to accurately reproduce multi-page navigation behavior. Specifically: Lifecycle management is implemented through a global callback registry. When a business page registers a lifecycle callback via a hook, it checks whether the lifecycle has been triggered. If it has, the callback is immediately resent to avoid omissions caused by the callback registration being later than the lifecycle trigger. The browser's forward / back button achieves bidirectional synchronization with the virtual stack by listening to the popstate event. When the event is triggered, the target page information is extracted from event.state, the virtual stack is searched and the required number of layers to be popped is calculated, and the corresponding operation is performed.
[0011] User behavior events include clicks, input, and scrolling; the information to be reported in S1-3-2 includes a unique trace identifier (traceId), request URL, request method, and timestamp; the initial state information in S1-4 includes global variables, state manager state, stored data, and routing parameters; the multi-dimensional index in S2-1 includes user ID, time range, page name, and application version; the interface response data in S3-1-3 is complete log information, including request URL, method, request body, response body, and response status code; the retry mechanism in S3-2-2 retries a maximum of 10 times, with each retry interval of 100ms.
[0012] Uploads in S1-5 use the Beacon API to ensure high reliability; if an upload fails, an exponential backoff retry mechanism is used, storing the ultimately failed data in the local database IndexedDB and automatically reporting it after the network recovers.
[0013] The interface logs in S2-2 contain complete information including traceId, sessionId, request URL, request method, request body, response body, response status code, and timestamp. They are stored in the log database with a dual index based on the unique traceId and sessionId, supporting quick retrieval of interface Mock data during the playback phase by querying the traceId association.
[0014] In step S1-3-1, when the data collection platform is a mini-program, a unique identifier `track-id` is injected into WXML through a compilation plugin. At runtime, the mini-program's lifecycle and events are monitored, and the tracking identifier is injected into the `wx.request` request header. When the data collection platform is a native app, a unique identifier `track-id` is added to the view instance through runtime injection. System event callbacks are hooked to collect interactions, and the tracking identifier is injected into the network request header via `URLProtocol / Interceptor`. When the data collection platform is a web application, a unique identifier `track-id` is automatically injected during the build phase through a Babel compilation plugin. At runtime, an event delegation mechanism is used to collect interactions, and `sessionId` and `traceId` are injected into the XMLHttpRequest / fetch request header via a request interceptor to achieve distributed tracing. The data collected from the mini-program, the app, and the web application is ultimately converted into a unified standardized format to ensure consistency in subsequent processing.
[0015] When the data collection platform is a native app, the project build phase generates H5 image resources of the corresponding version based on the native page structure, control identifiers and page version information. During the playback phase, the H5 image resources are driven to perform event dispatch through a virtual page stack and lifecycle simulation mechanism to restore the user operation effect of the native app.
[0016] In the compilation phase of S1-1, the plugin automatically scans elements and generates unique identifiers (track-ids) according to preset rules. When the artifact is built, a list of track-ids and corresponding version information are generated, and the list of track-ids and version information are registered with the version management service.
[0017] In the S2-3 project construction phase, corresponding H5 image resources are also generated and uploaded to the server. The server maintains the image resource address mapping relationship based on the version number.
[0018] In the playback phase of S3-1-1, the corresponding version of the H5 image resource is loaded according to the version number in the reported event, and the H5 image resource is driven to perform event dispatch based on user behavior events and interface logs.
[0019] A cross-platform application user behavior automatic tracking system includes: a client-side collection module, a server-side processing module, and a replay module; the client-side collection module is used to collect user behavior events, page initial state information, and interface request information and report them to the server; the server-side processing module is used to process and store the collected data, collect interface logs, and manage H5 mirror pages; the replay module is used to load mirror pages, restore page state, inject Mock data, and perform user behavior replay according to the event flow.
[0020] Compared with the prior art, the present invention has the following beneficial effects: 1. Truly achieve unified cross-platform playback: Through a unified track-id system and standardized event protocol, unified collection and playback of mini-programs, native apps, and web applications are achieved, solving the cross-platform consistency problem.
[0021] 2. Automated control identifier management: Through compile-time plugins and runtime automatic injection, the automatic generation and maintenance of track-ids are realized, which greatly reduces the cost of manual maintenance and supports dynamic rendering and cyclic generation of controls.
[0022] 3. Enhanced high-fidelity playback: By accurately matching the mirrored page version and injecting Mock data to restore the business environment, the accuracy of playback is significantly improved.
[0023] 4. Complete isolation of side effects: Through the Mock data interception mechanism, the replay process is prevented from having a real impact on business operations, thus ensuring data security.
[0024] 5. Robust anomaly handling capabilities: Through intelligent degradation strategies, system robustness is improved and maintenance costs are reduced.
[0025] 6. Independently designed data structure: By being completely isolated from the data tracking data, it does not affect the existing data analysis system, and the data structure is optimized specifically for playback.
[0026] 7. Multidimensional business value: Improved customer service efficiency is reflected in the visual reproduction of user problems; product optimization and low operating costs are reflected in the accurate identification of churn points and experience issues; and technical troubleshooting is reflected in the rapid location of bugs and performance problems. Attached Figure Description
[0027] Figure 1 This is a timing logic diagram of the method of the present invention.
[0028] Figure 2 This is a schematic diagram of the module structure of the system of the present invention. Detailed Implementation
[0029] The present invention will now be further described with reference to the accompanying drawings.
[0030] See Figures 1-2 This embodiment provides a method and system for automatically tracking user behavior in cross-platform applications: I. The system in this embodiment is as follows: It includes: a client-side data collection module, used to collect user behavior events, initial page state information, and interface request information and report them to the server; a server-side processing module, used to process and store the collected data, collect interface logs, and manage H5 mirror pages; and a replay module, used to load mirror pages, restore page state, inject Mock data, and perform user behavior replay according to the event flow.
[0031] II. The method in this embodiment is as follows: 1. Data collection phase: The system automatically generates a unique, cross-platform identifier (track-id) for interactive controls during application compilation or runtime. It adopts the naming rule of "page name_component context_control semantics" and extracts semantic information from control properties, event handling function names, and control types through intelligent semantic inference. It automatically adds an incrementing index to the same type of controls that are rendered in a loop to ensure uniqueness.
[0032] In a preferred embodiment, the generation of the unique identifier is completed by automatically scanning elements and following preset rules during the compilation phase through a plugin. When the product is built, a track-id list and corresponding version information are generated and the track-id list and version information are registered in the version management service.
[0033] Subsequently, an event listener is installed and uses an event delegation mechanism to listen for user interactions at the global level. After capturing events such as clicks, inputs, and scrolling, key information such as track-id, timestamps, and event parameters is extracted. Sensitive information is automatically anonymized and encapsulated into a standardized data structure and added to an in-memory queue.
[0034] For interface data collection, the system adopts a distributed tracing architecture: a request interceptor injects a session identifier (sessionId) and a unique trace identifier (traceId) into each HTTP request header to achieve trace context propagation. The implementation details vary across different platforms. The web application automatically injects track-id during the build phase using a Babel compilation plugin. At runtime, it uses an event delegation mechanism to collect interactions and injects sessionId and traceId into the XMLHttpRequest / fetch request header through a request interceptor to achieve distributed tracing. The mini-program injects the track-id into WXML through a compilation plugin, and at runtime, it listens to the mini-program's lifecycle and events and injects the tracking identifier into the wx.request request header. The native app adds a track-id attribute to the view instance through runtime injection, collects interactions by hooking system event callbacks, and injects the tracking identifier into the network request header through URLProtocol / Interceptor.
[0035] The data collected from all three terminals is ultimately converted into a unified, standardized format to ensure consistency in subsequent processing.
[0036] Simultaneously, the request initiation behavior is reported as an event (including traceId, request URL, request method, and timestamp). The server records complete request and response data through structured log output and associates it with traceId. During the replay phase, the server log system is queried using sessionId and traceId to obtain interface mock data, thus achieving separation between lightweight front-end data collection and centralized server-side log management.
[0037] Collect initial state information of the page (global variables, state manager state, stored data, routing parameters) to establish a complete session context.
[0038] The collected event data is compressed using Gzip and then reported to the server through an independent channel according to a batch strategy (10 records or 3-second intervals). The Beacon API is used first to ensure high reliability. In case of failure, an exponential backoff retry mechanism is adopted. Finally, the data of failed data is stored in IndexedDB and automatically reported after the network is restored.
[0039] 2. Server-side processing: After receiving the reported data, the server decompresses and validates the format, and distributes it to a dedicated playback database (isolated from traditional event tracking data) according to the data type. A time-series database is used to store the event stream, and a unique sessionId is created for each session, along with multi-dimensional indexes (user ID, time range, page name, application version) to support fast querying.
[0040] Simultaneously, an independent log collection service is run, which collects interface logs of business services in real time through structured log pipelines (such as ELK, Loki and other log systems). The logs contain complete information such as traceId, sessionId, request URL, request method, request body, response body, response status code, and timestamp. The log database is stored with dual indexes based on traceId and sessionId, and supports quick retrieval of interface mock data through trace association queries during the playback stage.
[0041] Each time a business application is built and released, a corresponding H5 mirror page is generated synchronously. The mirror page retains the DOM structure and control identification system of the business page, removes unnecessary business logic code, and injects a replay SDK and a Mock interceptor. All track-ids are extracted to generate a manifest file for consistency verification. The mirror page and manifest file are organized by version number and uploaded to the CDN. Version information is registered in the version management database to support precise version query and compatible version query.
[0042] In a preferred embodiment, the project construction process also synchronously generates H5 image resources of the corresponding version and uploads them to the server. The server maintains the image resource address mapping relationship according to the version number, so that the playback stage can load the H5 image resources of the corresponding version according to the version number in the reported event.
[0043] In a preferred embodiment, when the data collection platform is a native App, the project building phase generates corresponding H5 image resources based on the native page structure, control identifiers, and page version information, so that user operations can be restored during the playback phase by combining the virtual page stack and lifecycle simulation mechanism.
[0044] 3. Replay stage: Mirror Page Loading and Environment Preparation: The replay process first queries the corresponding mirror page version based on the application version number and page name in the session data. An exact match strategy is used to find a mirror page with a completely identical version number. If no such page exists, a version downgrade strategy is initiated to find a compatible version or the latest version. The mirror page resources are loaded in a separate iframe or new window. The replay SDK is injected, and the session's event stream and initial page state data are loaded from the server. A consistency check is performed to verify that all track-ids in the event stream exist in the mirror page, generating an exception report to mark missing controls. Subsequently, a Mock interceptor is installed to intercept the page's network request API. When the page initiates a request, the corresponding interface response data (including complete log information such as request URL, method, request body, response body, and response status code) is retrieved from the server logs based on the traceId recorded in the event stream. This prevents the actual request from being sent and directly returns the historical response data recorded in the logs. Simultaneously, the initial page state is injected to restore global variables, state manager state, stored data, and routing parameters, ensuring that the page presents the same initial state as during data collection.
[0045] During the replay process, the replay engine dispatches events based on the user behavior events and interface logs driven by the loaded H5 image resources to simulate the pages generated by the user's actual operations.
[0046] Core replay mechanism implementation: The core of replay execution is to accurately reconstruct the user's operation sequence. The system constructs an event stream object by sorting the event array in ascending order of timestamps and establishes a multi-dimensional index of event ID, page name, and event type to support fast querying. Replay adopts a loop mode of processing events one by one to achieve precise control of the timeline. Then, the target control is located by track-id. If the element does not exist, a retry mechanism is initiated (up to 10 retries, each with a 100ms interval) to wait for the element to render asynchronously. If the retry fails, XPath positioning or fuzzy matching of controls with similar semantics is attempted as a fallback strategy. After successful positioning, the target control can be selectively highlighted (with a red border animation for 500ms) for easy observation of the replay progress.
[0047] Event dispatching executes different simulated operations based on the event type: click events dispatch the mousedown, mouseup, and click DOM events in sequence, carrying coordinate parameters; input events directly set the element's value property and dispatch the input and change events; scroll events set the element's scrollTop property and dispatch the scroll event; page navigation events call the routing API to switch pages.
[0048] After each event is dispatched, a double requestAnimationFrame is used to wait for the DOM to update (ensuring the browser has finished re-rendering) before proceeding to the next event.
[0049] The playback process supports full time control capabilities: play / pause (modify playback status flags), speed adjustment (modify the speed parameter, supporting multiple speeds such as 0.5x / 1x / 2x / 4x), jump to a specified time point (modify currentEventIndex and recalculate the waiting time), and single-step execution (automatically pause after executing an event). Users can operate these control functions in real time through the playback control panel.
[0050] Cross-platform page stack simulation mechanism: For playback data collected from mini-programs and native apps, the system implements a virtual page stack mechanism in the H5 environment to accurately reproduce multi-page navigation behavior. Lifecycle management is implemented through a global callback registry. When a business page registers a lifecycle callback via a hook, it checks whether the lifecycle has been triggered. If it has, the callback is immediately resent (the resentment mechanism avoids omissions caused by callback registration being later than lifecycle triggering). The browser's forward / back button achieves bidirectional synchronization with the virtual stack by listening to the popstate event. When the event is triggered, the target page information is extracted from event.state, the virtual stack is searched and the required pop level is calculated, and the corresponding operation is performed. The entire mechanism achieves a high degree of fidelity simulation of the page stack behavior of mini-programs / native apps in the H5 environment, with a page stack depth accuracy of 100% and a lifecycle trigger accuracy of >98%, ensuring the accuracy of cross-platform playback.
[0051] The above are merely preferred embodiments of the present invention, intended only to aid in understanding the method and core ideas of this application. The scope of protection of the present invention is not limited to the above embodiments; all technical solutions falling within the scope of the present invention's concept are within its protection. It should be noted that for those skilled in the art, any equivalent substitutions, modifications, improvements, and refinements made without departing from the principles of the present invention should also be considered within the scope of protection of the present invention.
[0052] This invention comprehensively addresses the shortcomings of existing user behavior analysis and session replay technologies in terms of cross-platform consistency, control uniqueness maintenance, replay accuracy, data obfuscation, and side effect control. Through a unified track-id system and standardized event protocol, it achieves unified collection and replay across mini-programs, native apps, and the web. Furthermore, by utilizing a mock data interception mechanism and independently designed data structures, it avoids impacting real business operations and obfuscation with event tracking data.
Claims
1. A method for automatically tracking user behavior in cross-platform applications, characterized in that, Includes the following steps: S1, Data Acquisition Phase: S1-1 automatically generates a unique cross-platform identifier track-id for interactive controls during application compilation or runtime. It adopts the naming rule of page name_component context_control semantics and extracts semantic information from control attributes, event handling function names, and control types through intelligent semantic inference. It automatically adds an incrementing index to the same type of controls that are rendered in a loop to ensure uniqueness. S1-2, Install an event listener and use an event delegation mechanism to listen to user interactions at the global level. After capturing user behavior events, extract the unique identifier track-id, timestamp, and key information of event parameters. Perform automatic desensitization processing on sensitive information, encapsulate it into a standardized data structure and add it to the memory queue. S1-3 uses a distributed tracing architecture to collect interface data: S1-3-1 injects the session identifier (sessionId) and the unique trace identifier (traceId) into each HTTP request header through a request interceptor, thereby enabling context propagation of the trace identifier. S1-3-2, At the same time, the request initiation behavior is reported as an event point, and the server records the complete request and response data through structured log output and associates it with the unique trace identifier traceId; S1-3-3, During the replay phase, the session identifier sessionId and the unique trace identifier traceId are used to query the server-side log system to obtain the interface's Mock data, which is used to separate the lightweight collection of the front end from the centralized log management of the server. S1-4, Collect initial state information of the collection page to establish a complete session context; S1-5, the collected event data is compressed and then reported to the server through an independent channel according to the batch strategy; S2, Server-side processing stage: S2-1: After receiving the reported data, the server decompresses and verifies the format. Based on the data type, it distributes the data to a dedicated playback database in a way that isolates it from traditional data tracking. The event stream is stored in a time-series database. A unique session identifier (sessionId) is created for each session, and a multi-dimensional index is built to support fast querying. S2-2, The server also runs an independent log collection service, which collects interface logs of business services in real time through a structured log pipeline; S2-3, each time the server builds and releases a version, it synchronously generates the corresponding version of the H5 image page. The image page retains the DOM structure and control identification system of the business page, removes unnecessary business logic code, and injects the replay SDK and Mock interceptor. It extracts all the unique identifier track-id to generate a manifest file for consistency verification. The image page and manifest file are organized by version number and uploaded to CDN. The version information is registered in the version management database to support precise version query and compatible version query. S3, Replay Phase: S3-1, Mirror Page Loading and Environment Preparation: S3-1-1, Query the version of the corresponding mirror page based on the application version number and page name in the session data, and use the precise version query matching strategy to find a mirror page with the same version number. If it does not exist, start the version downgrade strategy to find the compatible version or the latest version. S3-1-2, Load the resources of the mirror page in an independent iframe or new window, inject the playback SDK and load the event stream of the session and the data of the initial state of the page from the server, perform a consistency check to check whether all the unique identifiers track-id in the event stream exist in the mirror page, and generate an exception report to mark missing controls; S3-1-3, Install a Mock interceptor to hijack the page's network request API. When the page makes a request, based on the unique trace identifier traceId recorded in the event stream, query the API through the server log to obtain the corresponding interface response data, prevent the real request from being sent, and directly return the historical response data recorded in the log. At the same time, inject the page's initial state to restore global variables, state manager state, stored data, and routing parameters to ensure that the page presents the same initial state as when it was collected. S3-2, Core replay mechanism implementation: S3-2-1 constructs an event stream object by sorting the event array in ascending order of timestamps and establishes a multi-dimensional index of event ID, page name, and event type to support fast querying; S3-2-2 adopts a loop mode of event-by-event processing to achieve precise control of the timeline. The target control is located by the unique tracking identifier track-id. If the element does not exist, a retry mechanism is started to wait for the element to be rendered asynchronously. If the retry fails, XPath positioning or fuzzy matching of similar semantic controls is attempted as a fallback strategy. After successful positioning, the target control is selectively highlighted to facilitate observation of the playback progress. S3-2-3, Event dispatch executes different simulation operations based on the event type: Click events dispatch the mousedown, mouseup, and click DOM events sequentially, carrying coordinate parameters; input events directly set the element's value property and dispatch the input and change events; scroll events set the element's scrollTop property and dispatch the scroll event; page navigation events call the routing API to switch pages; after each event is dispatched, a double requestAnimationFrame is used to wait for the DOM to update completely, ensuring that the browser has finished re-rendering, before continuing to the next event; S3-2-4, the playback process supports full time control capabilities: including play / pause, speed up playback, jump to a specified time point, and single-step execution. Users can operate these control functions in real time through the playback control panel. S3-3, Cross-Platform Page Stack Simulation Mechanism: For playback data collected from mini-programs and native apps, a virtual page stack mechanism is implemented in the H5 environment to accurately reproduce multi-page navigation behavior. Specifically: Lifecycle management is implemented through a global callback registry. When a business page registers a lifecycle callback via a hook, it checks whether the lifecycle has been triggered. If it has, the callback is immediately resent to avoid omissions caused by the callback registration being later than the lifecycle trigger. The browser's forward / back button achieves bidirectional synchronization with the virtual stack by listening to the popstate event. When the event is triggered, the target page information is extracted from event.state, the virtual stack is searched and the required number of layers to be popped is calculated, and the corresponding operation is performed.
2. The cross-platform application user behavior automatic tracking method of claim 1, wherein, The user behavior events include clicks, input, and scrolling; the content to be reported in S1-3-2 includes the unique trace identifier (traceId), request URL, request method, and timestamp; the initial state information in S1-4 includes global variables, state manager state, stored data, and routing parameters; the multi-dimensional index in S2-1 includes user ID, time range, page name, and application version; the interface response data in S3-1-3 is complete log information, including request URL, method, request body, response body, and response status code; the retry mechanism in S3-2-2 retries a maximum of 10 times, with each retry interval of 100ms. 3.The cross-platform application user behavior automatic tracking method according to claim 2, characterized in that, The upload process in S1-5 uses the Beacon API to ensure high reliability; if the upload fails, an exponential backoff retry mechanism is used to store the ultimately failed data in the local database IndexedDB and automatically report it after the network recovers.
4. The cross-platform application user behavior automatic tracking method of claim 3, wherein, The interface log in S2-2 contains complete information including traceId, sessionId, request URL, request method, request body, response body, response status code, and timestamp. It is stored in the log database with a dual index based on the unique trace identifier traceId and the session identifier sessionId, which supports quick retrieval of interface Mock data by using trace identifier association query during the playback stage.
5. The cross-platform application user behavior automatic tracking method according to claim 4, characterized in that, In step S1-3-1, when the data collection platform is a mini-program, a unique identifier `track-id` is injected into WXML through a compilation plugin. At runtime, the mini-program's lifecycle and events are monitored, and the tracking identifier is injected into the `wx.request` request header. When the data collection platform is a native app, a unique identifier `track-id` is added to the view instance through runtime injection. System event callbacks are hooked to collect interactions, and the tracking identifier is injected into the network request header via `URLProtocol / Interceptor`. When the data collection platform is a web application, a unique identifier `track-id` is automatically injected during the build phase through a Babel compilation plugin. At runtime, an event delegation mechanism is used to collect interactions, and `sessionId` and `traceId` are injected into the XMLHttpRequest / fetch request header via a request interceptor to achieve distributed tracing. The data collected from the mini-program, the app, and the web application is ultimately converted into a unified standardized format to ensure consistency in subsequent processing.
6. The cross-platform application user behavior automatic tracking method according to claim 5, characterized in that, When the data collection platform is a native app, the project build phase generates H5 image resources of the corresponding version based on the native page structure, control identifiers and page version information. During the playback phase, the H5 image resources are driven to perform event dispatch through a virtual page stack and lifecycle simulation mechanism to restore the user operation effect of the native app.
7. The cross-platform application user behavior automatic tracking method according to claim 1, characterized in that, In the compilation phase of S1-1, the plugin automatically scans elements and generates unique identifiers (track-ids) according to preset rules. When the artifact is built, a list of track-ids and corresponding version information are generated, and the list of track-ids and version information are registered with the version management service.
8. The cross-platform application user behavior automatic tracking method according to claim 7, characterized in that, In the project construction phase of S2-3, H5 image resources of the corresponding version are also generated and uploaded to the server. The server maintains the image resource address mapping relationship based on the version number.
9. The cross-platform application user behavior automatic tracking method according to claim 8, characterized in that, In the playback phase of S3-1-1, the corresponding version of the H5 image resource is loaded according to the version number in the reported event, and the H5 image resource is driven to perform event dispatch based on user behavior events and interface logs.
10. A cross-platform application user behavior automatic tracking system, characterized in that, include: Client-side data acquisition module, server-side processing module, and playback module; The client-side data collection module is used to collect user behavior events, page initial state information, and interface request information and report them to the server. The server-side processing module is used to process and store the collected data, collect interface logs, and manage H5 mirror pages. The replay module is used to load mirror pages, restore page state, inject Mock data, and perform user behavior replay according to the event stream.