Skip to main content
Calculates the user retention rate within a specified period of time. This function accepts 1 to 31 conditions and evaluates whether each condition is true. If the condition evaluates to true, 1 is returned. Otherwise, 0 is returned. It eventually returns an array of 0 and 1. You can calculate the user retention rate based on this data.

Syntax

Parameters

input: an array of conditions. A maximum of 31 conditions can be passed in. Separate multiple conditions with commas.

Return value

Returns an array of 0 and 1. The number of 0 and 1 is the same as the number of input conditions. The evaluation starts from the first condition.
  • If the condition evaluates to true, 1 is returned. Otherwise, 0 is returned.
  • If the first condition is not true, the current position and its following positions are all set to 0.

Examples

  1. Create a table named test and insert data.
  2. Query data from test.
    Text
  3. Use retention to calculate user retention rate. Example 1: Evaluate user behavior against the following conditions: view commodity page on 2022-01-01 (action=‘pv’) and place an order on 2022-01-02 (action=‘buy’).
    Text
    In the result:
    • Users 1 and 5 meets two conditions and [1,1] is returned.
    • User 2 does not meet the second condition and [1,0] is returned.
    • User 3 meets the second condition but does not meet the first condition. [0,0] is returned.
    • User 4 meets no condition and [0,0] is returned.
    Example 2: Calculate the percentage of users who have viewed commodity page on 2022-01-01 (action=‘pv’) and placed an order on 2022-01-02 (action=‘buy’).
    Text
    The return value is the user retention rate on 2022-01-02.

keyword

retention, retention rate, RETENTION