Data acquisition method and device, equipment and medium

By monitoring and reporting the data of API requests and static resource requests on the Web side, the problem of difficulty in collecting data after the Web product is launched is solved, the request situation is understood and performance optimized, and the user experience is improved.

CN118784512AActive Publication Date: 2024-10-15JINAN INSPUR DATA TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202410890924.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-03
Publication Date
2024-10-15
Estimated Expiration
2044-07-03

AI Technical Summary

Technical Problem

It is difficult for existing web products to collect data related to client resource requests in a timely and reasonable manner after they go online, resulting in the inability to proactively detect problems such as slow requests, slow rendering, or abnormal responses. Moreover, the lack of data support makes it difficult to analyze problems in different user scenarios.

Method used

Provide a data collection method that monitors multiple types of user requests, including API requests and static resource requests, obtains response body content and related information by injecting events into built-in functions, and reports data to the server, using APIs such as PerformanceObserver and GetEntries. Perform data collection and filtering.

Benefits of technology

Without intruding into user business, it helps developers understand API request situations, optimize performance, provide better user experience, and solve data collection and analysis problems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118784512A_ABST
    Figure CN118784512A_ABST
Patent Text Reader

Abstract

The invention provides a data acquisition method, relates to the technical field of data processing, is applied to a web end, and can monitor an API request sent by a user when the user accesses a browser of the web end, modify a built-in function responding to the API request, inject a first event into the built-in function, and acquire data through the first event. According to the method, the response body content is recorded before the API request is sent, the situation that only the response related information of the API request can be collected is avoided, and by obtaining the response body information and the response related information, developers of web browser products can be helped to know the situation of the API request, optimize performance, solve problems and provide better user experience on the premise that user services are not invaded.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a data acquisition method, device, equipment and medium. Background Art

[0002] The use of browsers to access Web products is affected by many factors, such as deployment server configuration, user client configuration, network conditions, user traffic, program coding, architecture design, and many other factors. After most Web products are released online, it is impossible to collect data related to client resource requests in a timely and reasonable manner. If the client has problems such as slow requests, slow rendering, slow responses, or abnormal responses, the product service provider cannot actively perceive them. Even if you know that there is a problem with the product through other feedback methods, it is difficult to track and solve it because there is no timely record and storage of product-related resource request result data.

[0003] In addition, most Web products do not collect web request data after they go online, resulting in the product side being unable to perceive some problems in different scenarios for different users. Even if feedback is received offline, relevant analysis cannot be performed due to the lack of relevant data support. Summary of the invention

[0004] In view of this, embodiments of the present application provide a data collection method, apparatus, device and medium to overcome the above problems or at least partially solve the above problems.

[0005] A first aspect of an embodiment of the present application provides a data collection method, which is applied to a web terminal, and the method includes:

[0006] Monitoring multiple types of requests from users on the web terminal, wherein the multiple types of requests include at least API requests;

[0007] In the built-in function that responds to the API request, inject a first event, where the first event is used to obtain the response body content of the API request;

[0008] Based on the API request, obtaining first data of the API request, the first data including response related information and the response body content;

[0009] Report the first data to the server.

[0010] Optionally, the multiple types of requests further include a static resource request, the static resource request includes a first static resource request and a second static resource request, and the method further includes:

[0011] Before the first acquisition script takes effect, the second data requested by the first static resource is obtained through GetEntries;

[0012] After the first acquisition script takes effect, a second static resource request is obtained through PerformanceObserver, and second data of the second static resource request is obtained;

[0013] The static resource request is obtained by filtering multiple types of requests from users of the web terminal according to a first preset screening strategy, and the second data includes second URL information, second time information, and second response size information;

[0014] Report the second data to the server.

[0015] Optionally, injecting a first event into a built-in function that responds to the API request includes:

[0016] Define a primitive function, and assign the primitive function to the value of the built-in function;

[0017] Define a new function, assign the new function a value of the built-in function, and add the first event to the new function to obtain an updated built-in function;

[0018] The obtaining the first data of the API request includes:

[0019] According to a second preset screening strategy, multiple types of requests from the user of the web terminal are filtered to obtain the API request;

[0020] Storing the response-related information of the API request in a predefined first local cache object, the response-related information at least including the first request URL, the first time information, and the first response body size information of the API request;

