Skip to content

Commit 5120c65

Browse files
committed
Fetch pageviews and visitors
1 parent cc0f307 commit 5120c65

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ if (timezone < 0) {
3131
timezone = timezone.replace("+", "-");
3232
}
3333

34-
const url = `https://analytics.services.netlify.com/v1/${siteId}/pageviews?from=${startDate.getTime().toFixed()}&to=${endDate.getTime()}&timezone=${timezone}&resolution=day`
3534

3635
console.log(url);
3736

3837
async function start() {
38+
getMetric("pageviews");
39+
getMetric("visitors");
40+
}
41+
42+
async function getMetric(metric) {
43+
const url = `https://analytics.services.netlify.com/v1/${siteId}/${metric}?from=${startDate.getTime().toFixed()}&to=${endDate.getTime()}&timezone=${timezone}&resolution=day`;
3944
var res = await fetch(url, {
4045
"credentials": "include",
4146
"headers": {
@@ -49,7 +54,7 @@ async function start() {
4954
});
5055

5156
const response = await res.json();
52-
writeToCSV(response.data, "pageviews");
57+
writeToCSV(response.data, metric);
5358
}
5459

5560
function writeToCSV(data, metric) {

0 commit comments

Comments
 (0)