How to Paste Tracking Code for Google Analytics

Cody Schneider9 min read

The first step to understanding who visits your website and what they do is installing your Google Analytics tracking code. This small snippet of JavaScript is the bridge that connects your website to Google's powerful analytics platform, collecting the data you need to make smarter marketing decisions. This guide will show you exactly how to find, copy, and correctly paste your Google Analytics code on your website.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

What Exactly Is the Google Analytics Tracking Code?

The Google Analytics tracking code, also known as the "GA tag" or "gtag.js," is a piece of JavaScript that you add to the code of your website. When a user visits one of your pages, this script runs in their browser. It gathers anonymous information about their session - like which page they're on, what browser they're using, and how they first found your site - and sends it back to your Google Analytics account.

In essence, this code powers all of the reports you see inside Google Analytics. Without it, your account is collecting zero data. Every insight about user demographics, popular content, traffic sources, and conversion tracking starts with this simple installation.

Previously, you might have seen code snippets called "analytics.js" (for Universal Analytics) or even older versions. As of July 2023, Google has fully shifted to Google Analytics 4. The modern global site tag (gtag.js) is designed to work seamlessly with GA4 and other Google marketing products, making it the standard for all new installations.

How to Find Your Google Analytics Tracking Code

Before you can paste the code, you need to find it. Locating your unique tracking code is a straightforward process within your Google Analytics 4 property.

Here are the steps:

  1. Log in to your Google Analytics account.
  2. Navigate to the Admin section by clicking the gear icon in the bottom-left corner of the sidebar.
  3. In the ‘Property’ column, make sure you have the correct GA4 property selected from the dropdown menu.
  4. Click on Data Streams, then select the appropriate web data stream for your website. (Most accounts will only have one).
  5. Under the "Google tag" section, click on View tag instructions.
  6. A new screen will appear. Click the Install manually tab.

Here you will see the JavaScript snippet you need to install. It will look something like this, but with your unique 'G-MEASUREMENT_ID' instead of the placeholder:

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-MEASUREMENT_ID"></script>
<script>
  window.dataLayer = window.dataLayer || [],
  function gtag(){dataLayer.push(arguments),}
  gtag('js', new Date()),

  gtag('config', 'G-MEASUREMENT_ID'),
</script>

This is the code block you'll be pasting. Use the copy icon in the top right of the code box to make sure you grab the entire snippet pixel-perfect.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Where to Paste the Google Analytics Tracking Code

Regardless of the method you choose, the rule is the same: the Google Analytics tracking code must be placed within the <head> section of your website’s HTML. It should appear immediately after the opening <head> tag and be present on every single page you want to track.

Why the <head> section? The head of an HTML document contains metadata and scripts that need to load before the visual content on the page (the <body>) does. Placing the GA tag here ensures it loads as quickly as possible, catching visitor data even if they click away before the page fully finishes rendering.

Now, let's look at the three common methods to actually get it there.

Method 1: Manually Pasting into Your Website’s HTML

This method involves editing your website's source code files directly. It offers maximum control but requires CPanel/FTP access or a theme editor within your platform. Important: Only use this method if you're comfortable editing code, as a mistake can break your site's layout or functionality. Always back up your files before making changes.

The goal is to find the core template file that generates the <head> section for all of your pages, often called something like header.php, head.html, or theme.liquid depending on your system.

For WordPress:

  1. From your dashboard, go to Appearance > Theme File Editor.
  2. On the right side, find and click on the file named “Theme Header” (header.php).
  3. Locate the opening <head> tag in the editor.
  4. Paste your copied Google Analytics code snippet on the line immediately following it.
  5. Click “Update File” to save your changes.

If you take this approach, be aware that updating your theme in the future might overwrite this file, removing your tracking code. A child theme is the proper developer way to avoid this, but it adds more complexity.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Method 2: Using a Plugin or Built-in Platform Settings

This is the most popular, safest, and highly recommended way for most users. Platforms like WordPress, Shopify, Wix, and Squarespace understand that users need to add scripts like the GA tag, so they provide designated fields or recommend official plugins to do the job without touching any code.

For WordPress Sites

While you can use the manual method, a specialized plugin is a much safer bet. These plugins ensure the code is placed correctly, won’t be erased during theme updates, and often offer extra features.

A great option is the free WPCode – Insert Headers and Footers plugin:

  1. In your WordPress dashboard, go to Plugins > Add New.
  2. Search for “WPCode” and install and activate the plugin offered by WPCode.
  3. After activation, you'll see a new "Code Snippets" menu item in your sidebar. Navigate to Code Snippets > Header & Footer.
  4. Paste your entire Google Analytics tracking code into the “Header” box.
  5. Click Save Changes.

That's it. The plugin will now inject your code into the <head> section of every page on your site.

For Shopify Stores

Shopify makes this process incredibly simple with a dedicated field for your code.

  1. From your Shopify Admin dashboard, go to Online Store > Preferences.
  2. Scroll down to the “Google Analytics” section.
  3. You’ll see a box that says "Paste your code from Google here."
  4. Paste the entire JavaScript tracking code snippet you copied from Google Analytics into this box.
  5. Click Save.

Shopify will automatically handle placing it in the correct location across all of your store's pages.

Method 3: Using Google Tag Manager (GTM)

Google Tag Manager is a central management system for all of your website's marketing and analytics tags (like the GA tag, Facebook Pixel, Google Ads conversion tag, etc.). Instead of pasting dozens of different code snippets into your site, you paste just one — the GTM container script. Then, you manage all your other tags from within the GTM interface.

This is the industry-standard method for marketers because it's flexible, powerful, and keeps your website's code clean. It also gives you granular control over when specific tags fire (e.g., track a lead form submission only on the "thank you" page).

Getting started with GTM involves a few more steps, but it pays off in the long run.

  1. Go to the Google Tag Manager website and create a new account and container for your site.
  2. GTM will then provide you with its own two snippets of code — one for the <head> and one for the <body>. Add these to your site using one of the methods described above (e.g., the WPCode plugin).
  3. Inside your GTM container, create a new tag. Choose the “Google Analytics: GA4 Configuration” tag type.
  4. In the "Measurement ID" field, paste your GA4 ID (the 'G-XXXXXXXXXX' value). You only need the ID, not the entire code snippet.
  5. Set the tag to trigger on "All Pages."
  6. Save your tag, then click "Submit" and "Publish" to push your changes live.

Now, GTM will dynamically load your GA4 script on your website instead of you having it hard-coded there.

How to Verify Your Installation is Working

After pasting your code, don't just assume it's working. You should always verify that Google is receiving data. Wait about 30-60 minutes after installation, then try one of these methods.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

1. Use the Realtime Report

This is the quickest and easiest way. Have your website open in one browser tab, and in another, go to your Google Analytics account.

  • Navigate to Reports > Realtime.
  • You should see yourself as "1" in the "Users in Last 30 Minutes" card.
  • Click around a few pages on your site, you should see the page views appear in the "Views by Page title" list within a few seconds. If you see activity, it's working!

2. Browser "View Page Source"

Do a quick manual check using your browser. On your website, right-click anywhere on the page and select “View Page Source.” This will open a new tab showing the raw HTML. Use the search function (Ctrl+F or Cmd+F) and search for "gtag.js" or your Measurement ID (G-...). If you find your tracking code snippet in the HTML, you know it has been successfully added to your site.

3. Google Tag Assistant Legacy (Chrome Extension)

Google's own free Chrome extension, Tag Assistant Legacy, scans the tags on a page. Install it, navigate to your site, click the extension icon, and enable it. Refresh your page, and the extension will pop up with a list of Google tags it found. It should show your Google Analytics tag with a green or blue icon, indicating a successful installation.

Final Thoughts

Installing your Google Analytics tracking code correctly is the foundational step for collecting website performance data. Whether you choose to paste it manually, use a user-friendly plugin, or scale up with Google Tag Manager, verifying the installation ensures you're ready to start turning user actions into actionable insights.

Of course, getting the data in is only half the battle. Making sense of it all in the often-confusing Google Analytics interface is its own challenge. At Graphed, we simplify that entire process. Once your tracking is set up, we connect directly to your Google Analytics account, allowing you to build clear, real-time dashboards and get answers just by asking questions in plain English. For anyone who's ever felt stuck manually pulling reports, we provide an effortless way to see what's actually working. You can sign up for free and create your first AI-powered dashboard in seconds with Graphed.

Related Articles