This website uses cookies to improve the user experience, more information on the legal information path.
Notes
0
years
0
mons
0
days
0
hour
0
mins
0
secs
00
2
Make a views counter with google analytics
Is not necessary make a complex system to count the views of your blog. You can use google analytics to do it, you dont need persiste the data in a database.
Here we dont explain how to create a Google analytics account, you can follow this tutorial to do it.
1. Create a endpoint to get the data using the class BetaAnalyticsDataClient
.analytics.ts
export default async function handler(req: NextApiRequest, res: NextApiResponse<Data>) {
const { query } = req;
const { slug = '/' } = query;
const analyticsDataClient = new BetaAnalyticsDataClient({