Skip to content

kyco/google-analytics-viewer

Repository files navigation

Google Analytics Viewer

View and export your Universal Analytics data before the API is disabled on July 1, 2024. This tool simplifies data exportation from Universal Analytics, allowing for flexible data retrieval in any format (by default CSV & JSON). Plus, this tool also allows you to do the same with your GA4 data, making it easy to both view and export your data well into the future.

Demo

Installation

This project uses Next.js and Material UI. Ensure you have Node.js and nvm installed. Then run:

git clone https://github.com/kyco/google-analytics-viewer
cd google-analytics-viewer
nvm use
npm install

Development

Start the project locally:

npm run dev

Access it at http://localhost:3000.

After the app is running locally you will need to hook it up to the Google services in order to retrieve data.

Connecting with Google Analytics APIs

NB: For all the steps below when navigating in Google Cloud Console ensure you have the correct project selected!

Step 1: Create a Service Account Key

If you don't have a service account, create one (we will need the JSON file later on):

Step 2: Enable Google Analytics APIs

Enable the required APIs:

Step 3: Add Service Account to Google Analytics

Copy the client_email from your service account file and add it as a "Viewer" via the Google Analytics UI:

  • Admin > Account Access Management > Add users

Step 4: Setup Environment Variables

Create .env.local in the root of the project:

GA_UNIVERSAL_VIEW_ID=<your_universal_view_id>
GA_PROPERTY_ID=<your_ga4_property_id>
GA_SERVICE_ACCOUNT_CREDENTIALS=<compressed_json_credentials>

View ID

  • Universal Analytics: Admin > View Settings > View ID

Property ID

  • GA4: Admin > Property details > Property ID

Service account credentials

Copy the contents of the service account JSON file and remove the white space so it fits on a single line. The end result should look like the following:

GA_SERVICE_ACCOUNT_CREDENTIALS={"type": "service_account", "project_id": "abc", ...}

Troubleshooting

Google Cloud:

Google Analytics:

Links

Universal Analytics:

GA4:

Universal Analytics & GA4:

Support

For bugs or improvements please use the issues tab or email support@kyco.io.