How to Insert Google Analytics Code
Getting Google Analytics set up on your website is the first critical step toward understanding your audience and measuring your marketing efforts. This brief guide cuts straight to the chase, walking you through how to find your Google Analytics tracking code and the best ways to install it on your site - no matter what platform you're using.
Finding Your Google Analytics Tracking Code
Before you can install anything, you need to grab your unique tracking code from Google Analytics. This involves two key pieces of information: your Measurement ID and the Global Site Tag (gtag.js) script. All modern setups use Google Analytics 4, so the process always starts there.
Step 1: Get Your GA4 Property and Data Stream
First, log in to your Google Analytics account. If you're starting fresh, Google will guide you through creating a new account and your first property. If you have an older account, ensure you have a GA4 property set up.
Once you're in your GA4 property, you need to find your "Data Stream," which is the source of data for your reports (in this case, your website).
- In the bottom-left corner, click Admin (the gear icon).
- In the Property column, click on Data Streams.
- Click on the data stream that corresponds to your website. If you don't have one, create one now by clicking "Add stream" and selecting "Web."
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Step 2: Locate Your Measurement ID and Global Site Tag
After clicking on your data stream, you'll see all the information you need on the "Web stream details" page.
Your Measurement ID
At the top-right, you'll see the Measurement ID, which looks something like G-XXXXXXXXXX. Many plugins and website builders will only ask for this ID, making setup incredibly simple.
The Global Site Tag (gtag.js)
For manual installations or more direct control, you'll need the full JavaScript snippet. Here's how to find it:
- On the "Web stream details" page, scroll down to the section titled Events. Look for the "View tag instructions" button. Click on it.
- A new tab or overlay will appear. Under "Installation instructions," select the Install manually tab.
- You will see a block of code starting with
<!-- Google tag (gtag.js) -->. This is your Global Site Tag. This is the code you'll copy and paste directly into your website's HTML.
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-YOUR_MEASUREMENT_ID"></script>
<script>
window.dataLayer = window.dataLayer || [],
function gtag(){dataLayer.push(arguments),}
gtag('js', new Date()),
gtag('config', 'G-YOUR_MEASUREMENT_ID'),
</script>How to Add the GA Code: Three Common Methods
Now that you have your code, it's time to install it. There are three common ways to do this, ranging from incredibly simple to more advanced and scalable.
- Method 1: Use a CMS Plugin or Integration. Best for users on platforms like WordPress, Shopify, Squarespace, or Wix. It's the easiest and safest method for beginners.
- Method 2: Manually Insert the Code. For those with custom-built websites or those who have direct access to their site's HTML files. It requires a bit more care but is very straightforward.
- Method 3: Use Google Tag Manager (GTM). The most robust and flexible approach. Best for marketers who plan to manage multiple tracking scripts (like Facebook Pixel, LinkedIn Insight Tag, etc.) over time.
Method 1: Using CMS Integrations and Plugins (The Easiest Way)
Most modern website platforms know how crucial analytics are, so they've made integrating Google Analytics incredibly simple. In many cases, you just need your Measurement ID (the G-XXXXXXXXXX one).
Installing on WordPress
WordPress users have two great options: using a dedicated analytics plugin or leveraging a feature within their theme.
Using a Plugin (Recommended)
A plugin is the best method for most WordPress users because it's simple, update-proof, and often comes with extra features like dashboard reports right inside WordPress.
- From your WordPress dashboard, go to Plugins > Add New.
- Search for a popular analytics plugin. Site Kit by Google is Google's official plugin and is an excellent, free choice. Other strong options include MonsterInsights and ExactMetrics.
- Click Install Now and then Activate.
- Follow the on-screen setup wizard. For Site Kit, you'll simply connect your Google account, and the plugin will automatically find your GA4 property and place the code for you. The whole process takes just a few clicks.
Using Your Theme's Settings
Some themes have built-in areas to paste tracking scripts. Check your theme's settings or the "Customize" panel for a section labeled "Header/Footer Scripts," "Code Injection," or "Integrations." If you find this section, simply copy the full Global Site Tag (gtag.js) snippet from GA and paste it into the "Header Scripts" box and save.
Installing on Shopify
Shopify makes this beautifully simple. Do not try to edit your theme files directly for this, use Shopify's built-in tool.
- From your Shopify Admin dashboard, go to Online Store > Preferences.
- Scroll down to the Google Analytics section.
- Paste your Measurement ID (
G-XXXXXXXXXX) into the field. Shopify's connection automatically handles all the e-commerce tracking features a store needs. - Click Save. You're all set!
Installing on Squarespace or Wix
Both Squarespace and Wix have native integrations that only require your Measurement ID.
- For Wix: Go to Marketing & SEO > Marketing Integrations. Find the Google Analytics block, click "Connect," and then "Connect Google Analytics." Paste your Measurement ID when prompted.
- For Squarespace: Go to Settings > Third-Party Tools. Click "Add" or "Edit" on the Google Analytics option and paste in your Measurement ID.
Method 2: Manually Adding the Code to Your Site's HTML
If you have a static site or a custom-built platform, you'll need to add the code directly to your site's files. The goal is to place the Global Site Tag in the <head> section of every page on your website.
The code must go inside the <head> tag because this ensures it loads early on every page, which is necessary for accurate tracking.
- Copy the entire Global Site Tag (gtag.js) snippet from your GA4 Data Stream settings.
- Open your website's source files. Find the template file that controls your site's header - this might be named
header.php,head.html, or something similar depending on your setup. - Paste the entire code block just before the closing
</head>tag. - Save the file and upload it to your server if needed. The script will now be present on every page that uses that header template.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Method 3: Using Google Tag Manager (The Scalable Way)
Google Tag Manager (GTM) is a free tool that acts like a container for all your other tracking codes. Instead of adding several scripts to your site, you just add the GTM script once. Then, you can manage, add, or remove other scripts (like GA4) from within the GTM interface, with no more coding required. It's the preferred method for marketers.
- Set up a Google Tag Manager account and create a new container for your website.
- GTM will provide you with two code snippets - one for the
<head>and one for the<body>. Add these snippets to your site's code, similar to the manual installation method. - Inside your GTM container, create a new tag. Choose the tag type Google Analytics: GA4 Configuration.
- In the "Measurement ID" field, paste your GA4 ID (
G-XXXXXXXXXX). - Next, set up the trigger. For basic page tracking, select the pre-built Initialization - All Pages trigger. This tells GTM to fire your GA tag on every page.
- Save the tag, then click Submit and Publish in the top-right of your GTM dashboard to push the changes live.
How to Verify Your Installation is Working
After you’ve added the code, don't just assume it's working. Always verify it. The easiest way is with Google's own Realtime report.
- Open a new browser window (ideally an incognito or private window) and navigate to your website. Click around a few pages.
- In your Google Analytics account, go to Reports > Realtime.
- Within a minute or so, you should see at least one visitor (that's you!) on the map and in the card labeled "Users in last 30 minutes."
If you can see yourself in the Realtime report, congratulations - you have successfully installed Google Analytics!
Final Thoughts
Installing your Google Analytics code is a foundational step for making data-driven decisions. Whether you choose the simplicity of a CMS plugin, the direct control of manual installation, or the scalability of Google Tag Manager, getting it done correctly opens the door to truly understanding your website's performance and audience.
Once your data starts flowing into Google Analytics, the next challenge is making sense of it all. Instead of getting bogged down trying to build reports or decipher GA4's complex interface, we built Graphed to simplify the entire process. Once you connect your GA account, you can instantly create dashboards and ask questions in plain English - like "Which marketing channels brought the most new users this month?" - and get immediate answers without the steep learning curve.
Related Articles
How to Create Facebook Ads API for Claude Code
Create a Meta Marketing API access token that never expires, using a system user, so Claude Code can pull Facebook ad reports and manage campaigns.
ClickHouse vs Postgres: When to Switch to Columnar
Comparing ClickHouse vs PostgreSQL means matching storage architecture to workload. Row storage wins for transactions. Columnar wins for scan-heavy analytics.
Google Ads for Orthodontists: Get More Booked Consults
Most orthodontic Google Ads campaigns waste money on low-intent searches. The problem is structure, not the platform.