benecaster_analytics_cohort
Filters the cohort retention matrix for GET benecaster-analytics/v1/analytics/cohort. $data has show_ids, date_from, date_to, tier_slug (always null: the tier filter does not apply to cohorts), cohort_from (the first day of the first cohort month), columns (the number of months), cohorts ([{month, size, retained, retained_pct}], one per UTC calendar month the range touches, month as Y-m) and notes ({erased_joins, erased_churns, synced_undated, join_not_on_record}).
A subscriber (a show and a user) is in the cohort of their first joined or dated synced event. retained[n] counts them still subscribed at the end of the n-th month after joining, the last entry ending on date_to. churned ends a subscription and reactivated restores it; licence-grace rows and tier moves change nothing. retained_pct is one decimal of size, null for a cohort of 0.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$data |
array |
— | The matrix the route answers |
$args |
array |
— | The query: show_ids (only shows where the add-on is active), date_from and date_to (inclusive UTC Y-m-d), tier_slug (always null) |
Returns:
array
Example
// Leave out cohorts too small to mean anything.
add_filter( 'benecaster_analytics_cohort', function ( array $data, array $args ): array {
$data['cohorts'] = array_values( array_filter( $data['cohorts'], fn( $c ) => $c['size'] >= 5 ) );
return $data;
}, 10, 2 );
Notes
Anything that is not an array is ignored and the unfiltered data is used. Guard with benecaster_addon_is_active( 'analytics-dashboard', $show_id ) for each show you act on. Walkthrough: Read the Analytics Dashboard cohort retention matrix.
Need this built rather than just documented? See our services →