Skip to content

Commit

Permalink
feat: change default back to 365 days ago;
Browse files Browse the repository at this point in the history
refactor: construct report
  • Loading branch information
7sferry committed Sep 15, 2024
1 parent 95c31ad commit dbb50f6
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ const scopes = [
"https://www.googleapis.com/auth/analytics.readonly",
];

const constructReport = row => {
return {
path: decodeURIComponent(String(row?.dimensionValues?.[0]?.value)),
value: Number(row?.metricValues?.[0].value),
};
}

async function getReport(pluginOptions) {
let report = await executeAnalytics(pluginOptions);
const reports = [];
const rows = report.data.rows ?? [];
for (const row of rows) {
reports.push({
path: decodeURIComponent(String(row?.dimensionValues?.[0]?.value)),
value: Number(row?.metricValues?.[0].value),
});
}
return reports;
return report.data.rows?.map(constructReport) || [];
}

async function executeAnalytics(pluginOptions) {
Expand All @@ -50,7 +49,7 @@ async function executeAnalytics(pluginOptions) {
requestBody: {
dimensions: [{ name: dimension }],
metrics: [{ name: metric }],
dateRanges: [{ startDate: pluginOptions.startDate || "30daysAgo", endDate: pluginOptions.endDate || "today" }],
dateRanges: [{ startDate: pluginOptions.startDate || "365daysAgo", endDate: pluginOptions.endDate || "today" }],
dimensionFilter: {
orGroup: {
expressions: [
Expand Down

0 comments on commit dbb50f6

Please sign in to comment.