Front-end point embedding method and device based on abstract syntax tree

By converting source code into an abstract syntax tree, constructing upload logic, and automatically adding tracking logic, the problems of data accuracy and high cost in existing technologies are solved, realizing a low-cost and efficient front-end tracking method, and improving data readability and analysis efficiency.

CN115994069BActive Publication Date: 2026-02-03INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310108216.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-01
Publication Date
2026-02-03
Estimated Expiration
2043-02-01

AI Technical Summary

Technical Problem

Existing front-end tracking solutions cannot effectively identify the business meaning of the uploaded information, resulting in high analysis costs or excessive tracking costs. There is a lack of a method that can both ensure data accuracy and reduce costs.

Method used

By converting source code files into an abstract syntax tree, constructing upload logic, and automatically adding event tracking logic to the source code, the tree-like format of the abstract syntax tree is used for event node identification and logic construction, achieving event tracking without manual intervention.

Benefits of technology

It reduced the cost of data tracking, improved the readability of uploaded data, enabled quick identification of the business meaning of uploaded information, and improved analysis efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115994069B_ABST
    Figure CN115994069B_ABST
Patent Text Reader

Abstract

The application provides a front-end point-in method and device based on an abstract syntax tree, which can be used in the financial field or other fields. The method comprises the following steps: converting a code source file into a first AST corresponding to the code source file; globally initializing point-in, wherein the global initialization at least comprises configuring a point-in uploading address, generating a collection event list, and generating a point-in uploading function; identifying a node corresponding to an event in the first AST according to the collection event list; constructing point-in logic code according to an original function name and a file path in node information of the first AST; converting the point-in logic code into a second AST corresponding to the point-in logic code; and adding the second AST to a head of the first AST. The application can automatically preset point-in logic without manual intervention, thereby reducing the cost, improving the readability of uploaded data, and quickly identifying the business meaning of uploaded information.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the financial field or other fields, and in particular to a front-end event tracking method and apparatus based on an abstract syntax tree. Background Technology

[0002] To collect user behavior data from the front end, it's necessary to implement event tracking in the front-end code to analyze the trigger frequency and page performance of specific user behaviors. Tracking these specific behaviors requires pre-setting information in the corresponding functions to ensure that the information is reported when the function is triggered. There are currently two main front-end event tracking solutions:

[0003] ① Full-tracking method: Listeners are set globally for the event categories that need to be monitored, and the events are automatically sent when they are triggered. Because the runtime code is compressed and obfuscated, and the function names are changed, this method cannot obtain the original name of the triggered function, cannot effectively identify the business meaning of the event, has poor readability, and has a high cost for subsequent analysis.

[0004] ② Code-based event tracking: To ensure that the uploaded data accurately includes the business meaning of the event and the function name, code-based event tracking can be used. This involves manually adding the uploading logic to each event that needs to be monitored, thus guaranteeing the accuracy of the uploaded data. However, this method requires manual processing of each function, resulting in high labor costs.

[0005] Among existing technical solutions, while full-tracking has a lower tracking cost, it cannot effectively identify the business meaning of the submitted information, resulting in higher subsequent analysis costs. Code-based tracking, while solving the data accuracy problem, leads to a significant increase in tracking costs. Therefore, a tracking solution that is both accurate and low-cost is needed. Summary of the Invention

[0006] The purpose of this application is to provide a front-end event tracking method and device based on an abstract syntax tree. By converting source code files into an abstract syntax tree, constructing the upload logic, and adding the upload logic to the source code, the event tracking logic can be automatically pre-set without manual intervention, thereby reducing costs and improving the readability of the uploaded data, and quickly identifying the business meaning of the uploaded information.

[0007] Abstract Syntax Tree (AST) is an abstract representation of the syntactic structure of source code. It represents the syntactic structure of a programming language in a tree-like structure, where each node represents a structure within the source code. In modern front-end engineering, the Babel library can be used to transpile front-end source code with different syntaxes into ASTs and then process them. Because the tree-like format of ASTs is easy to parse and has a uniform format, it is very convenient to develop various front-end code analysis or preprocessing tools based on it. Therefore, ASTs are widely used in the front-end field, for example:

