# analysis.getWeeklyRetain

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 weekly retention of user visits to a Mini Program.

Calling methods:

# HTTPS Call

# Request Address

POST https://api.weixin.qq.com/datacube/getweanalysisappidweeklyretaininfo?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. Its value is the date of Monday in the format of yyyymmdd.
end_date string Yes End date. Its value is the date of Sunday in the format of yyyymmdd. Only the data of one week can be queried.

# Return Value

# Object

JSON data package that is returned

Attribute Type Description
ref_date string Time range, for example, "20170306-20170312"
visit_uv_new Object Retention of new users
visit_uv Object Retention of active users

visit_uv_new is composed as follows

Property Type Description
key number The identifier. Its value starts from "0", which indicates the current week, and the value "1" indicates one week later, and so on. Its values include "0", "1", "2", "3", and "4".
value number The number of new or active users (when key is "0") or the number of retained users (when key is greater than "0") on the date corresponding to key.

visit_uv is composed as follows

Property Type Description
key number The identifier. Its value starts from "0", which indicates the current week, and the value "1" indicates one week later, and so on. Its values include "0", "1", "2", "3", and "4".
value number The number of new or active users (when key is "0") or the number of retained users (when key is greater than "0") on the date corresponding to key.

# Notes

The format of the request JSON data packet and the returned JSON data packet must be yyyymmdd. Only the data of one natural week can be queried, and the time must be entered according to the natural week, for example, 20170306 (Monday) and 20170312 (Sunday).

# Request Data Example

{
  "begin_date" : "20170306",
  "end_date" : "20170312"
}

# Return Data Example

{
  "ref_date": "20170306-20170312",
  "visit_uv_new": [
    {
      "key": 0,
      "value": 0
    },
    {
      "key": 1,
      "value": 16853
    }
  ],
  "visit_uv": [
    {
      "key": 0,
      "value": 0
    },
    {
      "key": 1,
      "value": 99310
    }
  ]
}

# 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.getWeeklyRetain

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

# Request Parameters

Attribute Type Default Required Description
beginDate string Yes Start date. Its value is the date of Monday in the format of yyyymmdd.
endDate string Yes End date. Its value is the date of Sunday in the format of yyyymmdd. Only the data of one week can be queried.

# Return Value

# Object

JSON data package that is returned

Attribute Type Description
refDate string Time range, for example, "20170306-20170312"
visitUvNew Object Retention of new users
visitUv Object Retention of active users

visitUvNew is composed as follows

Property Type Description
key number The identifier. Its value starts from "0", which indicates the current week, and the value "1" indicates one week later, and so on. Its values include "0", "1", "2", "3", and "4".
value number The number of new or active users (when key is "0") or the number of retained users (when key is greater than "0") on the date corresponding to key.

visitUv is composed as follows

Property Type Description
key number The identifier. Its value starts from "0", which indicates the current week, and the value "1" indicates one week later, and so on. Its values include "0", "1", "2", "3", and "4".
value number The number of new or active users (when key is "0") or the number of retained users (when key is greater than "0") on the date corresponding to key.

# Request Data Example

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

# Return Data Example

{
  "refDate": "20170306-20170312",
  "visitUvNew": [
    {
      "key": 0,
      "value": 0
    },
    {
      "key": 1,
      "value": 16853
    }
  ],
  "visitUv": [
    {
      "key": 0,
      "value": 0
    },
    {
      "key": 1,
      "value": 99310
    }
  ],
  "errMsg": "openapi.analysis.getWeeklyRetain:ok"
}