Running the analytics pull on a new machine or in the cloud
Running the analytics pull on a new machine or in the cloud
The scheduled GitHub Actions job runs every day at 08:17 UTC. It refreshes the prior 14 days and commits changed CSVs and last-pull.json to main. It also refreshes one summary file for the most recent Wednesday, so a missed Wednesday run catches up the next day. The rolling window catches late Google Search Console data and missed runs. A source failure makes the job fail and prevents a partial data commit; inspect the Actions run and re-run it after fixing access.
The browser logins happen once, on a machine with a browser. Each login leaves a small file holding a read-only refresh token. Those files, plus the Twenty and Umami keys, are all that any other machine needs: the pull script uses only Python 3 (no gcloud, no browser). Tested 17 Oct 2026 by copying the files to a fresh directory and running the pull.
What the credentials are
File (under ~/.config/) | Gives | Revoke at |
|---|---|---|
gcloud-lifeitself/application_default_credentials.json | Read-only GA4 + Search Console, rufus@lifeitself.org | that account's Google "Third-party access" page |
gcloud-datopian/application_default_credentials.json | Same, rufus.pollock@datopian.com | same |
gcloud-rufuspollock/application_default_credentials.json | Same, rufus@rufuspollock.com | same |
umami/api-key | Self-hosted Umami at umami.lifeitself.org (API key) | Umami, Settings, API keys |
twenty/apikey | Twenty CRM (shared Life Itself workspace; admin key, a read-only key would be better) | Twenty settings |
The Google tokens do not expire on a schedule (the OAuth client is published, and scripts/google_login.py asks only for read-only Analytics and Search Console, so Workspace "Google Cloud session control" does not apply), but revoking access, changing the password or six months unused will invalidate them. The script then reports "token refresh failed for python3 scripts/google_login.py <account>, see setup-checklist.md, step 3) and copy the new file out again.
New machine (Mac or Linux)
- Clone this repo.
- From the old machine, bundle the credentials into one file and copy it over:
scripts/analytics_creds.sh pack ~/analytics-creds.b64
scp ~/analytics-creds.b64 NEWHOST:~/
- On the new machine, unpack it (into
~/.configby default), delete the bundle, and test:
scripts/analytics_creds.sh unpack < ~/analytics-creds.b64 && rm ~/analytics-creds.b64
python3 scripts/analytics_pull.py --days 3
- For a local fallback on a Mac, run
scripts/analytics_weekly.shmanually. On Linux, use a cron line if needed:0 8 * * 3 cd ~/src/life-itself/marketing && python3 scripts/analytics_pull.py --days 14 && python3 scripts/analytics_summary.py.
GitHub Actions credentials
The encrypted rufuspollock/secrets/.env.analytics is committed in the secrets repo. It has its own dotenvx key; the general .env key is not available to the marketing workflow. The file contains only GOOGLE_LIFEITSELF_ADC_JSON, GOOGLE_DATOPIAN_ADC_JSON, GOOGLE_RUFUSPOLLOCK_ADC_JSON, TWENTY_API_KEY, and UMAMI_API_KEY. The Python pull uses these environment variables in cloud and falls back to local ~/.config files on a Mac. TWENTY_API_KEY here is the read-only key marketing-analytics-readonly (role Analytics Read Only, since 2026-11-20). The admin/write key for CRM work stays in the general .env as TWENTY_API_KEY; the read-only one is also there as TWENTY_ANALYTICS_READONLY_API_KEY.
The workflow needs two Actions secrets in life-itself/marketing: ANALYTICS_SECRETS_DEPLOY_KEY (a read-only SSH deploy key for rufuspollock/secrets) and DOTENV_PRIVATE_KEY_ANALYTICS (the key from .env.analytics.keys, never committed). Only the analytics workflow references them; anyone who can change workflows on main could use them. To rotate a source credential, update .env.analytics with dotenvx in the secrets repo and push it. To rotate the decryption key or deploy key, update the corresponding Actions secret too.
Run manually from the Actions tab using Refresh analytics → Run workflow. A cloud runner needs outbound access to oauth2.googleapis.com, analyticsdata.googleapis.com, www.googleapis.com, life-itself.twenty.com, and umami.lifeitself.org.
Adding a fourth Google account later
Run the login once on a Mac (setup-checklist.md, step 3, with a new gcloud-<name> folder), add <name> to FILES in scripts/analytics_creds.sh, re-pack, and update the secret.