<p>Administrators of <ahref="/api/channel">channels</a> of a certain size (the exact limit is a server-side config, returned in the <code>can_view_stats</code> flag of <ahref="/constructor/channelFull">channelFull</a>) can invoke <ahref="/method/stats.getBroadcastStats">stats.getBroadcastStats</a> to get detailed channel statistics.<br>
The query must be sent to the datacenter with ID <code>channelFull.stats_dc</code>, obtainable using <ahref="/method/channels.getFullChannel">channels.getFullChannel</a>.<br>
The returned <ahref="/constructor/stats.broadcastStats">stats.broadcastStats</a> contains multiple statistics: </p>
<ul>
<li>Period-related statistics: a pair of values, one at the beginning and one at the end of the period in consideration (<code>period</code>). <br> The <code>period</code> typically depends on channel activity.<ul>
<li><code>total_viewcount/postcount</code>, for posts posted during the period in consideration (<code>views_per_post</code>).<br>
Note that in this case, <code>current</code> refers to the <code>period</code> in consideration (<code>min_date</code> till <code>max_date</code>), and <code>prev</code> refers to the previous period (<code>(min_date - (max_date - min_date))</code> till <code>min_date</code>). </li>
<li><code>total_sharecount/postcount</code>, for posts posted during the period in consideration (<code>shares_per_post</code>).<br>
Note that in this case, <code>current</code> refers to the <code>period</code> in consideration (<code>min_date</code> till <code>max_date</code>), and <code>prev</code> refers to the previous period (<code>(min_date - (max_date - min_date))</code> till <code>min_date</code>).</li>
</ul>
</li>
<li>Percentage statistics<ul>
<li>Percentage of subscribers with enabled notifications (<code>enabled_notifications</code>)</li>
</ul>
</li>
<li>Graphs: <ahref="#graph-visualization">graphs are described below »</a>. </li>
<p>Administrators of <ahref="/api/channel">supergroups</a> of a certain size (the exact limit is a server-side config, returned in the <code>can_view_stats</code> flag of <ahref="/constructor/channelFull">channelFull</a>) can call <ahref="/method/stats.getMegagroupStats">stats.getMegagroupStats</a> to get detailed supergroup statistics.<br>
The query must be sent to the datacenter with ID <code>channelFull.stats_dc</code>, obtainable using <ahref="/method/channels.getFullChannel">channels.getFullChannel</a>.<br>
The returned <ahref="/constructor/stats.broadcastStats">stats.broadcastStats</a> contains multiple statistics, see the <ahref="/constructor/stats.broadcastStats">constructor page for more info »</a>. </p>
<p>Administrators of <ahref="/api/channel">channels</a> of a certain size (the exact limit is a server-side config, returned in the <code>can_view_stats</code> flag of <ahref="/constructor/channelFull">channelFull</a>) can invoke <ahref="/method/stats.getMessageStats">stats.getMessageStats</a> to get statistics of a specific message.<br>
The query must be sent to the datacenter with ID <code>channelFull.stats_dc</code>, obtainable using <ahref="/method/channels.getFullChannel">channels.getFullChannel</a>.<br>
The returned <ahref="/constructor/stats.messageStats">stats.messageStats</a> contains the view graph of the message. </p>
<p>There are four available visualizations for graph types:</p>
<ul>
<li><ahref="#line-graph">Line graph</a></li>
<li><ahref="#step-graph">Step graph</a></li>
<li><ahref="#bar-graph">Bar graph</a></li>
<li><ahref="#area-graph">Area graph</a></li>
</ul>
<p>Graph modifiers (see <ahref="#graph-examples">various graphs</a> for examples): </p>
<ul>
<li><code>y_scaled</code> - Indicates that each of the two (!) lines in a step graph must be visualized on its own scale, with two different tick axes on the left and right parts of the graph</li>
<li><code>percentage</code> - Indicates whether value percentages should be shown in labels</li>
<li><code>stacked</code> - Depending on the graph type, indicates stacking of multiple columns in the same graph</li>
<p>Certain graphs are not directly sent in the <ahref="/constructor/stats.broadcastStats">stats.broadcastStats</a> constructor to reduce server load: instead, those graphs will be sent as a <ahref="/constructor/statsGraphAsync">statsGraphAsync</a> constructor, and should be fetched separately using <ahref="/method/stats.loadAsyncGraph">stats.loadAsyncGraph</a>. </p>
<p>After obtaining the full <ahref="/constructor/statsGraph">statsGraph</a> constructor, clients should parse the JSON graph object in the <code>json</code> field.</p>
<p>Object structure: </p>
<tableclass="table">
<thead>
<tr>
<th>Key</th>
<th>Graph title</th>
</tr>
</thead>
<tbody>
<tr>
<td>columns</td>
<td>Array of all data column arrays in the chart. Each column array has its <strong>label</strong> at position 0, followed by values.</td>
<td><ahref="#graph-visualization">Graphs types</a> for each of the column arrays (object, <code>"label": "type"</code>): <br>- <code>line</code> - <ahref="#line-graph">line graph</a><br>- <code>area</code> - <ahref="#area-graph">area graph</a><br>- <code>step</code> - <ahref="#step-graph">step graph</a><br>- <code>bar</code> - <ahref="#bar-graph">bar graph</a><br>- <code>x</code> - x axis values for each of the charts at the corresponding positions, UNIX timestamps in milliseconds.</td>
<td>Color for each type (object, <code>"label": "colorKey#AAAAAA"</code>; see <ahref="#chart-colors">chart colors</a>).</td>
</tr>
<tr>
<td>names</td>
<td>Localized name for each variable (object, <code>"label": "Name"</code>)</td>
</tr>
<tr>
<td>subchart</td>
<td>Object indicating the default zoom range for the graph, this is object's structure: <br>- <code>show</code> - Whether to use the specified zoom range (boolean) <br>- <code>defaultZoom</code> - An array with two <code>x</code> values, indicating the two ends of the default zoom range</td>
</tr>
<tr>
<td>y_scaled</td>
<td>Indicates that each of the two (!) lines in a step graph must be visualized on its own scale, with two different tick axes on the left and right parts of the graph (boolean, see <ahref="#graph-examples">various graphs</a> for examples)</td>
</tr>
<tr>
<td>percentage</td>
<td>Indicates whether value percentages should be shown in labels (boolean, see <ahref="#graph-examples">various graphs</a> for examples)</td>
</tr>
<tr>
<td>stacked</td>
<td>Depending on the graph type, indicates stacking of multiple columns in the same graph (boolean, see <ahref="#graph-examples">various graphs</a> for examples)</td>
</tr>
</tbody>
</table>
<!-- | hidden | Array of columns that should not be visualized in the final graph | -->
<p>The following chart restrictions apply:</p>
<ul>
<li>Up to 50 columns on one graph must be supported.</li>
<li>Chart types are always the same for every column in the graph.</li>
<li>The <code>bar</code> chart type and <code>stacked</code> option are always used together.</li>
<li><code>percentage</code> is always used with the <code>area</code> graph.<!-- * Graphs with every chart type _should_ be able to zoom into the same chart type with the same columns (names and types). -->
<!-- * `y_scaled` is only used with exactly 2 `line` columns -->
<p>Graphs that support zooming will contain a <code>zoom_token</code> in the <ahref="/constructor/statsGraph">statsGraph</a> constructor.<br>
Said token should be then used as <code>token</code> in a new <ahref="/method/stats.loadAsyncGraph">stats.loadAsyncGraph</a> call triggered when the user clicks on the label, related to a certain x axis in the graph (see <ahref="#graph-examples">graph examples</a>).<br>
The <code>x</code> coordinate of the label should be provided to the <code>x</code> parameter; the method will then return (if available) a more detailed subgraph.<br>
If not enough data is available, a localized <ahref="/constructor/statsGraphError">statsGraphError</a> will be returned. </p>
<p>Chart colors can be provided as a color key, followed by the primary color value in hex format: </p>
<pre><code>red#e05356</code></pre>
<p>The color key can be one of <code>red</code>, <code>lightblue</code>, <code>lightgreen</code>, <code>golden</code>, <code>green</code>, <code>orange</code>, <code>blue</code>, <code>indigo</code>.<br>
Apps can choose to use a color value specified by the currently loaded theme: for example, the <ahref="https://github.com/DrKLO/Telegram/blob/dceccae0b74576d092fb3b2accaffded2c0b5f63/TMessagesProj/src/main/java/org/telegram/ui/Charts/data/ChartData.java#L81">android app</a> uses <code>statisticChartLine_*</code> themekeys for each of the color keys, check out the <ahref="https://github.com/DrKLO/Telegram/tree/master/TMessagesProj/src/main/assets">assets directory</a> for a bunch of default themes with various colors for channel statistics. </p>
<p>However, the server may also choose to return just a plain color value in hex format: </p>
<pre><code>#e05356</code></pre>
<p>In this case, the <code>dark</code> flag of the <ahref="/method/stats.getBroadcastStats">stats.getBroadcastStats</a> method can be used to choose the palette of returned colors.</p>