Introduction
Use the Prefetch API to track actions like Page Views, Likes, Shares, and more across your site.
Steps
-
One-time steps:
- Register your domain by providing your email to get a
Client ID
andClient Secret
. - Configure the API by verifying your domain and specifying valid pages and actions.
- Register your domain by providing your email to get a
-
Recurring steps:
- Get a token (valid for 1 hour).
- Use the Prefetch API to increment counters (e.g.,
pageviews
,likes
) or retrieve the current count.
You can also use our npm package for easy integration, which automatically updates and retrieves counts.
Register Domain
Request
POST
/api/v1/registercurl -X POST "https://prefetch.io/api/v1/register" \
-H "Content-Type: application/json" \
-d '{
"clientName": "test-client-1",
"domainName": "{{referer}}",
"emailId": "{{emailId}}"
}'
Response
{
"clientId": "1b7ec7d8-9211-46f2-b14f-14313ac4e275",
"clientSecret": "516698ca-8fef-4d93-afd8-2fc73aef6889"
}
Configure Valid Pages
Request
POST
/api/v1/configurecurl -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"]
}
Get Token
Request
GET
/api/v1/tokencurl -X GET "https://prefetch.io/api/v1/token"
Response
{
"token": "your-generated-token-string"
}
Increment count
Request
POST
/api/v1/pageviews/page-id/incrementcurl -X POST "https://prefetch.io/api/v1/pageviews/page-id/increment" \
-H "Content-Type: application/json" \
-d '{"token": "{{token}}"}'
Response
{
"count": 178
}
Getting count
Request
GET
/api/v1/pageviews/page-id/valuecurl -X GET "https://prefetch.io/api/v1/pageviews/page-id/value" \
-H "Authorization: {{token}}"
Response
{
"count": 177
}
Guides
Configure
Learn how to programmatically configure pass list of pages on which the api will work.
Steps
Register
First step starts with registering a client to get a unique clientId and clientSecret for each domain.
Configure
Learn about the configure api which is used to restrict pages on which increment can be called.
Increment
Learn about the increment api which is used to increment the pageviews counter using the token.