Add a comment counter

Help users identify Conversations with high engagement.

To show your users the engagement level of a specific Conversation, you can display the number of user comments that have been posted to the conversation. By referencing the POST_ID, you can add the user comment count for a Conversation on a page.



Real-time same-page comment counter

Use the following steps to add a real-time comment counter to the same page as a Conversation:


  1. In the <body> of your page, paste the following code in the location where the user comment count should appear.
<div class="spot-im-replies-count" data-post-id="POST_ID" real-time="true"></div>
  1. Replace POST_ID with the POST_ID for the specific conversation.


API-loaded comment counter

Use the following steps if you need only to embed a comment counter on a page. Partners typically use this approach to add comment counters to a landing page.

👍

IMPORTANT

This approach only returns the comment counts for the requested Conversations. You must decide how to display this information to your users.


  1. From your OpenWeb Admin Dashboard, copy your Spot ID from the URL.
https://admin.spot.im/spot/SPOT_ID/...

  1. Make a GET /v1/messages-count call. Replace SPOT_ID with your Spot ID. Replace POST_ID either with the Post ID for a single Conversation or with the Post IDs for multiple Conversations. Multiple Post IDs must be comma-delimited and limited to 30.
GET https://open-api.spot.im/v1/messages-count?spot_id=SPOT_ID&posts_ids=POST_ID
GET https://open-api.spot.im/v1/messages-count?spot_id=SPOT_ID&posts_ids=POST_ID1,POST_ID2

The API returns a comment count for each requested POST_ID.

{
    "spot_id": "SPOT_ID",
    "messages_count": {
        "POST_ID1": 3,
        "POST_ID2": 18
    }
}

  1. Display the message count for the requested Conversations.


JavaScript function comment counter

Use the following steps if you need to embed a comment counter on a page using a JavaScript function:


  1. From your OpenWeb Admin Dashboard, copy your Spot ID from the URL.
https://admin.spot.im/spot/SPOT_ID/...

  1. Call window.SPOTIM.getMessagesCount() to return the number of messages for a requested Conversation post ID.

    This asynchronous function requires you to pass an object as an argument. The object must include your Spot ID and the post ID of the Conversation.
window.SPOTIM.getMessagesCount({ 
  spotId: 'SPOT_ID', 
  postId: 'POST_ID'
}).then(data => console.log(data));
  1. Display the messages count for the requested Conversation.


React comment counter

Use this implementation method to add a comment counter to a React single-page application. The OpenWeb React SDK npm repository explains how to use the npm package:



Did this page help you?