This file contains hidden or 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
// src/index.js#L42 | |
const report = response.rows | |
.map((row, index) => { | |
const { dimensionValues, metricValues } = row; | |
return `${index + 1}. <https://${dimensionValues[0].value}|${dimensionValues[1].value}> | *x${ | |
metricValues[0].value | |
}*`; | |
}) |
This file contains hidden or 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
// src/index.js#L16 | |
const [response] = await analyticsDataClient.runReport({ | |
property: `properties/${process.env.GA4_PROPERTY_ID}`, | |
dateRanges: [ | |
{ | |
startDate: '7daysAgo', | |
endDate: 'today', | |
}, | |
], |
This file contains hidden or 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
# .github/workflows/analytics-report.yml | |
name: 7 Day Google Analytics Report | |
on: | |
schedule: | |
- cron: '0 10 * * 5' # Runs every Friday at 10 AM UTC | |
workflow_dispatch: # Allows manual triggering | |
jobs: |
This file contains hidden or 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
// app/results/get-all-votes.ts | |
'use server'; | |
import { doc } from '../../services/google-spreadsheet'; | |
import config from '../../utils/poll-config'; | |
export default async function getAllVotes() { | |
try { | |
await doc.loadInfo(); |
This file contains hidden or 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
// app/layout.tsx | |
export const metadata = { | |
title: 'Results', | |
description: 'Generated by Next.js', | |
} | |
export default function RootLayout({ | |
children, | |
}: { |
This file contains hidden or 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
// app/results/page.tsx | |
import Link from 'next/link'; | |
import getAllVotes from './get-all-votes'; | |
export default async function Page() { | |
const votes = await getAllVotes(); | |
return ( |
This file contains hidden or 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
// submit-vote.ts | |
'use server'; | |
import { redirect } from 'next/navigation'; | |
import { doc } from '../services/google-spreadsheet'; | |
export default async function submitVote(id: string) { | |
if (!id) { | |
redirect('/?error=true'); | |
} |
This file contains hidden or 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
// app/layout.tsx | |
export const metadata = { | |
title: 'Vote', | |
description: 'Generated by Next.js', | |
} | |
export default function RootLayout({ | |
children, | |
}: { |
This file contains hidden or 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
// app/page.tsx | |
'use client'; | |
import { useState } from 'react'; | |
import config from '../utils/poll-config'; | |
import submitVote from './submit-vote'; | |
export default function Page({ searchParams }) { | |
const { error } = searchParams; |
This file contains hidden or 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
// ./utils/poll-config.ts | |
const config = [ | |
{ | |
name: 'Frontend Development', | |
id: 'frontend_development', | |
}, | |
{ | |
name: 'Software Development', | |
id: 'software_development', |