Search.../

getPostMetrics( )

Gets a specified post's metrics.

Description

The getPostMetrics() function returns a Promise that resolves to the specified post's metrics.

A post's metrics include the comments, likes, and views the post receives.

Syntax

function getPostMetrics(postId: string): Promise<GetPostMetricsResponse>

getPostMetrics Parameters

NAME
TYPE
DESCRIPTION
postId
string

Post ID.

Returns

Fulfilled - Post metrics.

Return Type:

Promise<
GetPostMetricsResponse
>
NAME
TYPE
DESCRIPTION
metrics
Metrics

Post metrics.

Was this helpful?

Get the metrics of a post

Copy Code
1import { posts } from wix-blog-backend;
2
3/* Sample postId value:
4 * 'ccbb6257-ed0e-4521-97df-8b5b207adb00'
5 */
6
7export async function getPostMetricsFunction(postId) {
8 try {
9 const result = await posts.getPostMetrics(postId);
10 const likes = result.metrics.likes;
11 console.log('Retrieved Result:', result);
12 return result;
13 } catch (error) {
14 console.log(error);
15 }
16}
17
18
19/* Promise resolves to:
20 * {
21 * "metrics": {
22 * "comments": 8,
23 * "likes": 20,
24 * "views": 2
25 * }
26 * }
27 */