Setting Up Google Analytics (GA4)
Google Analytics 4 is a free, client-side analytics platform that counts real visitors in the browser. Because it runs in the visitor's browser rather than reading server logs, it gives you accurate numbers even when a CDN or cache serves most of your pages. This guide walks you through creating a property and installing the tracking code.
Why GA4 Is More Accurate
Server-side tools like AWStats and Webalizer only see requests that reach your origin server. When a CDN such as Cloudflare caches your pages, many visits are served from the CDN and never touch the origin — so those visitors are missing from your server stats.
GA4 works differently. A small piece of JavaScript loads in each visitor's browser and reports the page view directly to Google. That means:
- Every real browser is counted, whether the page came from your server or from a cache.
- A CDN in front of your site has no effect on the numbers.
- You get rich detail — sessions, engagement, devices, locations, traffic sources, and conversions.
The trade-off is that GA4 counts only visitors who run JavaScript, so it will not include most bots and crawlers. For human traffic — the audience that matters for most sites — it is the reliable source.
Step 1: Create a GA4 Property
- Go to analytics.google.com and sign in with your Google account.
- Click Admin (the gear icon), then Create → Property.
- Enter a property name (usually your website name), then set your time zone and currency.
- Answer the short business questions and click Create.
- When prompted to set up a data stream, choose Web, enter your website URL and a stream name, then click Create stream.
Step 2: Copy Your Measurement ID
After the web data stream is created, GA4 shows a Measurement ID in the format G-XXXXXXX. You can find it again any time under Admin → Data streams → your stream. Copy this ID — you will need it for the tracking snippet.
Step 3: Install the gtag.js Snippet
The most direct way to install GA4 is to add the Google tag (gtag.js) snippet to the <head> of every page. Paste it as high in the <head> as possible, and replace G-XXXXXXX with your own Measurement ID:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXX');
</script>
If you manage a static site, add the snippet to each page's HTML template. You can edit your files in the cPanel File Manager or over FTP.
<head> ensures the tag loads early and captures the page view.
Step 4: Or Use a Plugin or Tag Manager
If you would rather not edit code by hand, you have easier options:
- WordPress plugin — Install a Google Analytics plugin, or the official Site Kit by Google plugin, and paste your Measurement ID during setup. The plugin adds the tag to every page for you.
- Google Tag Manager (GTM) — Add the GTM container to your site once, then deploy your GA4 tag (and any future tags) from the GTM dashboard without touching your site code again.
These approaches are ideal if you expect to add more tags later or want to avoid editing templates directly.
Step 5: Verify in Realtime
- Open your website in a browser (an incognito window helps avoid cached versions).
- In Google Analytics, go to Reports → Realtime.
- Within a minute or so you should see at least one active user — that is you.
If nothing appears, confirm the Measurement ID is correct, that the snippet is in the <head>, and that no ad or tracking blocker is active in your test browser. Clear your cache or CDN cache if you edited a cached template.
Combining GA4 with cPanel Stats
GA4 and the built-in cPanel Metrics tools complement each other. Use GA4 for trustworthy human-visitor counts, audience insight, and conversions; use the cPanel Raw Access logs and error tools for the complete server-side record, bot activity, and troubleshooting. Together they give you the full picture of what is happening on your site.