Increment Custom Action Count

For every Prefetch API call to increment a custom action count (e.g., pageviews, likes, shares, or any other custom action), you need to pass a JWT token. The token endpoint is what provides the JWT token.

Prerequisites

Before you can call the increment API for custom actions, you need to complete the following steps:

  • Register domain to get client ID and client secret using /api/v1/register
  • Configure domain for valid actions (e.g., pageviews, likes, shares, or any other custom actions you define) and valid page IDs using /api/v1/configure
  • Get the token that's required to increment the counter using /api/v1/token

Increment Custom Action Count

Request

POST
/api/v1/custom-action-id/page-id/increment
curl -X POST "https://prefetch.io/api/v1/custom-action-id/page-id/increment" \
    -H "Content-Type: application/json" \
    -d '{"token": "{{token}}"}'

Response

{
  "count": 178
}

Parameters

  • custom-action-id (required): A placeholder for the actual custom action ID, which uniquely identifies the action being tracked. The action ID can be any string you choose (e.g., pageviews, likes, shares, or any other action relevant to your application). Hyphens (-) are optional and can be used for better readability, but are not required. For example:

    • pageviews
    • likes
    • shares

    The action ID can be any valid string that helps identify the action being tracked, allowing you to track custom behaviors on your site or app.

  • page-id (required): A placeholder for the actual page ID, which uniquely identifies the page for which the custom action count is being tracked. The page-id corresponds to a specific page on your blog or site. This is the ID associated with the URL of the page, and it allows you to track actions for individual pages. For example:

    • article-introduction-to-ssr-in-nextjs
    • article-guide-to-dynamic-routing-in-nextjs

    The page-id should be configured in your system, and it links to a specific URL on your website or blog.

Request Headers

  • Content-Type: application/json
    • The request body must be formatted as a JSON object.

Request Body

{
  "token": "{{token}}"
}
  • token (required): A string containing the authentication token for the API request. Replace {{token}} with your actual authentication token.

Response Body

The API responds with a JSON object containing the updated count for the custom action on the specified page.

Example Response:

{
  "count": 178
}
  • count: The total number of times the specified custom action (e.g., pageviews, likes, shares, or any other action) has occurred for the specified page. In this example, the custom action has occurred 178 times.

Success Response

  • Status Code: 200 OK

Error Responses

  • 400 Bad Request:
    • The request body is missing required parameters or is improperly formatted.
  • 401 Unauthorized:
    • The provided authentication token is invalid or missing.
  • 404 Not Found:
    • The specified custom action ID or page ID does not exist or is not configured.
  • 500 Internal Server Error:
    • The server encountered an unexpected error while processing the request.

Notes:

  • custom-action-id can be any string that represents the action you wish to track. This allows you to define custom actions that make sense for your application, such as pageviews, likes, shares, or any other interaction.

  • page-id uniquely identifies the page for which you are tracking the custom action count. The page-id corresponds to a page at a specific URL and is configured in your system.

  • The token is required for authentication and must be passed in every request for security purposes.

  • Once the actions are configured and the token is obtained, you can use the Increment API to track the number of times these custom actions occur on specific pages. This enables you to track user interactions and engagement at a granular level, tailored to each page on your site.

Was this page helpful?