This repository has been archived on 2025-03-28. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
coryd.dev-eleventy/src/_data/analytics.js
2024-03-24 08:15:21 -07:00

18 lines
No EOL
587 B
JavaScript

import EleventyFetch from '@11ty/eleventy-fetch'
export default async function () {
const API_KEY_FATHOM = process.env.API_KEY_FATHOM
const url =
'https://api.usefathom.com/v1/aggregations?entity=pageview&entity_id=CWSVCDJC&aggregates=pageviews&field_grouping=pathname&sort_by=pageviews:desc&limit=10'
const res = EleventyFetch(url, {
duration: '1h',
type: 'json',
fetchOptions: {
headers: {
Authorization: `Bearer ${API_KEY_FATHOM}`,
},
},
}).catch()
const pages = await res
return pages.filter((p) => p.pathname.includes('posts'))
}