[0021] Determine whether the response body content of the API request is received through the callback function of the first event injected into the update built-in function;

[0022] After the response body content of the API request is received, the response body content is stored in a predefined second local cache object, wherein the response body content at least includes first URL information, HTTP status code, business error code, and business error information.

[0023] Optionally, before reporting the first data to the server, the method further includes:

[0024] Traversing multiple pieces of response related information in the first local cache object, and obtaining multiple first request URLs of the API request from the response related information;

[0025] Based on the first request URL, taking out multiple response body contents matching the multiple first request URLs from the second local cache object;

[0026] Merging the multiple response body contents and the response related information according to the matching relationship between the first request URL, and storing them in the first local cache object to obtain third data of the API request;

[0027] The reporting the first data to the server includes: reporting third data in the first local cache object.

[0028] Optionally, the method further comprises:

[0029] storing the second data of the first static resource request in a predefined third local cache object;

[0030] Storing the second data of the second static resource request in a predefined fourth local cache object, wherein the second data at least includes: a second request URL, second time information, and second response body size information of the static resource request;

[0031] Before storing the first second data of the second static resource request into a predefined fourth local cache object, determining, based on the second request URL in the first second data, a subscript of the first static resource request in the third local cache object that matches the second request URL in the first second data;

[0032] And intercept the second data of the first static resource request before the subscript in the third local cache object, and add the second data of the first static resource request before the subscript to the fourth local cache object.

[0033] Optionally, reporting the second data to the server includes:

[0034] Detecting whether the web terminal triggers the following preset events, wherein the preset events include at least one of the following: uninstallation, closing, and view change;

[0035] When the preset event is triggered, the second data is reported.

[0036] Optionally, reporting the second data to the server includes:

[0037] When the priority of the current task of the web terminal is lower than the priority of the data reporting task of reporting the second data to the server, the first function is called to report the second data.

[0038] A second aspect of an embodiment of the present application provides a data collection device, which is applied to a web terminal, and the device includes:

[0039] A monitoring module, used to monitor multiple types of requests from users on the web terminal, wherein the multiple types of requests include at least API requests;

[0040] A response body content acquisition module, used to inject a first event into a built-in function that responds to the API request, wherein the first event is used to obtain the response body content of the API request;

[0041] A first data acquisition module, configured to acquire first data of the API request based on the API request, wherein the first data includes response related information and the response body content;

[0042] A data reporting module is used to report the first data to the server.

[0043] A third aspect of an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the data collection method as described in the first aspect.

[0044] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the data collection method as described in the first aspect is implemented.

[0045] Beneficial effects of this application:

[0046] An embodiment of the present application provides a data collection method, apparatus, device and medium, which are applied to a web side. The method includes: monitoring multiple types of requests from users on the web side, wherein the multiple types of requests include at least API requests; injecting a first event into a built-in function that responds to the API request, wherein the first event is used to obtain the response body content of the API request; based on the API request, obtaining first data of the API request, wherein the first data includes response-related information and the response body content; and reporting the first data to a server.

[0047] When the user accesses the web browser, it can monitor the API request issued by the user, and by modifying the built-in function that responds to the API request, inject the first event into the built-in function, and through the first event, record the response body content before sending the API request, so as to avoid the situation that only the response information of the API request can be collected. By obtaining the response body information and the response related information, it can help the developers of the web browser product understand the situation of the API request, optimize the performance, solve the problem and provide a better user experience without intruding the user's business. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application.

[0049] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the description of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0050] Figure 1 It is a flowchart of a data collection method shown in an embodiment of the present application;

[0051] Figure 2 It is a schematic diagram of data collection for static resource requests in a data collection method provided in an embodiment of the present application;

[0052] Figure 3 It is a schematic diagram of obtaining the content of the response body of an API request in a data collection method provided in an embodiment of the present application;

[0053] Figure 4 It is a schematic diagram of obtaining response related information in a data collection method provided in an embodiment of the present application;

[0054] Figure 5 is a schematic diagram of obtaining third data in a data collection method provided in an embodiment of the present application;

[0055] Figure 6 It is a schematic diagram of a framework of a data acquisition device shown in an embodiment of the present application. DETAILED DESCRIPTION

