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.

Backend Implementation

Use the following steps to get the number of comments made in a specific Conversation via an API call:

  1. Make a GET /v1/messages-count call.
  2. Replace SPOT_ID placeholder with your Spot ID.
  3. Replace the POST_ID placeholder with the post ID of a single Conversation or a comma-separated list of post IDs for up to 30 Conversations.

The API returns a comment count for each requested POST_ID.

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

Frontend Implementation

Use the following steps to embed a comment counter to your page:

  1. Add the Launcher code to the page.


    If you already have a Conversation on the page, the launcher already exists on the page. You do not need to add a separate launcher code or change the existing one.

  2. Paste the following code in the location where the comment counter should appear. Any container can be used for the counter, such as <div> or <span>.

    <div data-spotim-module="messages-count" data-post-id="POST_ID"></div>
  3. Replace the POST_ID placeholder with the post ID for the specific conversation.

  4. (Optional) For real-time comment count updates, add the real-time="true" attribute. This only applies to pages displaying the specific Conversation for which you request the count.

  5. To embed an additional counter, repeat steps 2-4.

Comment Count Fetching

After embedding the messages-count module on your page, you can use a JavaScript function to retrieve the comment count:

  1. Call window.SPOTIM.getMessagesCount(). This asynchronous function requires you to pass an object as an argument.
  spotId: 'SPOT_ID', 
  postId: 'POST_ID'
}).then(data => console.log(data));
  1. Replace SPOT_ID placeholder with your Spot ID.
  2. Replace POST_ID placeholder with the relevant Post ID.

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: