# analysis.getVisitDistribution

Call this API at the server side. For more information, see Server API.

This API supports Cloud Calls. The WeChat DevTools version must be 1.02.1904090 or later (download the latest stable version here), and the wx-server-sdk version must be 0.4.0 or later.

Obtains the distribution data of user visits to a Mini Program.

Calling methods:

# HTTPS Call

# Request Address

POST https://api.weixin.qq.com/datacube/getweanalysisappidvisitdistribution?access_token=ACCESS_TOKEN

# Request Parameters

Attribute Type Default Required Description
access_token string Yes Credentials to call API
begin_date string Yes Start date, in the format of yyyymmdd.
end_date string Yes End date, in the format of yyyymmdd. Only the data of one day can be queried, and the maximum value is the previous day.

# Return Value

# Object

JSON data package that is returned

Attribute Type Description
ref_date string Date, in the format of yyyymmdd.
list Array.<Object> Data list.

list is composed as follows

Property Type Description
index number Distribution type
item_list Array.<Object> Distribution data list

Valid values of index

Value Description Minimum Version
access_source_session_cnt Visit source distribution
access_staytime_info Visit duration distribution
access_depth_info Visit depth distribution

item_list is composed as follows

Property Type Description
key number The ID of the scene. Its definition varies with the index. For details, see the following table.
value number The page views (pv) of the scene ID.
access_source_visit_uv number The unique visitors (uv) of the scene ID.

# Request Data Example

{
  "begin_date" : "20170313",
  "end_date" : "20170313"
}

# Return Data Example

{
  "ref_date": "20170313",
  "list": [
    {
      "index": "access_source_session_cnt",
      "item_list": [
        {
          "key": 10,
          "value": 5
        },
        {
          "key": 8,
          "value": 687
        },
        {
          "key": 7,
          "value": 10740
        },
        {
          "key": 6,
          "value": 1961
        },
        {
          "key": 5,
          "value": 677
        },
        {
          "key": 4,
          "value": 653
        },
        {
          "key": 3,
          "value": 1120
        },
        {
          "key": 2,
          "value": 10243
        },
        {
          "key": 1,
          "value": 116578
        }
      ]
    },
    {
      "index": "access_staytime_info",
      "item_list": [
        {
          "key": 8,
          "value": 16329
        },
        {
          "key": 7,
          "value": 19322
        },
        {
          "key": 6,
          "value": 21832
        },
        {
          "key": 5,
          "value": 19539
        },
        {
          "key": 4,
          "value": 29670
        },
        {
          "key": 3,
          "value": 19667
        },
        {
          "key": 2,
          "value": 11794
        },
        {
          "key": 1,
          "value": 4511
        }
      ]
    },
    {
      "index": "access_depth_info",
      "item_list": [
        {
          "key": 5,
          "value": 217
        },
        {
          "key": 4,
          "value": 3259
        },
        {
          "key": 3,
          "value": 32445
        },
        {
          "key": 2,
          "value": 63542
        },
        {
          "key": 1,
          "value": 43201
        }
      ]
    }
  ]
}

# Correspondence Between Visit Sources and Keys

index="access_source_session_cnt". For the description of scene values, see Scene Values.

key Visit Source Scene Value
1 The list of recently used Mini Programs 1001
2 Search 1005 1006 1027 1042 1053
3 Chat 1007 1008 1044 1096
4 Scan of QR code 1011 1047
5 Homepage of an Official Account 1020
6 Drop-down panel on the Chat tab 1022
7 Home screen of the device 1023
8 Homepage of a Mini Program 1024
9 Mini Programs Nearby 1026 1068
11 Message template 1014 1043
13 Menu of an Official Account 1035
14 Share from an app 1036
15 Payment completion page 1034
16 Press and hold on a QR code 1012 1048
17 QR code in My Posts 1013 1049
18 Official Account article 1058
19 Wallet 1019
20 Cards & Offers 1028
21 Cards & Offers in a Mini Program 1029
22 Other Mini Programs 1037
23 Response of other Mini Programs 1038
24 Applicable Stores in Cards & Offers 1052
25 Quick entry to the search box 1054
26 Customer service message in a Mini Program 1073 1081
27 Sent by an Official Account 1074 1082
29 Recently Used in the task bar 1089
30 Press and hold the dote menu in the Mini Program 1090
31 Wi-Fi connection success screen 1078
32 Public Services 1092
33 An ad on WeChat 1045 1046 1067 1084
34 Other mobile apps 1069
35 Discover > Mini Programs > My Mini Programs (The scene value 1103 is discarded as of the base library 2.2.4, and does not affect the statistical result.) 1103
36 My Mini Programs in the task bar (The scene value 1104 is discarded as of the base library 2.2.4, and does not affect the statistical result.) 1104
10 Other Other scene values