[0056] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application may be combined with each other.

[0057] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0058] refer to Figure 1 , Figure 1 FIG. 1 is a flow chart of a data collection method according to an embodiment of the present application. Figure 1 As shown, the embodiment of the present application provides a data collection method, which is applied to a web terminal and includes the following steps:

[0059] In step S101, multiple types of requests from the user on the web terminal are monitored, and the multiple types of requests at least include API requests;

[0060] In step S102, a first event is injected into a built-in function that responds to the API request, where the first event is used to obtain the response body content of the API request;

[0061] In step S103, based on the API request, first data of the API request is obtained, where the first data includes response related information and the response body content;

[0062] In step S104, the first data is reported to the server.

[0063] First, in step S101, when a user starts to access a browser on the web side, PerformanceObserver provided by Performance is called to monitor various types of requests, including monitoring and collecting API requests.

[0064] PerformanceObserver is part of the Web API. PerformanceObserver monitors various types of requests issued by users on the web browser. PerformanceObserver is a JavaScript API used to monitor browser performance indicators. It collects and observes performance-related information asynchronously so that web browser developers can better understand and optimize the performance of their applications.

[0065] Among them, the various types of requests include API (application programming interface) requests, static resource requests, file upload requests, AJAX (Asynchronous JavaScript and XML) requests, JSONP (JSON with Padding) requests, WebSocket (a full-duplex communication protocol) requests, OPTIONS requests, etc.

[0066] Further, in step S102, before the API request is issued, a first event is injected into the built-in function (i.e., XMLHttpRequest object) that responds to the API request issued by the user, wherein the XMLHttpRequest object is a technology for initiating HTTP requests in a browser and is used for data interaction with a server, and the first event is used to obtain the response body content of the API request, such as a response code, business information, etc.

[0067] As an example, the first event is a readystatechange event. When the readyState attribute of the XMLHttpRequest object changes, the readystatechange event is triggered.

[0068] Further, in step S103, for multiple API requests issued by the user, the first data of the API request is obtained. The first data of each API request includes two parts: response related information and response body content, wherein the response body content can be obtained through the first event (such as the readystatechange event), and the response related information can be obtained through PerformanceObserver.

[0069] Finally, in step S104, after obtaining the first data containing response related information and response body content in multiple API requests, the first data is sent to the server corresponding to the developer of the web browser to facilitate the developer's subsequent performance problem analysis and tracking of the web browser product.

[0070] Through the above embodiments, it is possible to monitor the API requests issued by the user when the user accesses the browser on the web side, and by modifying the built-in function that responds to the API request, inject a first event into the built-in function. Through the first event, the response body content is recorded before sending the API request, thereby avoiding the situation where only the response-related information of the API request can be collected. By obtaining the response body information and the response-related information, it is possible to help the developers of web browser products understand the situation of the API request, optimize performance, solve problems, and provide a better user experience without intruding on the user's business.

[0071] Optionally, the multiple types of requests further include a static resource request, the static resource request includes a first static resource request and a second static resource request, and the method further includes:

[0072] Before the first acquisition script takes effect, the second data requested by the first static resource is obtained through GetEntries;

[0073] After the first acquisition script takes effect, a second static resource request is obtained through PerformanceObserver, and second data of the second static resource request is obtained;

[0074] The static resource request is obtained by filtering multiple types of requests from users of the web terminal according to a first preset screening strategy, and the second data includes second URL information, second time information, and second response size information;

[0075] Report the second data to the server.

[0076] Figure 2 It is a schematic diagram of data collection for static resource requests in a data collection method provided in an embodiment of the present application.

[0077] Specifically, in one embodiment, Figure 2 As shown, when the user starts to access the browser on the web side, while listening to various types of requests by calling the PerformanceObserver provided by Performance, it also includes listening to static resource requests, wherein the static resource request includes a first static resource request and a second static resource request, and the static resource request is obtained by filtering the various types of user requests obtained by the callback function of PerformanceObserver according to a first preset filtering strategy.

[0078] Among them, the first preset screening strategy is pre-set according to the user's business scenario. For example, when it is necessary to filter JS requests in static resource requests, the regular expression / (\.js)(\?.*)?$ / can be used to filter out requests matching .js and .js? in the URLs of all types of requests to obtain JS requests.

