# Data acquisition

In the We Analytics console, experience analysis can be enabled for free, automatically collecting data and having full analytics capabilities without changing a line of code, and customizing reporting user IDs, properties, and custom events.

When a more detailed population analysis is required (such as performing abtests, looking at different channel sources, conversion of member / non-member populations, heat comparison, etc.),More insights can be gained by correlating more business data, where you can customize reporting business-customized events and tag custom user attributes / IDs, and provide rich population filtering and contrasting capabilities in visualized logs, heat maps, and transformation analysis.

# Weixin Mini Program

Automatic data collection begins once it is opened. By default, the automatically collected data is sufficient to support the use of various analytical modules such as visualization logs, heat graphs, transformation analysis, and so on.It is also recommended to use the Weixin Mini Program interface to report custom user IDs, user attributes, and custom events on demand for more granular crowd and event analysis.

Note:

  • When the user exits Weixin Mini Program to the background for more than 30 minutes, and then returns to the Mini Program (and the scene value is not 1089), the system will automatically end the last collection and restart the new collection.On the management side you will see two different visualized logs.

# Web Project

After creating a new web project, enter the project, select "Settings - > Acquisition Configuration," you can see the access code, and write the access code to the index.html file to access the web project.Data can be collected automatically without additional actions. Web SDK documentation

# Web-end cross-domain acquisition

Cross domain collection is supported, and cross domain collection allows you to collect visual logs between the main domain and one or more sub domains. This is particularly useful in the following situations:

  • Users navigate between multiple relevant websites.
  • An application that runs across multiple subdomains requires consistent user tracking and behavior analysis.

You just need to properly access the web SDK across all domains and make sure that both primary and secondary domains use the same web project ID .In the realization, the cross-domain acquisition through the URL parameter passing visual log information, and in the target domain to parse and apply these information.This ensures that the user's behavior between the main domain and the sub domain can be consistently tracked and analyzed.

# Example

Suppose you have a primary application running at www.example1.com and a secondary application running at www.example2.com.Here are the steps to how to use cross domain acquisition:

  1. Start collection in the main domain:
// In www.example1.com
if (window.__wxobs__) {
  window.__wxobs__.setup({ /* 初始化参数 */ });
}
  1. Generate a link to jump to a subdomain:
// Still in www.example1.com
let auxiliaryDomainInfo = '';
if (window.__wxobs__ && window.__wxobs__.getAuxiliaryDomainInfo) {
  auxiliaryDomainInfo = window.__wxobs__.getAuxiliaryDomainInfo();
}

const subDomainUrl = `https://www.example2.com?wxobsMetadata=${auxiliaryDomainInfo}`;
// Use subDomainUrl as a jump link
  1. Start the collection in the secondary field and the collection collector automatically merges the visual logs based on the urlquery

# Weixin Mini Program web-view acquisition (joint acquisition)

# Access the document

If you want to capture content in a web-view in Weixin Mini Program, use the syndication feature.

The steps to use are as follows:

  1. In the We Analysis Experience Analysis console, go to [Settings - Web Capture] to configure the web project
  2. If you do not have a web project, you need to create a web project first according to the guidelines on the page
  3. Initiate web capture according to the guideline

The latest federated collection feature no longer requires developers to pass the sessionId manually in Weixin Mini Program and also supports the ability to skip other page collection in web-view without adding [[]]wxobsFollowquery parameter, therefore, after the above three steps, you can complete the joint acquisition.

Note: Currently only 1 to 1 federated collection is supported, i.e. one Weixin Mini Program project can federate only one web project (if you have multiple web domains, all domains use the same web project ID).

Of course, the old method is still compatible, and usually you don't need to pay attention to the following two steps, which are just a explaination of the old combined collection scheme.

  1. According to the guideline , in Weixin Mini Program (base library version > = 2.29.1),When the setup function is called, it returns asessionId of type string
  import '@wxobs/miniprogram-helper';

  App({
    onLaunch: async function () {
      const { sessionId } = await wx.obs.setup({})
    },
  });
  1. 在使用 web-view 组件时,将步骤 4 中的 sessionId 作为 url query 填入到 src 中,例如:
<web-view src="https://www.qq.com?wxobsId={{sessionId}}"></web-view>

注意事项:

  1. 若要采集的 web-view 设置了 x-iframe-optionsContent-Security-Policy响应头,则会导致热力图等功能无法正常展示 web-view 中的内容,需要:
    • 去掉 x-iframe-options 属性或者修改为 x-iframe-options: ALLOW-FROM dev.weixin.qq.com wedata.weixin.qq.com;
    • 修改 Content-Security-Policy 响应头为 Content-Security-Policy: frame-ancestors 'self' dev.weixin.qq.com wedata.weixin.qq.com;
  2. 【旧联合采集方案,当前已不再需要,仅作说明】在内嵌 web-view 中,默认情况下仅首次加载的页面支持联合采集。如果在 web-view 中跳转到其它页面(如从 a.example.com 跳到 b.example.com),则需要在打开 b.example.com 时,增加 wxobsFollow=true 的 query,如 b.example.com?wxobsFollow=true

# FAQ

  1. 提示当前页面存在 webview,但未开启联合采集,无法采集 webview 内容,应该如何解决。

请先按照以下顺序进行排查:

  • web 页面是否开启了采集,如果未开启,请先根据指引,启动 web 采集
  • web 页面的采集 projectId 与所配置的联合采集 projectId 是否一致,如果不一致,请修改为一致
  1. 我有多个 web 项目都需要接入一个小程序,应该怎么接入呢?

请参考接入文档,所有 web 使用同一个 projectId 进行采集。

# 技术支持

如果您在接入过程中遇到问题,请点击 we 分析控制台 - 体验分析页面右上角“技术支持“,扫码进群反馈。