[0008] ① The editor's error messages, code formatting, code highlighting, and code auto-completion;

[0009] ② Check for code errors or style issues;

[0010] ③ Translate different types of JavaScript syntax.

[0011] This application provides a front-end event tracking method based on an abstract syntax tree, the method comprising:

[0012] Transform the source code file into a first abstract syntax tree corresponding to the source code file;

[0013] Perform global initialization on the tracking points. The global initialization includes at least configuring the tracking point upload address, generating a list of collected events, and generating the tracking point upload function.

[0014] Based on the collected event list, the nodes corresponding to the events in the first abstract syntax tree are identified;

[0015] Based on the original function names and file paths in the node information of the first abstract syntax tree, construct the embedding logic code;

[0016] The event tracking logic code is converted into a second abstract syntax tree corresponding to the event tracking logic code; and

[0017] Add the second abstract syntax tree to the head of the first abstract syntax tree.

[0018] In a specific embodiment, based on the original function name and file path in the first abstract syntax tree node information, the embedding logic code is constructed, including:

[0019] Obtain the original function name and the file path;

[0020] Construct an upload structure based on the original function name and the file path; and

[0021] The embedding logic code is constructed based on the above-uploaded structure.

[0022] In a specific embodiment, obtaining the original function name and the file path includes:

[0023] The original function name is obtained based on the name field in the node information of the first abstract syntax tree; and

[0024] Obtain the file path from the compilation context.

[0025] In a specific embodiment, the node is identified based on the type of the attribute value of the node.

[0026] In a specific embodiment, configuring the data entry point upload address includes setting the user-defined upload address or the default upload address as the data entry point upload address.

[0027] The process of generating the event collection list includes setting the intersection of the user-defined event collection list and the complete event collection list from the data entry points as the event collection list.

[0028] The function for generating the tracking point upload includes generating the tracking point upload function based on the upload address, the current site identifier, and the channel identifier.

[0029] In a specific embodiment, the method further includes:

[0030] Determine whether the global initialization of the embedded points has been completed.

[0031] This application provides a front-end event tracking device based on an abstract syntax tree, the device comprising:

[0032] The first conversion module is used to convert the code source file into a first abstract syntax tree corresponding to the code source file;

[0033] An initialization module is used to perform global initialization of the tracking points. The global initialization includes at least configuring the tracking point upload address, generating a list of collected events, and generating the tracking point upload function.

[0034] The identification module is used to identify the nodes corresponding to the events in the first abstract syntax tree according to the collected event list;

[0035] The construction module is used to construct the embedding logic code based on the original function name and file path in the node information of the first abstract syntax tree;

[0036] The second conversion module is used to convert the tracking logic code into a second abstract syntax tree corresponding to the tracking logic code; and

[0037] An add module is provided, which is used to add the second abstract syntax tree to the head of the first abstract syntax tree.

[0038] This application also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the above-described front-end event tracking method based on an abstract syntax tree.

[0039] This application also provides a computer-readable storage medium storing a computer program that executes the above-described front-end event tracking method based on an abstract syntax tree.

[0040] This application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the aforementioned front-end event tracking analysis method based on an abstract syntax tree.

[0041] In the embodiments of this application, front-end event tracking is performed based on an abstract syntax tree. This involves converting source code files into an abstract syntax tree, constructing the submission logic, and adding this submission logic to the source code. Compared to the full event tracking method in the prior art, this application can effectively identify the business meaning of the submitted information, thereby improving the readability of the submitted data and facilitating rapid identification of the business meaning of the submitted information. Compared to the code-based event tracking method in the prior art, it automatically pre-sets the event tracking logic without manual intervention, thus reducing costs. Attached Figure Description

[0042] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0043] Figure 1 This is a flowchart of a front-end event tracking method based on an abstract syntax tree according to an embodiment of this application;

[0044] Figure 2 This is a flowchart of step 14 in an embodiment of this application;