[0079] When a user accesses a web service through a web browser, the first collection script for executing the data collection task corresponding to the static resource request will be loaded on the web. Since there is no guarantee that the first collection script is the first static resource loaded, there is a situation where some static resources may be loaded before the first collection script takes effect. Therefore, the embodiment of the present application adopts the first static resource request and the second static resource request to distinguish the static resource requests. The first static resource request is a static resource request before the first collection script takes effect, and the second static resource request is a static resource request after the first collection script takes effect.

[0080] Before the first collection script takes effect, the second data of the first static resource request is obtained through GetEntries provided by Performance; because the GetEntries method has a number limit for resource statistics of the resources type, and can only count a maximum of 245 resources of the resources type, therefore, after the first collection script takes effect, it is necessary to obtain the second static resource request through PerformanceObserver provided by Performance, and obtain the second data of the second static resource request, the second data is the static resource, and the second data includes the second URL information, second time information, and second response size information of the static resource request, such as:

[0081] The second URL information is: the URL of the static resource request;

[0082] Second time information includes:

[0083] fetchStart: The time when the web browser is ready to initiate a static resource request;

[0084] domainLookupStart: Returns the time when the DNS domain name query starts;

[0085] domainLookupEnd: Returns the time when the DNS domain name query ends;

[0086] connectStart: the time when the web browser TCP establishes a connection;

[0087] connectEnd: the time when the web browser TCP connection is successful;

[0088] requestStart: the time when the web browser sends an HTTP request to the server;

[0089] responseStart: the time when the web browser receives the first byte from the server;

[0090] responseEnd: the time when the web browser receives the last byte from the server;

[0091] The second response size information is:

[0092] decodeBodySize: The response body size of the static resource request.

[0093] After acquiring the second data, the second data is reported to the server.

[0094] Through the above embodiment, it is possible to monitor and collect static resource requests through GetEntries and PerformanceObserver provided by Performance, and obtain the second data of all static resource requests through the customized first preset screening strategy.

[0095] Optionally, the method further comprises:

[0096] storing the second data of the first static resource request in a predefined third local cache object;

[0097] Storing the second data of the second static resource request in a predefined fourth local cache object, wherein the second data at least includes: a second request URL, second time information, and second response body size information of the static resource request;

[0098] Before storing the first second data of the second static resource request into a predefined fourth local cache object, determining, based on the second request URL in the first second data, a subscript of the first static resource request in the third local cache object that matches the second request URL in the first second data;

[0099] And intercept the second data of the first static resource request before the subscript in the third local cache object, and add the second data of the first static resource request before the subscript to the fourth local cache object.

[0100] Specifically, Figure 2 As shown, after obtaining the second data of the first static resource request, the second data of the first static resource request needs to be stored in a predefined third local cache object, and the second data of the first static resource request needs to be stored in a predefined fourth local cache object. The third local cache object and the fourth local cache object are both the user's local cache.

[0101] Furthermore, before storing the first second data of the second static resource request into the predefined fourth local cache object, it is necessary to determine the second request URL in the first second data, and determine the index of the first static resource request that matches the second request URL in the first second data in the third local cache object;

[0102] And in the third local cache object, the second data of the first static resource request before the subscript is intercepted, and the second data of the first static resource request before the subscript is added to the fourth local cache object.

[0103] Through the above embodiment, after the first acquisition script takes effect, before storing the second data of the second static resource request in the fourth local cache object, the second data of the first static resource request obtained by GetEntries in the third local cache object can be transferred to the fourth local cache object.

[0104] Figure 3 is a schematic diagram of obtaining the content of the response body of an API request in a data collection method provided in an embodiment of the present application, such as Figure 3 shown.

[0105] Optionally, step S102 includes:

[0106] Define a primitive function, and assign the primitive function to the value of the built-in function;

[0107] Define a new function, assign the new function a value of the built-in function, and add the first event to the new function to obtain an updated built-in function;

[0108] The obtaining the first data of the API request includes:

[0109] According to a second preset screening strategy, multiple types of requests from the user of the web terminal are filtered to obtain the API request;

