Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07cfbab
commit 14e8254
Showing
1 changed file
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { fetchGET } from "@/src/utils/fetcher" | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
|
||
const liveViews = await fetchGET( | ||
`${process.env.NEXT_PUBLIC_MATOMO_URL}?method=Live.getCounters&idSite=${process.env.NEXT_PUBLIC_MATOMO_SITE_ID}&lastMinutes=5&module=API&format=JSON&token_auth=${process.env.NEXT_PUBLIC_MATOMO_API_KEY}` | ||
) | ||
|
||
/*const overallPageViews = await fetchGET( | ||
`${process.env.NEXT_PUBLIC_MATOMO_URL}?method=Actions.get&idSite=${ | ||
process.env.NEXT_PUBLIC_MATOMO_SITE_ID | ||
}&period=range&date=2018-02-01,${new Date() | ||
.toISOString() | ||
.slice(0, 10)}&module=API&format=JSON&token_auth=${ | ||
process.env.NEXT_PUBLIC_MATOMO_API_KEY | ||
}` | ||
) | ||
const recentPageViews = await fetchGET( | ||
`${process.env.NEXT_PUBLIC_MATOMO_URL}?method=Actions.get&idSite=${process.env.NEXT_PUBLIC_MATOMO_SITE_ID}&period=day&date=previous30&module=API&format=JSON&token_auth=${process.env.NEXT_PUBLIC_MATOMO_API_KEY}` | ||
) | ||
const allTimeStats = await fetchGET( | ||
`${process.env.NEXT_PUBLIC_MATOMO_URL}?method=VisitsSummary.get&idSite=${ | ||
process.env.NEXT_PUBLIC_MATOMO_SITE_ID | ||
}&period=range&date=2011-01-01,${new Date() | ||
.toISOString() | ||
.slice(0, 10)}&module=API&format=JSON&token_auth=${ | ||
process.env.NEXT_PUBLIC_MATOMO_API_KEY | ||
}` | ||
) | ||
const seoStats = await fetchGET( | ||
`${process.env.NEXT_PUBLIC_MATOMO_URL}?method=SEO.getRank&url=https://mxd.codes/&idSite=${process.env.NEXT_PUBLIC_MATOMO_SITE_ID}&module=API&format=JSON&token_auth=${process.env.NEXT_PUBLIC_MATOMO_API_KEY}` | ||
) | ||
const topPages = await fetchGET( | ||
`${ | ||
process.env.NEXT_PUBLIC_MATOMO_URL | ||
}?module=API&method=Actions.getPageUrls&segment=pageUrl=@/articles/&flat=1&idSite=${ | ||
process.env.NEXT_PUBLIC_MATOMO_SITE_ID | ||
}&period=range&date=2018-02-01,${new Date() | ||
.toISOString() | ||
.slice(0, 10)}&format=JSON&filter_limit=5&token_auth=${ | ||
process.env.NEXT_PUBLIC_MATOMO_API_KEY | ||
}` | ||
) | ||
const cookieConsent = await fetchGET( | ||
`${ | ||
process.env.NEXT_PUBLIC_MATOMO_URL | ||
}?module=API&method=Events.getCategory&idSite=${ | ||
process.env.NEXT_PUBLIC_MATOMO_SITE_ID | ||
}&period=range&date=2018-02-01,${new Date() | ||
.toISOString() | ||
.slice( | ||
0, | ||
10 | ||
)}&filter_limit=10&flat=1&force_api_session=1&format_metrics=1&format=JSON&token_auth=${ | ||
process.env.NEXT_PUBLIC_MATOMO_API_KEY | ||
}` | ||
) | ||
const biggestTrafficSource = await fetchGET( | ||
`${ | ||
process.env.NEXT_PUBLIC_MATOMO_URL | ||
}?module=API&method=Referrers.getReferrerType&idSite=${ | ||
process.env.NEXT_PUBLIC_MATOMO_SITE_ID | ||
}&period=range&date=2018-02-01,${new Date() | ||
.toISOString() | ||
.slice( | ||
0, | ||
10 | ||
)}&filter_limit=1&flat=1&force_api_session=1&format_metrics=1&format=JSON&token_auth=${ | ||
process.env.NEXT_PUBLIC_MATOMO_API_KEY | ||
}` | ||
) | ||
const countryVisits = await fetchGET( | ||
`${ | ||
process.env.NEXT_PUBLIC_MATOMO_URL | ||
}?method=UserCountry.getCountry&idSite=${ | ||
process.env.NEXT_PUBLIC_MATOMO_SITE_ID | ||
}&period=range&date=2011-01-01,${new Date() | ||
.toISOString() | ||
.slice(0, 10)}&module=API&format=JSON&token_auth=${ | ||
process.env.NEXT_PUBLIC_MATOMO_API_KEY | ||
}` | ||
) | ||
*/ | ||
res.status(200).json({ | ||
analytics: { | ||
currentVisitors: liveViews[0], | ||
/*overallPageViews: overallPageViews.nb_pageviews, | ||
recentPageViews: recentPageViews, | ||
allTimeStats: allTimeStats, | ||
seoStats: seoStats, | ||
topPages: topPages, | ||
cookieConsent: cookieConsent, | ||
biggestTrafficSource: biggestTrafficSource, | ||
countryVisits: countryVisits,*/ | ||
}, | ||
cms: {}, | ||
}) | ||
} |