[0045] Figure 3 This is another flowchart of the front-end event tracking method based on abstract syntax tree in this application embodiment;

[0046] Figure 4 This is a schematic diagram of a front-end event tracking device based on an abstract syntax tree according to an embodiment of this application;

[0047] Figure 5 This is a schematic diagram of the construction module of an embodiment of this application;

[0048] Figure 6This is another schematic diagram of a front-end event tracking device based on an abstract syntax tree according to an embodiment of this application;

[0049] Figure 7 A schematic diagram of a computer device according to an embodiment of this application. Detailed Implementation

[0050] Referring to the accompanying drawings, the foregoing and other features of this application will become apparent from the following description. Specific embodiments of this application are specifically disclosed in the description and drawings, illustrating partial implementations in which the principles of this application may be employed. It should be understood that this application is not limited to the described embodiments; rather, it includes all modifications, variations, and equivalents falling within the scope of the appended claims.

[0051] In embodiments of this application, the term "and / or" includes any one and all combinations of one or more of the terms listed in association. The terms "comprising," "including," "having," etc., refer to the presence of the stated features, elements, components, or assemblies, but do not exclude the presence or addition of one or more other features, elements, components, or assemblies.

[0052] In the embodiments of this application, the singular forms "a," "the," etc., may include the plural forms and should be broadly interpreted as "a kind" or "a class" rather than limited to the meaning of "an." Furthermore, the term "the" should be understood to include both the singular and plural forms unless the context explicitly indicates otherwise. Additionally, the term "according to" should be understood as "at least partially based on…," and the term "based on" should be understood as "at least partially based on…," unless the context explicitly indicates otherwise.

[0053] It should be noted that the front-end tracking method and apparatus based on abstract syntax trees disclosed in this application can be used in the field of financial technology, or in any field other than financial technology. The application field of the front-end tracking method and apparatus based on abstract syntax trees disclosed in this application is not limited.

[0054] This application provides a front-end event tracking method based on an abstract syntax tree.

[0055] Figure 1 This is a flowchart of the front-end event tracking method based on an abstract syntax tree in an embodiment of this application. For example... Figure 1 As shown, the method includes:

[0056] Step 11: Convert the source code file into a first abstract syntax tree (AST) corresponding to the source code file;

[0057] Step 12: Perform global initialization of the data points. Global initialization includes configuring the data point upload address, generating a list of collected events, and generating the data point upload function.

[0058] Step 13: Identify the nodes corresponding to the events in the first AST based on the initialization event list;

[0059] Step 14: Construct the embedding logic code based on the original function names and file paths in the node information of the first AST;

[0060] Step 15: Convert the tracking logic code into a second AST corresponding to the tracking logic code; and

[0061] Step 16: Add the second AST to the header of the first AST.

[0062] As can be seen from the above embodiments, this application converts the source code file into an AST, constructs the uploading logic, and adds the uploading logic to the source code. This enables the automatic pre-setting of the embedding logic without manual intervention, thereby reducing costs and improving the readability of the uploaded data, allowing for quick identification of the business meaning of the uploaded information.

[0063] Step 11 is illustrated below.

[0064] In some embodiments, the source code file is transformed to obtain the corresponding abstract syntax tree (AST). Babel technology can be used to transform the source code file. Babel is a JavaScript compiler that can parse the source code file and generate the corresponding first abstract syntax tree (AST).

[0065] Step 12 is illustrated below.

[0066] In some embodiments, configuring the event tracking upload address includes determining whether the user-set parameters include a custom upload address. If so, the upload address is read and set as the event tracking upload address; otherwise, the default upload address is set as the event tracking upload address.

[0067] In some embodiments, generating a collection event list includes reading a user-defined collection event list, such as clicks and inputs, selecting the intersection of the user-defined collection event list and the complete event list that the tracking point can collect, and using this intersection as the collection event list. If the user has not set a collection event list, then the complete event list that the tracking point can collect is used as the collection event list.

[0068] In some embodiments, generating a tracking point upload function includes filling information such as upload address, current site identifier, and channel identifier into a function template to generate a unified tracking point upload function.