[0110] Storing the response-related information of the API request in a predefined first local cache object, the response-related information at least including the first request URL, the first time information, and the first response body size information of the API request;

[0111] Determine whether the response body content of the API request is received through the callback function of the first event injected into the update built-in function;

[0112] After the response body content of the API request is received, the response body content is stored in a predefined second local cache object, wherein the response body content at least includes first URL information, HTTP status code, business error code, and business error information.

[0113] Specifically, in one embodiment, an original function named originOpen is first defined, and the value of the built-in function (the value of the built-in function is: XMLHttpRequest.prototype.open) is assigned to the original function named originOpen, thereby saving the Open function of the XMLHttpRequest object. Further, a new function named newOriginOpen is defined, and the value of the built-in function is also assigned to the new function named newOriginOpen. In the XMLHttpRequest instance that responds to the current API request, a listener for the readystatechange event (i.e., the first event) is added. In the callback function summary of the readystatechange event, it is possible to check whether the status of the XMLHttpRequest instance is reception completed.

[0114] Among them, the first event (readystatechange event) will be triggered in the following stages:

[0115] The status code is 0 (UNSENT): The API request is not initialized and the open method has not been called.

[0116] Status code is 1 (OPENED): The API request has been initiated, but the send method has not been called yet.

[0117] Status code is 2 (HEADERS_RECEIVED): The send method has been called and the headers and status are available.

[0118] The status code is 3 (LOADING): receiving response data.

[0119] Status code is 4 (DONE): Response data reception is complete and subsequent processing can be performed.

[0120] Therefore, when the status code is 4, it indicates that the reception is confirmed to be complete. At this time, the response body content can be obtained, and the original function named originOpen can be called to execute.

[0121] Figure 4 is a schematic diagram of obtaining response related information in a data collection method provided in an embodiment of the present application, such as Figure 4 shown.

[0122] Further, according to the second preset screening strategy, multiple types of requests from users on the web side are filtered to obtain multiple API requests, and response-related information of the API requests is stored in a predefined first local cache object, wherein the response-related information at least includes a first request URL, first time information, and first response body size information of the API request;

[0123] The response related information includes the first URL information, the first time information, and the first response body size information, such as:

[0124] The first URL information is: the URL of the API request;

[0125] First-hand information includes:

[0126] fetchStart: The time when the web browser is ready to initiate an API request;

[0127] domainLookupStart: Returns the time when the DNS domain name query starts;

[0128] domainLookupEnd: Returns the time when the DNS domain name query ends;

[0129] connectStart: the time when the web browser TCP establishes a connection;

[0130] connectEnd: the time when the web browser TCP connection is successful;

[0131] requestStart: the time when the web browser sends an http request to the server;

[0132] responseStart: the time when the web browser receives the first byte from the server;

[0133] responseEnd: the time when the web browser receives the last byte from the server;

[0134] The first response size information is:

[0135] decodeBodySize: The response body size of the API request.

[0136] Furthermore, by updating the callback function of the first event injected in the built-in function, it is determined whether the response body content of the API request is received; when the response body content of the API request is received, the response body content is stored in a predefined second local cache object, wherein the response body content includes at least the first URL information, the HTTP status code, the business error code, and the business error information, and the first local cache object and the second local cache object are the user's local cache.

[0137] Through the above embodiment, all API requests can be screened out using the preset second preset screening strategy, and the first data of the API requests can be cached locally.

[0138] Optionally, before step S104, the method further includes:

[0139] Traversing multiple pieces of response related information in the first local cache object, and obtaining multiple first request URLs of the API request from the response related information;

[0140] Based on the first request URL, taking out multiple response body contents matching the multiple first request URLs from the second local cache object;

[0141] Merging the multiple response body contents and the response related information according to the matching relationship between the first request URL, and storing them in the first local cache object to obtain third data of the API request;

[0142] The reporting the first data to the server includes: reporting third data in the first local cache object.

[0143] Figure 5 is a schematic diagram of obtaining third data in a data collection method provided in an embodiment of the present application, such as Figure 5 shown.

[0144] Specifically, in one embodiment, since the first data that needs to be collected for the API request includes two parts: response-related information and response body content, which are respectively stored in a first local cache object and a second local cache object, it is necessary to merge the two parts into the same local cache before reporting the first data to the server.

