Skip to content

Commit cd24b9a

Browse files
committed
feat: add Plausible Analytics proxy URL to CI workflow (#333)
# Add Plausible Analytics Proxy URL Configuration and Website Deployment Documentation This PR adds proper configuration for the Plausible Analytics proxy URL used in the website: 1. Adds a new `PLAUSIBLE_PROXY_URL` environment variable to the CI workflow, sourced from the `WEBSITE_PLAUSIBLE_PROXY_URL` GitHub secret 2. Updates the `astro.config.mjs` to use this environment variable with a fallback for local development 3. Adds comprehensive deployment documentation in `pkgs/website/DEPLOYMENT.md` that explains: - Deployment targets (Cloudflare Pages) - Required GitHub secrets and their mappings to environment variables - Deployment workflow details - Local development configuration - Troubleshooting steps for common issues This change ensures the analytics proxy URL can be updated without code changes and provides clear documentation for the website deployment process.
1 parent 5f844c2 commit cd24b9a

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ jobs:
154154
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
155155
VITE_SUPABASE_URL: ${{ github.event_name == 'pull_request' && secrets.WEBSITE_PREVIEW_SUPABASE_URL || secrets.WEBSITE_PRODUCTION_SUPABASE_URL }}
156156
VITE_SUPABASE_ANON_KEY: ${{ github.event_name == 'pull_request' && secrets.WEBSITE_PREVIEW_SUPABASE_ANON_KEY || secrets.WEBSITE_PRODUCTION_SUPABASE_ANON_KEY }}
157+
PLAUSIBLE_PROXY_URL: ${{ secrets.WEBSITE_PLAUSIBLE_PROXY_URL }}
157158
steps:
158159
- uses: actions/checkout@v4
159160
with:

pkgs/website/DEPLOYMENT.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Website Deployment
2+
3+
This document describes the deployment configuration for the pgflow documentation website.
4+
5+
## Deployment Target
6+
7+
The website is deployed to **Cloudflare Pages** via GitHub Actions workflow.
8+
9+
- **Production URL**: https://www.pgflow.dev
10+
- **Preview URLs**: https://pr-{number}.pgflow.pages.dev (for pull requests)
11+
12+
## Required GitHub Secrets
13+
14+
The following secrets must be configured in the GitHub repository (Settings → Secrets and variables → Actions).
15+
16+
**Note**: Some secrets are namespaced (e.g., `WEBSITE_*`) at the GitHub level but are mapped to simpler names (e.g., `VITE_*`, `PLAUSIBLE_PROXY_URL`) when passed as environment variables to the build process.
17+
18+
### Cloudflare Configuration
19+
20+
- **`CLOUDFLARE_API_TOKEN`**
21+
- **GitHub Secret Name**: `CLOUDFLARE_API_TOKEN`
22+
- **Environment variable**: `CLOUDFLARE_API_TOKEN`
23+
- API token for deploying to Cloudflare Pages
24+
25+
- **`CLOUDFLARE_ACCOUNT_ID`**
26+
- **GitHub Secret Name**: `CLOUDFLARE_ACCOUNT_ID`
27+
- **Environment variable**: `CLOUDFLARE_ACCOUNT_ID`
28+
- Cloudflare account ID
29+
30+
### Supabase Configuration
31+
32+
Website deployment requires Supabase configuration for both preview and production environments:
33+
34+
**Preview Environment:**
35+
- **`WEBSITE_PREVIEW_SUPABASE_URL`**
36+
- **GitHub Secret Name**: `WEBSITE_PREVIEW_SUPABASE_URL`
37+
- **Maps to environment variable**: `VITE_SUPABASE_URL` (in preview deployments)
38+
- Supabase project URL for preview deployments
39+
40+
- **`WEBSITE_PREVIEW_SUPABASE_ANON_KEY`**
41+
- **GitHub Secret Name**: `WEBSITE_PREVIEW_SUPABASE_ANON_KEY`
42+
- **Maps to environment variable**: `VITE_SUPABASE_ANON_KEY` (in preview deployments)
43+
- Supabase anonymous key for preview deployments
44+
45+
**Production Environment:**
46+
- **`WEBSITE_PRODUCTION_SUPABASE_URL`**
47+
- **GitHub Secret Name**: `WEBSITE_PRODUCTION_SUPABASE_URL`
48+
- **Maps to environment variable**: `VITE_SUPABASE_URL` (in production deployments)
49+
- Supabase project URL for production
50+
51+
- **`WEBSITE_PRODUCTION_SUPABASE_ANON_KEY`**
52+
- **GitHub Secret Name**: `WEBSITE_PRODUCTION_SUPABASE_ANON_KEY`
53+
- **Maps to environment variable**: `VITE_SUPABASE_ANON_KEY` (in production deployments)
54+
- Supabase anonymous key for production
55+
56+
### Analytics Configuration
57+
58+
- **`WEBSITE_PLAUSIBLE_PROXY_URL`** - Cloudflare Workers proxy URL for Plausible Analytics (website-specific)
59+
- **GitHub Secret Name**: `WEBSITE_PLAUSIBLE_PROXY_URL`
60+
- **Maps to environment variable**: `PLAUSIBLE_PROXY_URL` (used in `astro.config.mjs`)
61+
- Example value: `https://your-worker-name.your-username.workers.dev`
62+
- This proxies requests to Plausible to avoid ad blockers
63+
- If this URL becomes invalid, Plausible tracking will stop working
64+
- Note: This is separate from demo app analytics which uses its own proxy URL
65+
66+
## Deployment Workflow
67+
68+
The deployment is handled by the `deploy-website` job in `.github/workflows/ci.yml`:
69+
70+
1. **Trigger**: Runs on push to `main` or when a pull request is opened/updated
71+
2. **Affected Check**: Only deploys if the website package is affected by changes (using Nx)
72+
3. **Build**: Builds the website with environment variables injected
73+
4. **Deploy**:
74+
- Production: Deploys to main branch on Cloudflare Pages
75+
- Preview: Deploys to PR-specific branch on Cloudflare Pages
76+
77+
## Local Development
78+
79+
For local development, the Plausible proxy URL falls back to a hardcoded value in `astro.config.mjs` if the `PLAUSIBLE_PROXY_URL` environment variable is not set.
80+
81+
To test with a specific proxy URL locally:
82+
83+
```bash
84+
PLAUSIBLE_PROXY_URL=https://your-worker.your-username.workers.dev pnpm nx dev website
85+
```
86+
87+
## Troubleshooting
88+
89+
### Plausible Analytics Not Tracking
90+
91+
If Plausible stops tracking visitors:
92+
93+
1. Check if the Cloudflare Workers proxy URL is accessible:
94+
```bash
95+
curl -I https://your-worker-name.your-username.workers.dev/assets/script.hash.outbound-links.pageview-props.tagged-events.js
96+
```
97+
98+
2. If the URL fails (DNS resolution error or 404), update the `WEBSITE_PLAUSIBLE_PROXY_URL` secret in GitHub with the correct URL
99+
100+
3. The proxy URL may change if the Cloudflare Workers username changes
101+
102+
4. After updating the secret, redeploy the website (push to `main` or re-run the workflow)
103+
104+
### Deployment Fails
105+
106+
- Verify all required secrets are configured in GitHub
107+
- Check the GitHub Actions workflow logs for specific error messages
108+
- Ensure the Cloudflare API token has the necessary permissions (Account → Cloudflare Pages - Edit)

pkgs/website/astro.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const GITHUB_REPO_URL = 'https://github.com/pgflow-dev/pgflow';
1717
const DISCORD_INVITE_URL = 'https://pgflow.dev/discord/';
1818
const EMAIL_URL = 'mailto:hello@pgflow.dev';
1919
const PLAUSIBLE_PROXY = {
20-
url: 'https://wispy-pond-c6f8.wojciech-majewski.workers.dev',
20+
url: process.env.PLAUSIBLE_PROXY_URL || 'https://wispy-pond-c6f8.jumski.workers.dev',
2121
eventPath: '/data/event',
2222
scriptPath:
2323
'/assets/script.hash.outbound-links.pageview-props.tagged-events.js',

0 commit comments

Comments
 (0)