[0069] Step 13 is illustrated below.

[0070] In some embodiments, the event list generated during initialization includes events such as click events, input events, and function events. Taking function events as an example, if event tracking is performed on function events, then four nodes—ClassDeclaration, ArrowFunctionExpression, FunctionExpression, and FunctionDeclaration—need to be identified.

[0071] The following examples illustrate the four nodes mentioned above.

[0072] The `ClassDeclaration` is a class declaration that contains function definitions. It typically includes constructors and class functions. Function definitions within a class are located in the `body` property array of the `ClassDeclaration` node in the AST. The constructor's node is named `MethodDefinition`, and its value is `FunctionExpression`; the class function's node is named `PropertyDefinition`, and its value is also `FunctionExpression`. The steps to identify functions in a class declaration are: first, locate the class declaration `ClassDeclaration`; then, locate the node whose class property's value type is either `MethodDefinition` or `PropertyDefinition`.

[0073] ArrowFunctionExpression is an arrow function expression. The expression property of the ExpressionStatement node with the type "ArrowFunctionExpression" is of this type.

[0074] A FunctionExpression is a function expression, which is usually located in a VariableDeclaration node. To identify a FunctionExpression, simply find the VariableDeclaration node whose type (type) is FunctionExpression.

[0075] FunctionDeclaration is a function declaration. To identify FunctionDeclaration, simply find the node whose type is FunctionDeclaration.

[0076] Step 14 is illustrated below.

[0077] Figure 2 This is a flowchart of step 14 in an embodiment of this application. Figure 2 As shown, step 14 includes:

[0078] Step 141: Obtain the original function name and file path. The initialized upload function contains the upload address and basic logic. Additionally, other parameters need to be completed, such as the original function name and file path. Specifically, obtain the original function name of the current function based on the name field in the first AST node information, for example, the original function name is testClick; obtain the current file path from the compilation context, for example, the file path is "\src\views\test.js";

[0079] Step 142: Construct the upload structure `postBody` based on the original function name and file path, with the structure `{name: "testClick", path: "\src\views\test.js"}`; and

[0080] Step 143: Construct the tracking logic code based on the above upload structure. For example, pass postBody as a parameter to the upload function. For example, if the upload function is named uploadMessage(), the constructed tracking logic code is uploadMessage(postBody), that is, uploadMessage({name:“testClick”, path:“\src\views\test.js”}). Denote the constructed tracking logic code as trackerAST.

[0081] Therefore, by embedding event points in the event functions to be collected after global initialization, valid information such as the original function name and file path can be preserved, which facilitates subsequent restoration of business meaning and data analysis.

[0082] Step 15 is illustrated below.

[0083] In some embodiments, similar to step 11, Babel technology is used to convert the tracking logic code into a second AST corresponding to the tracking logic code.

[0084] Step 16 is illustrated below.

[0085] In some embodiments, since the AST is a tree-like JSON structure, the description of the function content is stored in the body property of the corresponding node. The body property exists in the form of an array, and each element in the body array corresponds to a line of the execution body in the original function. Therefore, it is only necessary to insert the tracking logic code constructed in the previous step into the first element position of the body array, that is, to insert the calling logic into the head of the original function, that is, to insert the trackerAST code into the head of the body array of the node node node.node.body.unshift(), to get node.body.unshift(trackerAST).

[0086] Figure 3 This is another flowchart of the front-end event tracking method based on an abstract syntax tree in this application embodiment. For example... Figure 3 As shown, the method also includes:

[0087] Step 17: Determine whether the global initialization of the tracking points has been completed. If it is determined that it has been completed, proceed to step 13; otherwise, proceed to step 12.

[0088] Therefore, if the global initialization of the tracking points is completed, the global initialization step can be omitted, thus improving the efficiency of tracking points.

[0089] The above specific applications are merely examples; other implementation methods will not be described in detail.

