How to get a Google tag to understand the traffic to your website?
A website can sit on the internet and you would never know whether anyone reads it. A Google tag is a short piece of code that you put on your pages. Every time someone opens a page, the tag sends a small, anonymous note to Google Analytics. After a few hours you can log in and see how many times each page was opened, which pages are most popular, which country the visitor was in, or how they reached your site — by typing the address directly (direct), by clicking a link on another website (referral), by clicking your link in a search engine’s results (organic search), or by clicking your link inside an AI assistant.
The tag does not tell you who the people are. It counts traffic — page views and visits — not individuals. The way it does this is: the first time a browser opens one of your pages, Google Analytics 4 (GA4, the fourth and current generation of Google Analytics, released in 2020) generates a random number called a client ID and stores it in a small text file called a cookie on your own website’s domain, as Google explains in its official cookie documentation. That number is not the person’s name, email, or a hardware device ID — it is just an anonymous label for that particular browser on that particular computer or phone. (Unless you separately set up GA4’s User-ID feature for logged-in visitors — which this note does not — Analytics never learns who the visitor is.) On later visits the same cookie is read again, so Analytics can tell that the same browser came back, without ever knowing who is using it. This note walks through getting a tag from Google and pasting it into your website, step by step.
Watch the walkthrough
Open in Google Drive (no account needed).
What you need before you start
- A Google account (a free Gmail address works).
- A website you can edit, so you can add a few lines to each page.
Step 1: Open Google Analytics
Go to analytics.google.com and sign in with your Google account. The first time you open it, Google asks you to create an account. An account is just a container for your websites; you can call it anything, for example your own name or the name of your site.
Step 2: Create a GA4 property
Inside the account, Google asks you to create a property. A property represents one website. Give it a name (for example “My Website”) and choose your time zone and currency.
Make sure the property is a GA4 property. You can tell by the
ID it shows you later: GA4 IDs start with G-.
Step 3: Add a web data stream
A property needs at least one data stream, which is the connection between your website and Google Analytics.
On the property setup screen, choose Web, then type your
website’s address (for example https://example.com) and give
the stream a name. Click Create stream.
Step 4: Copy the Google tag
After the stream is created, Google shows you a Measurement ID
that looks like G-XXXXXXXXXX, and a block of code called the
Google tag. It looks like this (with your own ID in place of
G-XXXXXXXXXX):
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>
Click the copy button next to the code in Google Analytics to copy your own version.
Step 5: Paste it into your website
Open the HTML of every page you want to measure. Find the <head>
section near the top of the file, and paste the Google tag right after the
opening <head> tag, before anything else.
<html>
<head>
<!-- paste the Google tag here -->
...
</head>
Putting it at the very top makes sure the tag loads before the rest of the page, so even visitors who leave after a second are counted. If your site uses a template or a content management system, paste the tag into the shared template once and it will appear on every page automatically. If you use an AI-integrated IDE — such as Visual Studio Code with an AI assistant — you can ask the AI to help you open the HTML of every page you want to measure and paste the Google Tag.
Step 6: Check that it works
Save your pages and open your website in a browser. Then go back to Google Analytics and open the Realtime report on the left. You should see your own visit appear within a few seconds. That is the quickest way to confirm the tag is working.
The full reports — how many people visited each page, how they reached your site (direct, referral, organic search, or an AI assistant), which pages they looked at — take a few hours to process, so come back the next day to see the first complete numbers.
What the numbers tell you
Once the tag is running, Google Analytics can show you:
- Views per page — how many times each page was opened.
- Traffic sources — how people reached your site: by typing the address directly (direct), by clicking a link on another website (referral), by clicking your link in a search engine’s results (organic search), or by clicking your link inside an AI assistant.
- Devices — the operating system (Windows, Macintosh, iOS, Android), platform / device category (desktop / mobile), and browsers (Chrome, Edge, Safari, Safari in-app, Firefox) that visitors used.
- Locations — which country or city the visitors were in.
- Popular pages — which content attracts the most attention.
Privacy and limitations
- The tag collects aggregated, anonymous data. It does not identify individuals, and you should not try to make it do so.
- Visitors who use an ad blocker or who disable JavaScript
may not be counted at all, because the tag’s script never runs. Visitors
who disable cookies are counted, but without the
_gacookie Analytics cannot tell that the same browser is returning, so every visit looks like a brand-new visitor — the number of “users” can be inflated and you lose the ability to track returning visitors. - There is a processing delay of a few hours before numbers become final. The Realtime report shows visits within seconds, which is useful only for checking that the tag is actually working. The complete reports — page views, traffic sources, devices, and locations — take a few hours to process.
- If your site is covered by privacy laws such as the General Data Protection Regulation (GDPR) in the EU, the California Consumer Privacy Act (CCPA) in California, the Personal Information Protection Law (PIPL) in mainland China, or the Personal Data (Privacy) Ordinance (PDPO) in Hong Kong, tell your visitors in a privacy policy that you use Google Analytics, and offer them a way to opt out if required.
Further reading
- Add the Google tag directly to your website — Google’s official installation instructions.
- Google Analytics — the product page and sign-up.
- How Google Analytics uses cookies on websites — Google’s developer reference for the
_gacookie and the client ID.