[0145] Therefore, firstly, the multiple response-related information that need to be reported in the first local cache object are traversed, and the first URL information in each response-related information that needs to be reported is determined from the multiple response-related information that need to be reported, and multiple first URL information are obtained. According to the multiple first URL information obtained, the response body content corresponding to each first URL information in the multiple first URL information is found in the second local cache object, and the response body content and response-related information corresponding to the same first URL information are merged, that is, the response body content is added to the corresponding response-related information, and stored in the first local cache object to obtain third data, which is the multiple data that have been combined with the response-related information and the response body content.

[0146] Finally, the third data is uploaded to the server.

[0147] Through the above embodiment, before uploading the first data to the server, the response related information and response body content in the first data that the API request needs to collect are merged according to the first URL information to obtain the third data, and the third data is uploaded to the server.

[0148] Optionally, the method further comprises:

[0149] In order to prevent the user from having too much data in the local cache, the first data length of the third data in the first local cache object and the first data length of the second data in the fourth local cache object can be monitored in real time. When it is found that the first data length or the second data length is greater than the preset data length threshold, a preset proportion of the second data or the third data is taken out from the first local cache object or the fourth local cache object, respectively, and uploaded to the server.

[0150] As an example, the preset data length threshold is 100. When the first data length or the second data length reaches 100, the data with subscripts 0 to 50 are taken out from the first local cache object or the fourth local cache object and reported to the server, and the second data or the third data in the first local cache object or the fourth local cache object that has been uploaded to the server is periodically deleted.

[0151] Through the above embodiments, data can be uploaded through a quantitative upload mechanism without affecting the performance of the user's web browser, and the local cache can be cleaned up after uploading to avoid occupying a large amount of user's local cache space.

[0152] Optionally, reporting the second data to the server includes:

[0153] Detecting whether the web terminal triggers the following preset events, wherein the preset events include at least one of the following: uninstallation, closing, and view change;

[0154] When the preset event is triggered, the second data is reported.

[0155] Specifically, the data reporting process is divided into multiple situations, and different reporting methods are required for different situations. When the user leaves the page of the browser on the web end currently visited, such as: the user cannot see the current website on the display due to minimization or switching views, at this time, the second data and the third data can be reported through the visibility event trigger; when the user closes the current browser Tab or the entire browser is closed, at this time, the second data and the third data can be reported through the unload event monitoring.

[0156] Through the above embodiments, it can be ensured that when the user leaves or closes the page, the data can be reported to the server in time, thereby avoiding data loss and delayed reporting.

[0157] Optionally, reporting the second data to the server includes:

[0158] When the priority of the current task of the web terminal is lower than the priority of the data reporting task of reporting the second data to the server, the first function is called to report the second data.

[0159] Specifically, in one embodiment, when the priority of the current task on the web side is lower than the priority of the data reporting task for reporting the second data to the server, it is determined that the browser on the web side is in an idle state at this time, and the first function (such as the requestIdlecallback function) can be called at this time to report the second data or the third data.

[0160] Furthermore, when XMLHttpRequest is unavailable, the built-in function of the browser (Navigator.sendBeacon function) can be called as an independent process task of the browser to complete the data reporting, thereby ensuring that the second data or the third data can be successfully reported to the server without delaying the normal closing behavior of the browser.

[0161] Through the above embodiments, the data reporting process can be performed in an idle state, and when XMLHttpRequest is unavailable, the built-in function of the browser (Navigator.sendBeacon function) is called to complete the data reporting.

[0162] refer to Figure 6 , Figure 6 is a schematic diagram of a data acquisition device according to an embodiment of the present application. Figure 6As shown, an embodiment of the present application provides a data collection device, which is applied to a web terminal, and the device includes:

[0163] A monitoring module 11, configured to monitor various types of requests from users on the web terminal, wherein the various types of requests include at least API requests;

[0164] A response body content acquisition module 12, used to inject a first event into a built-in function that responds to the API request, wherein the first event is used to obtain the response body content of the API request;

[0165] A first data acquisition module 13 is used to acquire first data of the API request based on the API request, where the first data includes response related information and the response body content;

[0166] The data reporting module 14 is used to report the first data to the server.

