|
| 1 | +# Hall Analytics Setup for AWS Amplify |
| 2 | + |
| 3 | +## Environment Variable Setup |
| 4 | + |
| 5 | +Since AWS Amplify doesn't support server-side middleware, we've implemented client-side analytics tracking. You need to set the environment variable in your Amplify console: |
| 6 | + |
| 7 | +### 1. Set Environment Variable in Amplify |
| 8 | + |
| 9 | +1. Go to your AWS Amplify Console |
| 10 | +2. Navigate to your app → **Environment variables** |
| 11 | +3. Add a new environment variable: |
| 12 | + - **Key**: `PUBLIC_HALL_API_KEY` |
| 13 | + - **Value**: Your Hall API key |
| 14 | +4. **Redeploy** your application |
| 15 | + |
| 16 | +### 2. Verify the Setup |
| 17 | + |
| 18 | +After redeploying, you should see: |
| 19 | + |
| 20 | +1. **Browser Console Logs**: Open browser dev tools and look for: |
| 21 | + ``` |
| 22 | + [Hall Analytics] Page view tracked: /get-started/guides/first-things-first/ |
| 23 | + ``` |
| 24 | + |
| 25 | +2. **Hall Dashboard**: Check your [Hall dashboard](https://app.usehall.com) for incoming data |
| 26 | + |
| 27 | +### 3. Test the Integration |
| 28 | + |
| 29 | +Visit your site and check: |
| 30 | +- Browser console for tracking messages |
| 31 | +- Hall dashboard for new visits |
| 32 | +- Network tab for requests to `analytics.usehall.com` |
| 33 | + |
| 34 | +## How Client-Side Tracking Works |
| 35 | + |
| 36 | +The client-side implementation: |
| 37 | + |
| 38 | +- **Tracks page views** when users visit pages |
| 39 | +- **Captures browser data** (User-Agent, Referer, etc.) |
| 40 | +- **Sends data asynchronously** to Hall |
| 41 | +- **Works with static hosting** like Amplify |
| 42 | +- **Handles navigation** in single-page app style |
| 43 | + |
| 44 | +## Differences from Server-Side |
| 45 | + |
| 46 | +| Aspect | Server-Side | Client-Side | |
| 47 | +|--------|-------------|-------------| |
| 48 | +| **IP Address** | Real server IP | Client IP (127.0.0.1) | |
| 49 | +| **Hosting** | Requires server | Works with static hosting | |
| 50 | +| **Performance** | No client impact | Minimal client impact | |
| 51 | +| **Reliability** | Server-side execution | Depends on client JavaScript | |
| 52 | + |
| 53 | +## Troubleshooting |
| 54 | + |
| 55 | +### If no tracking appears: |
| 56 | + |
| 57 | +1. **Check environment variable**: Ensure `PUBLIC_HALL_API_KEY` is set in Amplify |
| 58 | +2. **Check browser console**: Look for Hall Analytics messages |
| 59 | +3. **Check network tab**: Look for requests to `analytics.usehall.com` |
| 60 | +4. **Verify API key**: Test with curl command from earlier |
| 61 | + |
| 62 | +### Common issues: |
| 63 | + |
| 64 | +- **Environment variable not set**: Add `PUBLIC_HALL_API_KEY` to Amplify |
| 65 | +- **JavaScript disabled**: Client-side tracking won't work |
| 66 | +- **Ad blockers**: May block analytics requests |
| 67 | +- **CORS issues**: Should work with Hall's API |
| 68 | + |
| 69 | +## Testing Commands |
| 70 | + |
| 71 | +Test your API key manually: |
| 72 | +```bash |
| 73 | +curl -X POST https://analytics.usehall.com/visit \ |
| 74 | + -H "Content-Type: application/json" \ |
| 75 | + -H "Authorization: Bearer YOUR_API_KEY" \ |
| 76 | + -d '{"request_path":"/test","request_method":"GET","request_ip":"127.0.0.1","request_headers":{"User-Agent":"Test"},"request_timestamp":1234567890}' |
| 77 | +``` |
| 78 | + |
| 79 | +## Next Steps |
| 80 | + |
| 81 | +1. **Set the environment variable** in Amplify console |
| 82 | +2. **Redeploy** your application |
| 83 | +3. **Test by visiting** your site |
| 84 | +4. **Check Hall dashboard** for incoming data |
| 85 | +5. **Monitor browser console** for tracking messages |
0 commit comments