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/* Promise resolves to:
19 * {
20 * "metrics": {
21 * "comments": 8,
22 * "likes": 20,
23 * "views": 2
24 * }
25 * }
26 */
27
Get the metrics of a post (export from backend code)

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