[0167] Optionally, the multiple types of requests further include a static resource request, the static resource request includes a first static resource request and a second static resource request, and the apparatus further includes;

[0168] The second data acquisition module of the first static resource request is used to acquire the second data of the first static resource request through GetEntries before the first acquisition script takes effect;

[0169] A second data acquisition module for a second static resource request, configured to acquire the second static resource request through PerformanceObserver after the first acquisition script takes effect, and acquire second data of the second static resource request;

[0170] The static resource request is obtained by filtering multiple types of requests from users of the web terminal according to a first preset screening strategy, and the second data includes second URL information, second time information, and second response size information;

[0171] The second data reporting module is used to report the second data to the server.

[0172] Optionally, the response body content acquisition module includes:

[0173] A first definition module is used to define a primitive function and assign the primitive function to a value of a built-in function;

[0174] A second definition module is used to define a new function, assign the new function a value of the built-in function, and add the first event to the new function to obtain an updated built-in function;

[0175] The first data acquisition module 13 includes:

[0176] A first filtering module, configured to filter multiple types of requests from the user of the web terminal according to a second preset filtering strategy to obtain the API request;

[0177] A response related information storage module, used to store the response related information of the API request in a predefined first local cache object, the response related information at least including the first request URL, first time information, and first response body size information of the API request;

[0178] A determination module, used to determine whether the response body content of the API request is received through the callback function of the first event injected in the update built-in function;

[0179] A response body content storage module is used to store the response body content of the API request in a predefined second local cache object after the response body content is received, wherein the response body content includes at least first URL information, HTTP status code, business error code, and business error information.

[0180] Optionally, the device further comprises:

[0181] A traversal module, used for traversing a plurality of pieces of response-related information in the first local cache object before reporting the first data to the server, and obtaining a plurality of first request URLs of the API request from the response-related information;

[0182] A fetching module, configured to fetch, based on the first request URL, a plurality of response body contents matching the plurality of first request URLs from the second local cache object;

[0183] a merging module, configured to merge the multiple response body contents and the response related information according to a matching relationship between the first request URL, and store the merged information in the first local cache object to obtain third data of the API request;

[0184] The first data reporting module is used to report the first data to the server, including: reporting the third data in the first local cache object.

[0185] Optionally, the device further comprises:

[0186] A second data storage module for the first static resource request is used to store the second data of the first static resource request into a predefined third local cache object;

[0187] A second data storage module for a second static resource request, used for storing the second data of the second static resource request into a predefined fourth local cache object, wherein the second data at least includes: a second request URL, second time information, and second response body size information of the static resource request;

[0188] A matching module, used for determining, in the third local cache object, a subscript of a first static resource request that matches the second request URL in the first second data, before storing the first second data of the second static resource request into a predefined fourth local cache object, based on the second request URL in the first second data;

[0189] The interception module is used to intercept the second data of the first static resource request before the subscript in the third local cache object, and add the second data of the first static resource request before the subscript to the fourth local cache object.

[0190] Optionally, the second data reporting module includes:

[0191] A detection module, used to detect whether the web terminal triggers the following preset events, wherein the preset events include at least one of the following: uninstallation, closing, and view change;

[0192] A trigger reporting module is used to report the second data when the preset event is triggered.

[0193] Optionally, the second data reporting module includes:

[0194] The second data reporting unit is used to call the first function to report the second data when the priority of the current task of the web terminal is lower than the priority of the data reporting task of reporting the second data to the server.

[0195] Based on the same inventive concept, another embodiment of the present application further provides an electronic device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the data collection method as described in any of the above embodiments.

[0196] Based on the same inventive concept, another embodiment of the present application further provides a computer program product, including a computer program, which is executed by a processor to perform the data collection method described in any of the above embodiments.

[0197] Based on the same inventive concept, another embodiment of the present application further provides a computer-readable storage medium on which a computer program is stored, wherein when the program is executed by a processor, the data acquisition method as described in any of the above embodiments is implemented.

[0198] As for the device, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0199] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0200] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, devices, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0201] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0202] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0203] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable terminal device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0204] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.

