How to Set Up Google Analytics Tracking Code
Getting your website analytics set up correctly is the first step toward understanding your visitors and growing your business. This tutorial walks you through exactly how to find and install the Google Analytics 4 tracking code. We'll cover the three most common installation methods so you can choose the one that’s right for you.
What Exactly is the Google Analytics Tracking Code?
The Google Analytics tracking code is a special snippet of JavaScript, also known as the Google Tag (gtag.js). When you add this code to your website, it acts like a messenger between your site and your Google Analytics account.
Every time someone visits a page, this script runs in their browser. It collects anonymous information about their session - like what page they're viewing, the device they're using, how they found your site, and where they are geographically - and sends all of that useful data straight to your GA4 property for analysis. Without this code, Google Analytics has no way of knowing what’s happening on your website.
Step 1: Finding Your Google Tag ID and Tracking Snippet
Before you can install the code, you need to find it. This requires having a Google Analytics 4 property set up. If you haven't created one yet, head over to the Google Analytics site and follow the prompts to create an account and your first property.
Once your property is ready, here’s how to locate your code:
- Log in to your Google Analytics account.
- Click the Admin gear icon in the bottom-left corner.
- In the Property column, make sure the correct GA4 property is selected.
- Click on Data Streams, then select the data stream for your website (it's often the only one there).
- On the Web stream details page, scroll down to the section titled Google tag and click on View tag instructions.
This will open a new page. You will see two key pieces of information:
- Your Google Tag ID: This is a unique identifier that looks like G-XXXXXXXXXX. You'll use this for most plugin and integration setups.
- The Full Tracking Snippet: Under the "Install manually" tab, you'll see the full JavaScript code. This is what you'll need if you're adding the code directly to your site’s HTML.
It should look something like this:
<!-- 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>Keep this tab open. Now you're ready to choose your installation method.
Step 2: Choose Your Installation Method
There are three main ways to install the tracking code. The best option depends entirely on how your website is built and your comfort level with code.
Method 1: Adding the Code Directly to Your Website's HTML
This is the classic manual method. It involves editing your website’s theme files to paste the code snippet directly into the HTML.
Who it's for: Best for static HTML websites or for users who are comfortable editing theme files and know that their changes won't be overwritten.
How to do it:
- Copy the entire tracking code snippet from the "Install manually" tab in Google Analytics.
- Access your website's source code. For many content management systems like WordPress, this might be a file named
header.phpor a similar template file that controls the global header of your site. - Find the opening
<head>tag. - Paste the tracking code snippet on a new line immediately after the
<head>tag. It’s important to place it here so it loads on every single page of your website. - Save the file and upload it back to your server.
Benefit: It’s direct and doesn't require extra tools. Drawback: This method can be risky. If you make a mistake, you might break your site's layout. A more significant issue is that theme updates will often overwrite your manual changes, causing you to lose tracking without realizing it.
Method 2: Using Google Tag Manager (The Recommended Way)
Google Tag Manager (GTM) is a free tool that acts as a middleman between your website and your various marketing/analytics tags (like Google Analytics, Facebook Pixel, etc.). Instead of adding lots of code snippets to your site, you add just one GTM snippet. Then, you manage all your other tags from the GTM interface.
Who it's for: Everyone. It's the industry best practice because it keeps your website code clean, simplifies tag management, and reduces reliance on developers for marketing changes.
How to do it:
- If you don't already have one, create a Google Tag Manager account and container for your website. Follow the instructions GTM provides to add its single code snippet to your site.
- Inside your GTM dashboard, navigate to Tags and click New.
- Give your tag a descriptive name, like "GA4 Configuration - All Pages".
- Click inside the Tag Configuration box and choose Google Analytics: GA4 Configuration from the list.
- In the Measurement ID field, paste your Google Tag ID (your G-XXXXXXXXXX ID, not the whole snippet).
- Next, click inside the Triggering box and select All Pages - Page View. This tells GTM to fire the GA4 tag on every page load.
- Click Save.
- Finally, in the top right corner of GTM, click Submit, give your version a name (like "Added GA4 Tag"), and click Publish. Your changes are not live until you publish!
Method 3: Using a CMS Plugin or Platform Integration
Most popular website platforms like WordPress, Shopify, Wix, and Squarespace have made this process incredibly easy with native integrations or official plugins.
Who it's for: Users on popular platforms who want the simplest, no-code installation method available.
For WordPress:
The easiest way is with a plugin. Google's official Site Kit is a great choice as it also integrates Search Console and other Google services. Other popular options include MonsterInsights or GA Google Analytics. The process is generally the same:
- Install and activate your chosen plugin from the WordPress Dashboard (Plugins > Add New).
- Follow the plugin's setup wizard to connect your Google account.
- When prompted, authorize access and select the correct Analytics property and data stream. The plugin handles adding the code to the right place for you. All you do is click and connect.
For Shopify:
Shopify has a fantastic native integration that even helps with e-commerce tracking.
- From your Shopify Admin, go to Online Store > Preferences.
- Scroll down to the Google Analytics section.
- Here, you simply need to paste your Google Tag ID (the G-XXXXXXXXX one) into the box provided.
- Click Save. Shopify will now automatically add the necessary code and start tracking standard e-commerce events like 'add_to_cart' and 'purchase'.
Step 3: Verifying Your Tracking is Working
Don’t just assume it’s working! It’s crucial to verify your setup to ensure you’re collecting accurate data. Here are two easy ways to do it.
Check the Realtime Report in GA4
This is the simplest gut-check.
- Go to your Google Analytics property.
- In the left-hand navigation, go to Reports > Realtime.
- In a new browser tab or on your phone, open your website and navigate to a few pages.
- You should see yourself appear as a visitor in the Realtime report within a minute or two. Seeing "1" in the "Users in last 30 minutes" card is a great sign!
Use the Tag Assistant Companion Chrome Extension
For a more technical confirmation, use Google's own browser extension.
- Install the Tag Assistant Companion from the Chrome Web Store.
- Visit your website.
- Click the Tag Assistant icon in your browser's toolbar, and on the dropdown click "Done". Then refresh the page.
- Click the extension icon again. It will detect the Google tags firing on your page. If you see your Google Tag ID (G-XXXXXXXXXX) listed with a green or blue icon next to it, congratulations! Your tag is installed correctly and sending data.
Final Thoughts
You’ve now learned how to find your Google Analytics tracking code and install it on your site, either directly into the HTML, through Google Tag Manager, or by using a simple CMS integration. Now that you're collecting data, you're on your way to making better, data-informed decisions for your business.
Gathering data is just the first step, the real value comes from turning that data into clear insights. We built Graphed because we believe anyone should be able to get answers from their data without a steep learning curve. After you connect Google Analytics, you can stop fighting with complex reports and simply ask questions in plain English, like "Show me my top traffic sources last month" or "Chart conversion rates by landing page." Graphed instantly builds the dashboards you need, so you can spend less time wrangling data and more time acting on it.
Related Articles
How to Connect Facebook to Google Data Studio: The Complete Guide for 2026
Connecting Facebook Ads to Google Data Studio (now called Looker Studio) has become essential for digital marketers who want to create comprehensive, visually appealing reports that go beyond the basic analytics provided by Facebook's native Ads Manager. If you're struggling with fragmented reporting across multiple platforms or spending too much time manually exporting data, this guide will show you exactly how to streamline your Facebook advertising analytics.
Appsflyer vs Mixpanel: Complete 2026 Comparison Guide
The difference between AppsFlyer and Mixpanel isn't just about features—it's about understanding two fundamentally different approaches to data that can make or break your growth strategy. One tracks how users find you, the other reveals what they do once they arrive. Most companies need insights from both worlds, but knowing where to start can save you months of implementation headaches and thousands in wasted budget.
DashThis vs AgencyAnalytics: The Ultimate Comparison Guide for Marketing Agencies
When it comes to choosing the right marketing reporting platform, agencies often find themselves torn between two industry leaders: DashThis and AgencyAnalytics. Both platforms promise to streamline reporting, save time, and impress clients with stunning visualizations. But which one truly delivers on these promises?