[0090] Based on the same inventive concept, this application also provides a front-end tracking device based on an abstract syntax tree. Since the principle of the problem solved by the front-end tracking device based on an abstract syntax tree is similar to that of the front-end tracking method based on an abstract syntax tree, the implementation of the front-end tracking device based on an abstract syntax tree can refer to the implementation of the front-end tracking method based on an abstract syntax tree, and the repeated parts will not be described again.

[0091] Figure 4 This is a schematic diagram of a front-end event tracking device based on an abstract syntax tree, according to an embodiment of this application. Figure 4 As shown, the front-end tracking device 1 based on abstract syntax tree provided in this application embodiment includes a first conversion module 10, an initialization module 20, an identification module 30, a construction module 40, a second conversion module 50, and an addition module 60.

[0092] The first conversion module 10 is used to convert the source code file into a first abstract syntax tree (AST) corresponding to the source code file.

[0093] In some embodiments, the first transformation module 10 transforms the code source file to obtain the corresponding abstract syntax tree (AST). Babel technology can be used to transform the code source file. Babel is a JavaScript compiler that can parse the code source file and generate the corresponding first abstract syntax tree.

[0094] The initialization module 20 is used to perform global initialization of the data points. Global initialization includes configuring the data point upload address, generating a list of collected events, and generating data point upload functions.

[0095] In some embodiments, configuring the event tracking upload address includes determining whether the user-set parameters include a custom upload address. If so, the upload address is read and set as the event tracking upload address; otherwise, the default upload address is set as the event tracking upload address.

[0096] In some embodiments, generating a collection event list includes reading a user-defined collection event list, such as clicks and inputs, selecting the intersection of the user-defined collection event list and the complete event list that the tracking point can collect, and using this intersection as the collection event list. If the user has not set a collection event list, then the complete event list that the tracking point can collect is used as the collection event list.

[0097] In some embodiments, generating a tracking point upload function includes filling information such as upload address, current site identifier, and channel identifier into a function template to generate a unified tracking point upload function.

[0098] The identification module 30 is used to identify the nodes corresponding to the events in the first AST according to the collection event list generated during initialization.

[0099] In some embodiments, the event list generated during initialization includes events such as click events, input events, and function events. Taking function events as an example, if event tracking is performed on function events, then four nodes—ClassDeclaration, ArrowFunctionExpression, FunctionExpression, and FunctionDeclaration—need to be identified and processed.

[0100] The following examples illustrate the four nodes mentioned above.

[0101] The `ClassDeclaration` is a class declaration that contains function definitions. `ClassDeclaration` includes constructors and class functions. Function definitions within a `Class` are located in the `body` property array of the `ClassDeclaration` node in the AST. The constructor's node is named `MethodDefinition`, and its value is `FunctionExpression`; the class function's node is named `PropertyDefinition`, and its value is also `FunctionExpression`. The steps to identify functions in a class declaration are: first, locate the class declaration `ClassDeclaration`; then, locate the node whose class property's value type is either `MethodDefinition` or `PropertyDefinition`.

[0102] ArrowFunctionExpression is an arrow function expression. The expression property of the ExpressionStatement node with the type "ArrowFunctionExpression" is of this type.

[0103] A FunctionExpression is a function expression, which is usually located in a VariableDeclaration node. To identify a FunctionExpression, simply find the VariableDeclaration node whose type (type) is FunctionExpression.

[0104] FunctionDeclaration is a function declaration. To identify FunctionDeclaration, simply find the node whose type is FunctionDeclaration.

[0105] The construction module 40 is used to construct the embedding logic code based on the original function name and file path in the first AST node information.

[0106] Figure 5 This is a schematic diagram of the construction module 40 in an embodiment of this application. Figure 5 As shown, the construction module 40 includes a first construction unit 401, a second construction unit 402, and a third construction unit 403.

[0107] The first construction unit 401 is used to obtain the original function name and file path. The initialized upload function contains the upload address and basic logic, and other parameters need to be completed, such as the original function name and file path. Specifically, the original function name of the current function is obtained from the name field in the first AST node information, for example, the original function name is testClick; the current file path is obtained from the compilation context, for example, the file path is "\src\views\test.js".

