First, make sure all the configurations are done. Below the required configurations guide.
Go to https://console.cloud.google.com/
- Select project
- Click on Navigation menu (hamburger menu to the left)
- API and Services > Enabled APIs and services > Search bar: Google Analytics Data API > Enable
- Inside Google Analytics Data API > Credentials > Create Credentials > Service account > provide service account name (ID gets auto generated)
- Click on Done
- Click on new service account > KEYS > ADD KEY > Create new key
- Save .json file
Go to https://analytics.google.com/
- Select project
- Click on Admin > Property Access Management > Add (plus icon)
- Add Service Account email from previous step on Google Cloud (ends with .iam.gserviceaccount.com) with Viewer role
YouTube Tutorial: How to use Google Analytics Reporting API with Nodejs | TutsCoder
Go to https://firebase.google.com/ and get started
- Select project
- Click on Project settings > Service accounts > Generate new private key
- Copy databaseURL
With about Keys fill in the following:
HOST= // localhost:3000
GSA_CLIENT_EMAIL= // Google Service Account for GA4
GSA_PRIVATE_KEY= // Google Service Account for GA4
FIREBASE_PROJECT_ID=
FIREBASE_PRIVATE_KEY=
FIREBASE_CLIENT_EMAIL=
FIREBASE_DB_URL=
Private keys have unix "\n" new lines, not needed on Vercel.
npm i
Then
npm run dev