# Correspondence Between Visit Duration and Keys (index="access_staytime_info")

key Visit duration
1 0-2s
2 3-5s
3 6-10s
4 11-20s
5 20-30s
6 30-50s
7 50-100s
8 >100s

# Correspondence Between Average Visit Depth and Keys (index="access_depth_info")

key Visit duration
1 1 page
2 2 pages
3 3 pages
4 4 pages
5 5 pages
6 6–10 pages
7 More than 10 pages

# Cloud Call

Cloud call is a capability provided by Mini Program·Cloud Base that allows you to call WeChat APIs in a cloud function. It must be used via wx-server-sdk in the cloud function.

# API Calling Method

openapi.analysis.getVisitDistribution

You need to configure the permissions for the analysis.getVisitDistribution API via config.json. Details

# Request Parameters

Attribute Type Default Required Description
beginDate string Yes Start date, in the format of yyyymmdd.
endDate string Yes End date, in the format of yyyymmdd. Only the data of one day can be queried, and the maximum value is the previous day.

# Return Value

# Object

JSON data package that is returned

Attribute Type Description
refDate string Date, in the format of yyyymmdd.
list Array.<Object> Data list.

list is composed as follows

Property Type Description
index number Distribution type
itemList Array.<Object> Distribution data list

Valid values of index

Value Description Minimum Version
access_source_session_cnt Visit source distribution
access_staytime_info Visit duration distribution
access_depth_info Visit depth distribution

itemList is composed as follows

Property Type Description
key number The ID of the scene. Its definition varies with the index. For details, see the following table.
value number The page views (pv) of the scene ID.
accessSourceVisitUv number The unique visitors (uv) of the scene ID.

# Request Data Example

const cloud = require('wx-server-sdk')
  cloud.init()
  exports.main = async (event, context) => {
    try {
      const result = await cloud.openapi.analysis.getVisitDistribution({
        beginDate: '20170313',
        endDate: '20170313'
      })
      console.log(result)
      return result
    } catch (err) {
      console.log(err)
      return err
    }
  }

# Return Data Example

{
  "refDate": "20170313",
  "list": [
    {
      "index": "access_source_session_cnt",
      "itemList": [
        {
          "key": 10,
          "value": 5
        },
        {
          "key": 8,
          "value": 687
        },
        {
          "key": 7,
          "value": 10740
        },
        {
          "key": 6,
          "value": 1961
        },
        {
          "key": 5,
          "value": 677
        },
        {
          "key": 4,
          "value": 653
        },
        {
          "key": 3,
          "value": 1120
        },
        {
          "key": 2,
          "value": 10243
        },
        {
          "key": 1,
          "value": 116578
        }
      ]
    },
    {
      "index": "access_staytime_info",
      "itemList": [
        {
          "key": 8,
          "value": 16329
        },
        {
          "key": 7,
          "value": 19322
        },
        {
          "key": 6,
          "value": 21832
        },
        {
          "key": 5,
          "value": 19539
        },
        {
          "key": 4,
          "value": 29670
        },
        {
          "key": 3,
          "value": 19667
        },
        {
          "key": 2,
          "value": 11794
        },
        {
          "key": 1,
          "value": 4511
        }
      ]
    },
    {
      "index": "access_depth_info",
      "itemList": [
        {
          "key": 5,
          "value": 217
        },
        {
          "key": 4,
          "value": 3259
        },
        {
          "key": 3,
          "value": 32445
        },
        {
          "key": 2,
          "value": 63542
        },
        {
          "key": 1,
          "value": 43201
        }
      ]
    }
  ],
  "errMsg": "openapi.analysis.getVisitDistribution:ok"
}