[0108] The second construction unit 402 is used to construct the upload structure postBody based on the original function name and file path mentioned above. Its structure is {name:“testClick”, path:“\src\views\test.js”}.

[0109] The third construction unit 403 is used to construct the tracking logic code based on the above-mentioned upload structure. For example, postBody is passed as a parameter to the upload function. For example, if the upload function is named uploadMessage(), the constructed tracking logic code is uploadMessage(postBody), that is, uploadMessage({name:“testClick”, path:“\src\views\test.js”}). The constructed tracking logic code is denoted as trackerAST.

[0110] Therefore, by embedding event points in the event functions to be collected after global initialization, valid information such as the original function name and file path can be preserved, which facilitates subsequent restoration of business meaning and data analysis.

[0111] The second conversion module 50 is used to convert the tracking logic code into a second AST corresponding to the tracking logic code.

[0112] In some embodiments, similar to the first conversion module 10, the second conversion module 50 uses Babel technology to convert the tracking logic code into a second AST corresponding to the tracking logic code.

[0113] Add module 60 is used to add the second AST to the header of the first AST.

[0114] In some embodiments, since the AST is a tree-like JSON structure, the description of the function content is stored in the body property of the corresponding node. The body property exists in the form of an array, and each element in the body array corresponds to a line of the execution body in the original function. Therefore, it is only necessary to insert the tracking logic code constructed in the previous step into the first element position of the body array, that is, to insert the calling logic into the head of the original function, that is, to insert the trackerAST code into the head of the body array of the node node node.node.body.unshift(), to get node.body.unshift(trackerAST).

[0115] As can be seen from the above embodiments, this application converts the source code file into an AST, constructs the uploading logic, and adds the uploading logic to the source code. This enables the automatic pre-setting of the embedding logic without manual intervention, thereby reducing costs and improving the readability of the uploaded data, allowing for quick identification of the business meaning of the uploaded information.

[0116] Figure 6 This is another schematic diagram of the front-end event tracking device based on an abstract syntax tree, according to an embodiment of this application. Figure 6 As shown in the figure, the front-end tracking device 1 based on abstract syntax tree provided in this application embodiment also includes a judgment module 70.

[0117] The judgment module 70 is used to determine whether the global initialization of the tracking points has been completed. Before performing global initialization, the judgment module 70 determines whether the global initialization of the tracking points has been completed. If it determines that the global initialization has been completed, then the global initialization is not performed.

[0118] Therefore, if the global initialization of the tracking points is completed, the global initialization step can be omitted, thus improving the efficiency of tracking points.

[0119] This application also provides a computer device. Figure 7 This is a schematic diagram of a computer device according to an embodiment of this application. The computer device 2 includes a memory 21, a processor 22, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the aforementioned front-end event tracking method based on an abstract syntax tree.

[0120] This application also provides a computer-readable storage medium storing a computer program that executes the above-described front-end event tracking method based on an abstract syntax tree.

[0121] This application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the aforementioned front-end event tracking method based on an abstract syntax tree.

[0122] It should be noted that the acquisition, storage, use, and processing of data in the technical solution of this application all comply with the relevant provisions of national laws and regulations.

[0123] The user information in this application embodiment is obtained through legal and compliant means, and the acquisition, storage, use, and processing of user information are authorized and agreed upon by the user.

[0124] While this application provides the method operation steps as described in the embodiments or flowcharts, more or fewer operation steps may be included based on conventional or non-inventive labor. The order of steps listed in the embodiments is merely one possible execution order among many and does not represent the only execution order. In actual device or client product execution, the methods shown in the embodiments or drawings can be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment).

[0125] Those skilled in the art will understand that the embodiments of this specification can be provided as methods, apparatus (systems), or computer program products. Therefore, the embodiments of this specification can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied 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.

[0126] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0127] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0128] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0129] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on its differences from other embodiments. In particular, the system embodiments are relatively simple in description because they are fundamentally similar to the method embodiments; relevant parts can be referred to the descriptions in the method embodiments. In this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "upper," "lower," etc., indicating orientation or positional relationships based on the orientation or positional relationships shown in the accompanying drawings, are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this application.

