Home > WeChat Applet > Mini Program Development > Custom analysis process of data in WeChat applet

Custom analysis process of data in WeChat applet

不言
Release: 2018-08-17 14:48:43
Original
2773 people have browsed it

The content of this article is about the custom analysis process of data in WeChat applet. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

In the background of the mini program, WeChat has provided powerful data analysis functions, including real-time statistics, access analysis, source analysis and user portrait functions. It can be said that it is completely sufficient for general data analysis, but sometimes it is not suitable for You need to do some more precise data analysis, such as specific sharing of a certain page, clicks on a certain button on the page, etc. In this case, you need to use the custom analysis function.

What is custom analysis?

Quote from the official document:

Custom analysis supports flexible multi-dimensional and near-real-time user behavior analysis, and can conduct refined tracking of user behavior within the mini program through customized reporting. Meet personalized analysis needs beyond standard statistics such as page visits.

Create a custom event

Custom analysis process of data in WeChat applet

  • ##Fill in the English name of the event and the Chinese name of the event according to the instructions. Here Both names are unique and cannot be set to those that have already been set. When setting, try to be concise and understand the name

  • Configuration methods include: filling in the configuration and reporting to the API. .

  • Configuration template: The official has provided some custom event templates, which can be used directly, including: entering the page, leaving the page, and sharing within the mini program, but the analysis granularity of these events They are all relatively rough. For the entire application, you can modify it by yourself to fill in the configuration only for a certain page

  • . The following statistical triggers are supported, including:

click triggers when clicked

enterPage triggers when entering the page, including opening a new page, going back, and switching to the foreground, all belong to the entering page
leavePage triggers when leaving the page, including leaving, switching to the background, all belong to the leaving page
pageLoad Triggered when opening a new page, that is, entering the page for the first time
pageUnload Triggered when recycling the page
pullDownRefresh Triggered when pull-down refresh
launch Triggered when loading the applet
background Triggered when switching to the background
foreground Triggered when switching to the foreground
share Upper right corner menu sharing
switchTab Triggered when the switchTab interface is called to switch pages

Custom analysis process of data in WeChat applet

  • action refers to the action when sending, and is reported once, which means that in each click, data is collected and a piece of data is reported; I haven't understood the step-by-step reporting yet.

  • page refers to the page to trigger the event. The content filled in here must be the same as the page path configured in app.json

  • data It is optional and is used to pass some data when the event is triggered. Among them, the field value is the data name in the data of the current page

For example

In e-commerce mini-programs, users will have an action of clicking on a product to add to the shopping cart. We can perform data analysis on this action. The following is how to fill in the configuration:

Fill in the English and Chinese names of the event:

Custom analysis process of data in WeChat applet

Fill in the event configuration and define how to collect data:

Custom analysis process of data in WeChat applet

In this example, use one action to report "Add to Shopping" car" incident.

trigger: trigger condition, click, indicating that the click operation triggers;

action: action when triggered, reported at one time, indicating that in each click, data is collected and a piece of data is reported;

page: Trigger page, fill in viewProduct (viewProduct is the product details page);

element: Trigger element, fill in .addToCart (.addToCart is an "add to shopping cart" button);

data: The event data and its source, represented by "field name field value", where the field value is a variable on the page.

Let’s talk about the field value in detail. He has the following rules:

The variable name filled in is obtained from the data field of the page instance by default.

If you want to collect it and render it by the list variable A certain item of data in the list can be represented by list[].*. The array subscript will be determined based on the number of the NodeList obtained from the currently filled element (can only be class).

If the list is two-dimensional, list[](file:///Users/wanghui/Blog/source/_posts/WeChat-miniprogram-data-analysis-custom-analysis.md#) can be used. * indicates that element here needs to fill in two classes (separated by spaces) to represent the parent list and the child list respectively.

If you want to get the subscript of the array, you can use list[].$INDEX to represent it

If you want to get the value of the data-series attribute in wxml, you can use $DATASET. to represent it

If you want to get the data of the app instance, you can use $APP.* to express it. Only basic types of data are supported, such as number, string, and boolean.

In addition, you can also fill in some provided system attributes, starting with "$". Currently, the following attributes are supported:

$PAGE_TIME The time from when the user enters this page to the current time (the time when the action is triggered Click)

$APP_TIME The current time when the user enters the mini program (the time point when the action is triggered)

$CURRENT_PAGE The page where the current user is located

$LAST_PAGE Previous page

Note: data can be empty. When it is empty, the event report only collects data from the system default fields

In this example, data has four items:

product_id: itemID

product_name : itemName

product_price: price

product_category: category

That is: the product_id field of the

event, collect the itemID in the data of the page instance on the viewProduct page Field; the product_name field of the

event collects the itemName field in the data of the page instance on the viewProduct page; the product_price field of the

event collects the price field in the data of the page instance on the viewProduct page;

The product_category field of the event collects the category field in the data of the page instance on the viewProduct page;

The above content means: when the user clicks the .addToCart button on the viewProduct page, a record is reported to add_to_cart Event, product_id, product_name, product_price, product_category fields of the event, The values ​​are itemID, itemName, price, and category on the page.

After filling in the configuration, click to check the fields.

Custom analysis process of data in WeChat applet

At this time, you will be prompted for the specific fields included in the add_to_cart event, and continue to add the name, data type and remark information of the fields.

About API reporting

API reporting is more flexible than filling in configuration, but it also involves some code changes and requires the release of a new version, while filling in configuration requires almost no code changes , so there is no need to release a new version. When we select API reporting, we can set the following parameters that need to be reported:

Custom analysis process of data in WeChat applet

Custom analysis process of data in WeChat applet

Custom analysis process of data in WeChat applet

Continue , we can insert the generated code into the mini program code. The following is the API report I submitted in the success() callback function after successful forwarding.

...
// 转发成功
success: function (res) {
      wx.reportAnalytics('click_share', {
        page_path: current_page_path,
        from: from,
      });
},
...
Copy after login

Whether you are filling in the configuration or reporting to the API, you need to save and test after filling in the configuration.

Custom analysis process of data in WeChat applet

Custom analysis process of data in WeChat applet

Custom analysis process of data in WeChat applet

Custom analysis process of data in WeChat applet

##When we test events, we often It will take a while to receive the data, about 1-2 minutes. In order to judge the correctness in time, we can turn on debugging in the mini program application on the mobile phone. In this way, every time an event is triggered, the Log in the console will be displayed. You can see the words [Custom Analysis] reported successfully. Click to view and you can see more data, such as the reported parameters, etc. The eventID inside corresponds to the English name of the event. In this way, you can quickly determine whether the event trigger meets the requirements. As expected, the following screenshot:

Custom analysis process of data in WeChat applet

Through use, we found that the custom analysis function of the mini program is very powerful. You can analyze any element and any event on the page, so that we can Understand the usage of mini programs in an all-round way, analyze and summarize the data, and use data to drive product iterations and improve user retention.

Related recommendations:

WeChat Mini Program - Custom Creation

Usage analysis of custom events in JavaScript_javascript skills

Detailed explanation of the custom toast implementation method of WeChat applet

The above is the detailed content of Custom analysis process of data in WeChat applet. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template