[0205] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0206] The above is a detailed introduction to a data acquisition method, device, equipment and medium provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of ​​the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A data collection method, characterized in that: Applied to the web side, the method includes: Monitoring multiple types of requests from users on the web terminal, wherein the multiple types of requests include at least API requests; In the built-in function that responds to the API request, inject a first event, where the first event is used to obtain the response body content of the API request; Based on the API request, obtaining first data of the API request, the first data including response related information and the response body content; Report the first data to the server.

2. The data collection method according to claim 1, characterized in that: The multiple types of requests also include a static resource request, the static resource request includes a first static resource request and a second static resource request, and the method further includes: Before the first acquisition script takes effect, the second data requested by the first static resource is obtained through GetEntries; After the first acquisition script takes effect, a second static resource request is obtained through PerformanceObserver, and second data of the second static resource request is obtained; The static resource request is obtained by filtering multiple types of requests from users of the web terminal according to a first preset screening strategy; Report the second data to the server.

3. The data collection method according to claim 1, characterized in that: In the built-in function that responds to the API request, injecting a first event includes: Define a primitive function, and assign the primitive function to a value of a built-in function; Define a new function, assign the new function a value of the built-in function, and add the first event to the new function to obtain an updated built-in function; The obtaining the first data of the API request includes: According to a second preset screening strategy, multiple types of requests from the user of the web terminal are filtered to obtain the API request; Storing the response-related information of the API request in a predefined first local cache object, the response-related information at least including the first request URL, the first time information, and the first response body size information of the API request; Determine whether the response body content of the API request is received through the callback function of the first event injected into the update built-in function; After the response body content of the API request is received, the response body content is stored in a predefined second local cache object, wherein the response body content at least includes first URL information, HTTP status code, business error code, and business error information.

4. The data collection method according to claim 3, characterized in that: Before reporting the first data to the server, the method further includes: Traversing multiple pieces of response related information in the first local cache object, and obtaining multiple first request URLs of the API request from the response related information; Based on the first request URL, taking out multiple response body contents matching the multiple first request URLs from the second local cache object; Merging the multiple response body contents and the response related information according to the matching relationship between the first request URL, and storing them in the first local cache object to obtain third data of the API request; The reporting the first data to the server includes: reporting third data in the first local cache object.

5. The data collection method according to claim 2, characterized in that: The method further comprises: storing the second data of the first static resource request in a predefined third local cache object; Storing the second data of the second static resource request in a predefined fourth local cache object, wherein the second data at least includes: a second request URL, second time information, and second response body size information of the static resource request; Before storing the first second data of the second static resource request into a predefined fourth local cache object, determining, based on the second request URL in the first second data, a subscript of the first static resource request in the third local cache object that matches the second request URL in the first second data; And intercept the second data of the first static resource request before the subscript in the third local cache object, and add the second data of the first static resource request before the subscript to the fourth local cache object.

6. The data collection method according to claim 2, characterized in that: The reporting the second data to the server includes: Detecting whether the web terminal triggers the following preset events, wherein the preset events include at least one of the following: uninstallation, closing, and view change; When the preset event is triggered, the second data is reported.

7. The data collection method according to claim 2, characterized in that: The reporting the second data to the server includes: When the priority of the current task of the web terminal is lower than the priority of the data reporting task of reporting the second data to the server, the first function is called to report the second data.

8. A data acquisition device, characterized in that: Applied to a web terminal, the device includes: A monitoring module, used to monitor multiple types of requests from users on the web terminal, wherein the multiple types of requests include at least API requests; A response body content acquisition module, used to inject a first event into a built-in function that responds to the API request, wherein the first event is used to obtain the response body content of the API request; A first data acquisition module, configured to acquire first data of the API request based on the API request, wherein the first data includes response related information and the response body content; A data reporting module is used to report the first data to the server.

9. An electronic device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory, wherein the processor executes the computer program to implement the data collection method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, wherein when the computer program is executed by a processor, the data collection method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Performance monitoring method and system for WEB system and storage medium

    CN109165152A

  • Website page quality evaluation and monitoring method and system

    CN111898059A

  • Method and system for monitoring real user experience at browser side in real time

    CN113010371A

  • Abnormal request capturing method and device, electronic equipment and storage medium

    CN115378925A

  • Presenting web resource to user in browser

    US20160196246A1