A minimal static two-page website for testing Google Analytics 4, deployed to GitHub Pages via GitHub Actions.
| File | Purpose |
|---|---|
index.html |
Home page (route 1) |
about.html |
About page (route 2) |
styles.css |
Shared styling |
app.js |
"Start a new session" button behavior |
.github/workflows/deploy.yml |
GitHub Actions → GitHub Pages deploy |
.nojekyll |
Tells Pages to skip Jekyll processing |
- In Google Analytics create a GA4
property and a Web data stream for your Pages URL
(
https://<username>.github.io/<repo>/). - Copy the Measurement ID (looks like
G-XXXXXXXXXX). - Replace
G-XXXXXXXXXXin bothindex.htmlandabout.html. It appears twice per file (in the scriptsrcURL and theGA_MEASUREMENT_IDvariable) — 4 replacements total.
git init
git add .
git commit -m "Initial GA test site"
git branch -M main
git remote add origin https://github.com/<username>/<repo>.git
git push -u origin mainThe repo must be public for free GitHub Pages (or you need a paid plan).
In the repo: Settings → Pages → Build and deployment → Source: GitHub
Actions. The workflow runs on every push to main (and can be triggered
manually from the Actions tab). Once it succeeds, your site is live at the
URL shown in the workflow's deploy step.
- New tab = new session. GA4 normally shares one session across tabs. Each
page uses per-tab
sessionStorageto detect a fresh tab and mint a uniquesession_id, so opening the site in a new tab counts as a new session / unique visit. Closing the tab clears the flag. - Same-tab reset. Click "Start a new session" on either page to clear the flag and reload, forcing a fresh session without opening a new tab.
- Two routes.
index.htmlandabout.htmlare tracked as separate page views — check Reports → Engagement → Pages and screens in GA4.
Open browser dev tools → Network tab → filter for collect. You'll see a
request fire to Google on each page view and session start. GA4's Realtime
report also shows activity within a few seconds.