Pageviews Count Value

For every Prefetch Pageviews API call to get the count value, you need to pass a JWT token. The token endpoint is what provides the JWT token.

Prerequisites

Before you can call the increment api, you need to do 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 thats required to get the count using /api/v1/token

Getting count

Request

GET
/api/v1/pageviews/page-id/value
curl -X GET "https://prefetch.io/api/v1/pageviews/page-id/value" \
    -H "Authorization: {{token}}"

Response

{
  "count": 177
}

Parameters

  • page-id (required): A placeholder for the actual page ID, which uniquely identifies the page for which the view count is being incremented. In the example, the page ID is page-id.

Request Headers

  • Authorization: {{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 page view count.

Example Response:

{
  "count": 178
}
  • count: The total number of page views for the specified page. In this example, the page has 178 views after the increment.

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 page ID does not exist.
  • 500 Internal Server Error:
    • The server encountered an unexpected error while processing the request.

FAQs

Why am I getting the error message "pageviews is not a valid action"?

This error occurs because the pageviews action has not been configured for your domain yet. Before you can increment the pageviews count for any page, you need to explicitly configure pageviews as a valid action through the /api/v1/configure endpoint.

To resolve this:

  1. Configure Valid Actions: Use the /api/v1/configure endpoint to specify pageviews (or any other action you wish to track) as a valid action for your domain.

Example configuration:

curl -X POST "https://prefetch.io/api/v1/configure" \
    -H "Content-Type: application/json" \
    -d '{
        "clientId": "{{clientId}}",
        "clientSecret": "{{clientSecret}}",
        "validPageIds": [
            list of valid page ids
        ],
        "validActionIds": ["pageviews"]
    }'
  1. Retry the Increment API: Once you've configured pageviews as a valid action, retry the request to increment the pageviews for your page.

Additional Note:

The validActionIds list can include any custom actions you'd like to track, such as likes, shares, etc. You can configure multiple actions in the same request.

Was this page helpful?