[0130] Unless otherwise expressly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to fixed connections, detachable connections, or integral connections; mechanical connections or electrical connections; direct connections or indirect connections through an intermediate medium; and internal connections between two components. Those skilled in the art can understand the specific meaning of the above terms in this application according to the specific circumstances. It should be noted that, without conflict, the embodiments and features in the embodiments of this application can be combined with each other. This application is not limited to any single aspect, nor to any single embodiment, nor to any combination and / or substitution of these aspects and / or embodiments. Moreover, each aspect and / or embodiment of this application can be used alone or in combination with one or more other aspects and / or embodiments.

[0131] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application, and they should all be covered within the scope of the claims and specification of this application.

Claims

1. A front-end event tracking method based on abstract syntax trees, characterized in that, The method includes: Transform the source code file into a first abstract syntax tree corresponding to the source code file; Perform global initialization on the tracking points. The global initialization includes at least configuring the tracking point upload address, generating a list of collected events, and generating the tracking point upload function. Based on the collected event list, the nodes corresponding to the events in the first abstract syntax tree are identified; Based on the original function names and file paths in the node information of the first abstract syntax tree, construct the embedding logic code; The event tracking logic code is converted into a second abstract syntax tree corresponding to the event tracking logic code; and Add the second abstract syntax tree to the head of the first abstract syntax tree; The configuration of the tracking point upload address includes setting the upload address set by the user or the default upload address as the tracking point upload address; the generation of the collection event list includes setting the collection event list as the intersection of the collection event list set by the user and the collection event list of all events collected by the tracking point; and the generation of the tracking point upload function includes generating the tracking point upload function based on the upload address, the current site identifier, and the channel identifier.

2. The method as described in claim 1, characterized in that, Based on the original function names and file paths in the node information of the first abstract syntax tree, construct the event tracking logic code, including: Obtain the original function name and the file path; Construct an upload structure based on the original function name and the file path; and The embedding logic code is constructed based on the above-uploaded structure.

3. The method as described in claim 2, characterized in that, Obtaining the original function name and the file path includes: The original function name is obtained based on the name field in the node information of the first abstract syntax tree; and Obtain the file path from the compilation context.

4. The method as described in claim 1, characterized in that, Identifying the nodes corresponding to events in the first abstract syntax tree includes: The node is identified based on the type of the value of its attribute.

5. The method as described in claim 1, characterized in that, The method further includes: Before performing the global initialization, it is determined whether the global initialization of the embedded points has been completed. If it is determined that the global initialization has been completed, then the global initialization is not performed.

6. A front-end event tracking device based on an abstract syntax tree, characterized in that, The device includes: The first conversion module is used to convert the code source file into a first abstract syntax tree corresponding to the code source file; An initialization module is used to perform global initialization of the tracking points. The global initialization includes at least configuring the tracking point upload address, generating a list of collected events, and generating the tracking point upload function. The identification module is used to identify the nodes corresponding to the events in the first abstract syntax tree according to the collected event list; The construction module is used to construct the embedding logic code based on the original function name and file path in the node information of the first abstract syntax tree; The second conversion module is used to convert the tracking logic code into a second abstract syntax tree corresponding to the tracking logic code; and An add module is provided, which is used to add the second abstract syntax tree to the head of the first abstract syntax tree; The configuration of the tracking point upload address includes setting the upload address set by the user or the default upload address as the tracking point upload address; the generation of the collection event list includes setting the collection event list as the intersection of the collection event list set by the user and the collection event list of all events collected by the tracking point; and the generation of the tracking point upload function includes generating the tracking point upload function based on the upload address, the current site identifier, and the channel identifier.

7. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the front-end instrumentation method based on the abstract syntax tree as described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that executes the front-end instrumentation method based on the abstract syntax tree as described in any one of claims 1 to 5.

9. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the front-end instrumentation method based on an abstract syntax tree as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method and device for adding burying points, processor, storage medium and program product

    CN114047924A