Configure
The Configure API is used to set up the configuration for your domain, specifying which pages the Prefetch API will be active on and which actions should be tracked. You’ll need to provide your clientId, clientSecret, a list of valid entity IDs (representing the pages where the prefetch functionality should be enabled), and a list of valid action IDs (such as pageviews, favorites, likes, dislikes, and shares) that should be tracked on those pages.
Notes:
- validPageIds must represent valid page IDs, which are derived from the URL of each page. For example, if the URL is
https://example.com/articles/intro-to-nextjs
, the page ID would be something likearticle-introduction-to-nextjs
. These IDs are used to track specific pages. - validActionIds can be any string, including hyphens, and will define the types of actions that can be tracked for the pages (e.g.,
pageviews
,likes
,shares
). The actions you specify here are the ones that will be incremented through the API. - Once the client configuration is set, the validActionIds can be used to increment actions on the pages specified by validPageIds using the Increment API (e.g., incrementing
pageviews
for"article-introduction-to-ssr-in-nextjs"
). - The response body will mirror the configuration you sent, ensuring the settings are correctly applied.
Configure Valid Pages
Request
curl -X POST "https://prefetch.io/api/v1/configure" \
-H "Content-Type: application/json" \
-d '{
"clientId": "{{clientId}}",
"clientSecret": "{{clientSecret}}",
"validPageIds": [
"article-introduction-to-ssr-in-nextjs",
"article-guide-to-dynamic-routing-in-nextjs",
"article-best-practices-for-monorepo-setup",
"article-how-to-deploy-nextjs-app-on-heroku",
"article-understanding-react-server-components",
"article-securing-your-nextjs-app-with-jwt",
"article-using-shell-scripts-for-automation"
],
"validActionIds": ['pageviews', 'favorites', 'likes', 'dislikes', 'shares'],
}'
Response
{
"clientId": "{{clientId}}",
"clientSecret": "{{clientSecret}}",
"validPageIds": [
"article-introduction-to-ssr-in-nextjs",
"article-guide-to-dynamic-routing-in-nextjs",
"article-best-practices-for-monorepo-setup",
"article-how-to-deploy-nextjs-app-on-heroku",
"article-understanding-react-server-components",
"article-securing-your-nextjs-app-with-jwt",
"article-using-shell-scripts-for-automation"
],
"validActionIds": ["pageviews", "favorites", "likes", "dislikes", "shares"]
}
Request Headers
- Content-Type:
application/json
- The request body must be in JSON format.
Request Body
The request body must be a JSON object containing the following parameters:
- clientId (required): The unique identifier for the client (provided during registration).
- clientSecret (required): The secret key associated with the client (provided during registration).
- validPageIds (required): An array of page IDs that represent specific pages on the website. These page IDs are typically derived from the URL of each page and used for tracking. For example, a URL like
https://example.com/articles/intro-to-nextjs
would generate a page ID likearticle-introduction-to-nextjs
. Given this,validPageIds
array cannot be empty. - validActionIds (required): An array of action IDs that the client wishes to track for the specified pages. These action IDs can be any string, optionally containing hyphens (
-
). These actions define the types of operations (such as page views, likes, etc.) that will be tracked for the pages. Given this,validActionIds
array cannot be empty.
Response
If the configuration is successful, the API will return a JSON object containing the configuration values that were provided. This confirms that the client has successfully registered the valid page IDs and actions.
Example Response:
{
"clientId": "1b7ec7d8-9211-46f2-b14f-14313ac4e275",
"clientSecret": "516698ca-8fef-4d93-afd8-2fc73aef6889",
"validPageIds": [
"article-introduction-to-ssr-in-nextjs",
"article-guide-to-dynamic-routing-in-nextjs",
"article-best-practices-for-monorepo-setup",
"article-how-to-deploy-nextjs-app-on-heroku",
"article-understanding-react-server-components",
"article-securing-your-nextjs-app-with-jwt",
"article-using-shell-scripts-for-automation"
],
"validActionIds": [
"pageviews",
"favorites",
"likes",
"dislikes",
"shares",
"user-interactions-page"
]
}
Success Response
- Status Code: 200 OK
- The response body will confirm the configuration by echoing back the
clientId
,clientSecret
,validPageIds
, andvalidActionIds
.
- The response body will confirm the configuration by echoing back the
Error Responses
-
400 Bad Request:
- The request body is missing required parameters (
clientId
,clientSecret
,validPageIds
, orvalidActionIds
) or the body is malformed.
- The request body is missing required parameters (
-
401 Unauthorized:
- The
clientId
orclientSecret
provided is invalid or does not match the registered client.
- The
-
404 Not Found:
- The specified client ID does not exist in the system.
-
500 Internal Server Error:
- The server encountered an error while processing the configuration request.