Table of Contents
What is custom analysis?
Create a custom event
Home WeChat Applet Mini Program Development Custom analysis process of data in WeChat applet

Custom analysis process of data in WeChat applet

Aug 17, 2018 pm 02:48 PM
html javascript php

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles