Analytics Tool Setup Guide
Overview
New API now supports integration with popular analytics platforms to help you track user behavior and website performance:
- Google Analytics 4 (GA4): The latest version of Google's analytics platform
- Umami Analytics: A privacy-focused, open-source analytics tool
Both analytics tools can be enabled simultaneously without conflict.
Features
✅ Zero-code integration - configured solely via environment variables
✅ Automatic script injection into the web interface
✅ Supports Docker and standalone deployments
✅ Privacy-focused implementation
✅ No front-end code modification required
Google Analytics 4 Setup
1. Obtain Your Measurement ID
- Visit Google Analytics
- Create a new property or select an existing one
- Go to Admin → Data Streams
- Create or select a web data stream
- Copy your Measurement ID (format:
G-XXXXXXXXXX)
2. Configure Environment Variables
Using Docker Compose:
Edit the docker-compose.yml file and uncomment the Google Analytics line:
environment:
- GOOGLE_ANALYTICS_ID=G-XXXXXXXXXX # Replace with your actual Measurement IDStandalone Deployment:
Add to the .env file or set as an environment variable:
export GOOGLE_ANALYTICS_ID=G-XXXXXXXXXXUsing Docker Run:
docker run -d \
-e GOOGLE_ANALYTICS_ID=G-XXXXXXXXXX \
...其他选项...
calciumion/new-api:latest3. Restart the Application
# Docker Compose
docker-compose down && docker-compose up -d
# Standalone Deployment
# Directly restart your applicationUmami Analytics Setup
1. Obtain Umami Credentials
Option A: Using Umami Cloud
- Register on Umami Cloud
- Add a new website
- Copy your Website ID (UUID format)
Option B: Self-hosting Umami
- Deploy your own Umami instance
- Create a website in the dashboard
- Copy your Website ID and Script URL
2. Configure Environment Variables
Using Docker Compose:
Edit the docker-compose.yml file:
environment:
- UMAMI_WEBSITE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
# Optional: Only required for self-hosted instances
- UMAMI_SCRIPT_URL=https://your-umami-domain.com/script.jsStandalone Deployment:
Add to the .env file:
export UMAMI_WEBSITE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
export UMAMI_SCRIPT_URL=https://your-umami-domain.com/script.js # OptionalNote: If using Umami Cloud, you do not need to set UMAMI_SCRIPT_URL, as it uses the official URL by default.
3. Restart the Application
Same as Google Analytics - restart the application to apply changes.
Using Both Analytics Tools Simultaneously
You can enable both Google Analytics and Umami simultaneously:
environment:
- GOOGLE_ANALYTICS_ID=G-ABC123XYZ
- UMAMI_WEBSITE_ID=a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6
- UMAMI_SCRIPT_URL=https://analytics.umami.is/script.jsVerification
After restarting the application:
- Open the web interface in your browser
- Open browser developer tools (F12) → Network tab
- Refresh the page
- Look for the following requests:
- Google Analytics:
https://www.googletagmanager.com/gtag/js - Umami: Your configured script URL
- Google Analytics:
You can also view the page source code and look for the injected scripts in the <head> section.
Troubleshooting
Analytics tools not working?
- ✅ Verify environment variables are set correctly
- ✅ Restart the application after changing variables
- ✅ Check browser console for errors
- ✅ Ensure Measurement ID/Website ID format is correct
- ✅ Check if ad blockers are interfering
Docker Users:
# Check if environment variables are set
docker exec new-api env | grep -E "GOOGLE_ANALYTICS|UMAMI"Privacy Considerations
- Google Analytics collects user data according to Google's Privacy Policy
- Umami is privacy-focused and does not collect personal data
- If using analytics tools, consider adding a privacy policy to your website
- Both tools are GDPR compliant when configured correctly
Environment Variable Reference
| Variable | Required | Default Value | Description |
|---|---|---|---|
GOOGLE_ANALYTICS_ID | No | - | Google Analytics 4 Measurement ID (format: G-XXXXXXXXXX) |
UMAMI_WEBSITE_ID | No | - | Umami Website ID (UUID format) |
UMAMI_SCRIPT_URL | No | https://analytics.umami.is/script.js | Umami Script URL (only required for self-hosted instances) |
Related Links
How is this guide?
Last updated on