|
| 1 | +# Analytics Tool Setup Guide |
| 2 | + |
| 3 | +### Overview |
| 4 | + |
| 5 | +New API now supports integration with popular analytics platforms to help you track user behavior and website performance: |
| 6 | + |
| 7 | +- **Google Analytics 4 (GA4)**: The latest version of Google's analytics platform |
| 8 | +- **Umami Analytics**: A privacy-focused, open-source analytics tool |
| 9 | + |
| 10 | +Both analytics tools can be enabled simultaneously without conflict. |
| 11 | + |
| 12 | +### Key Features |
| 13 | + |
| 14 | +β
Zero-code integration - configured solely via environment variables |
| 15 | +β
Automatically injects scripts into the Web interface |
| 16 | +β
Supports Docker and Standalone deployment |
| 17 | +β
Privacy-focused implementation |
| 18 | +β
No front-end code modification required |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +### Google Analytics 4 Setup |
| 23 | + |
| 24 | +#### 1. Obtain Your Measurement ID |
| 25 | + |
| 26 | +1. Visit [Google Analytics](https://analytics.google.com/) |
| 27 | +2. Create a new property or select an existing one |
| 28 | +3. Go to **Admin** β **Data Streams** |
| 29 | +4. Create or select a web data stream |
| 30 | +5. Copy your **Measurement ID** (Format: `G-XXXXXXXXXX`) |
| 31 | + |
| 32 | +#### 2. Configure Environment Variables |
| 33 | + |
| 34 | +**Using Docker Compose:** |
| 35 | + |
| 36 | +Edit the `docker-compose.yml` file and uncomment the Google Analytics line: |
| 37 | + |
| 38 | +```yaml |
| 39 | +environment: |
| 40 | + - GOOGLE_ANALYTICS_ID=G-XXXXXXXXXX # Replace with your actual Measurement ID |
| 41 | +``` |
| 42 | +
|
| 43 | +**Standalone Deployment:** |
| 44 | +
|
| 45 | +Add to the `.env` file or set as an environment variable: |
| 46 | + |
| 47 | +```bash |
| 48 | +export GOOGLE_ANALYTICS_ID=G-XXXXXXXXXX |
| 49 | +``` |
| 50 | + |
| 51 | +**Using Docker Run:** |
| 52 | + |
| 53 | +```bash |
| 54 | +docker run -d \ |
| 55 | + -e GOOGLE_ANALYTICS_ID=G-XXXXXXXXXX \ |
| 56 | + ...ε
Άδ»ιι‘Ή... |
| 57 | + calciumion/new-api:latest |
| 58 | +``` |
| 59 | + |
| 60 | +#### 3. Restart the Application |
| 61 | + |
| 62 | +```bash |
| 63 | +# Docker Compose |
| 64 | +docker-compose down && docker-compose up -d |
| 65 | +
|
| 66 | +# Standalone Deployment |
| 67 | +# Restart your application directly |
| 68 | +``` |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +### Umami Analytics Setup |
| 73 | + |
| 74 | +#### 1. Obtain Umami Credentials |
| 75 | + |
| 76 | +**Option A: Using Umami Cloud** |
| 77 | +1. Register on [Umami Cloud](https://cloud.umami.is/) |
| 78 | +2. Add a new website |
| 79 | +3. Copy your **Website ID** (UUID format) |
| 80 | + |
| 81 | +**Option B: Self-hosting Umami** |
| 82 | +1. Deploy your own [Umami instance](https://umami.is/docs/install) |
| 83 | +2. Create a website in the dashboard |
| 84 | +3. Copy your **Website ID** and **Script URL** |
| 85 | + |
| 86 | +#### 2. Configure Environment Variables |
| 87 | + |
| 88 | +**Using Docker Compose:** |
| 89 | + |
| 90 | +Edit the `docker-compose.yml` file: |
| 91 | + |
| 92 | +```yaml |
| 93 | +environment: |
| 94 | + - UMAMI_WEBSITE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 95 | + # Optional: Only required for self-hosted instances |
| 96 | + - UMAMI_SCRIPT_URL=https://your-umami-domain.com/script.js |
| 97 | +``` |
| 98 | + |
| 99 | +**Standalone Deployment:** |
| 100 | + |
| 101 | +Add to the `.env` file: |
| 102 | + |
| 103 | +```bash |
| 104 | +export UMAMI_WEBSITE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 105 | +export UMAMI_SCRIPT_URL=https://your-umami-domain.com/script.js # Optional |
| 106 | +``` |
| 107 | + |
| 108 | +**Note:** If using Umami Cloud, you do not need to set `UMAMI_SCRIPT_URL`, as it defaults to the official URL. |
| 109 | + |
| 110 | +#### 3. Restart the Application |
| 111 | + |
| 112 | +Same as Google Analytics - restart the application to apply changes. |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +### Using Both Analytics Tools Simultaneously |
| 117 | + |
| 118 | +You can enable both Google Analytics and Umami at the same time: |
| 119 | + |
| 120 | +```yaml |
| 121 | +environment: |
| 122 | + - GOOGLE_ANALYTICS_ID=G-ABC123XYZ |
| 123 | + - UMAMI_WEBSITE_ID=a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6 |
| 124 | + - UMAMI_SCRIPT_URL=https://analytics.umami.is/script.js |
| 125 | +``` |
| 126 | + |
| 127 | +--- |
| 128 | + |
| 129 | +### Verification |
| 130 | + |
| 131 | +After restarting the application: |
| 132 | + |
| 133 | +1. Open the Web interface in your browser |
| 134 | +2. Open browser developer tools (F12) β **Network** tab |
| 135 | +3. Refresh the page |
| 136 | +4. Look for the following requests: |
| 137 | + - Google Analytics: `https://www.googletagmanager.com/gtag/js` |
| 138 | + - Umami: Your configured script URL |
| 139 | + |
| 140 | +You can also check the page source code and look for the injected script in the `<head>` section. |
| 141 | + |
| 142 | +--- |
| 143 | + |
| 144 | +### Troubleshooting |
| 145 | + |
| 146 | +**Analytics tools not working?** |
| 147 | + |
| 148 | +1. β
Verify that environment variables are set correctly |
| 149 | +2. β
Restart the application after changing variables |
| 150 | +3. β
Check the browser console for errors |
| 151 | +4. β
Ensure the Measurement ID/Website ID format is correct |
| 152 | +5. β
Check if ad blockers are interfering |
| 153 | + |
| 154 | +**Docker Users:** |
| 155 | + |
| 156 | +```bash |
| 157 | +# Check if environment variables are set |
| 158 | +docker exec new-api env | grep -E "GOOGLE_ANALYTICS|UMAMI" |
| 159 | +``` |
| 160 | + |
| 161 | +--- |
| 162 | + |
| 163 | +### Privacy Considerations |
| 164 | + |
| 165 | +- Google Analytics collects user data according to the [Google Privacy Policy](https://policies.google.com/privacy) |
| 166 | +- Umami is privacy-focused and does not collect personal data |
| 167 | +- If using analytics tools, consider adding a privacy policy to your website |
| 168 | +- Both tools, when configured correctly, can comply with GDPR requirements |
| 169 | + |
| 170 | +--- |
| 171 | + |
| 172 | +## Environment Variable Reference |
| 173 | + |
| 174 | +| Variable | Required | Default Value | Description | |
| 175 | +|------|------|--------|------| |
| 176 | +| `GOOGLE_ANALYTICS_ID` | No | - | Google Analytics 4 Measurement ID (Format: G-XXXXXXXXXX)| |
| 177 | +| `UMAMI_WEBSITE_ID` | No | - | Umami Website ID (UUID format)| |
| 178 | +| `UMAMI_SCRIPT_URL` | No | `https://analytics.umami.is/script.js` | Umami script URL (Only required for self-hosted)| |
| 179 | + |
| 180 | +--- |
| 181 | + |
| 182 | +## Related Links |
| 183 | + |
| 184 | +- [Google Analytics](https://analytics.google.com/) |
| 185 | +- [Umami Analytics](https://umami.is/) |
| 186 | +- [Umami Documentation](https://umami.is/docs) |
| 187 | +- [Google Analytics Privacy](https://support.google.com/analytics/answer/6004245) |
| 188 | + |
| 189 | +--- |
| 190 | + |
| 191 | +## Support |
| 192 | + |
| 193 | +If you encounter any issues or have questions, please: |
| 194 | +- Submit an issue on [GitHub](https://github.com/Calcium-Ion/new-api/issues) |
| 195 | +- Check existing issues for solutions |
0 commit comments