How to Create a Google Analytics Tag

Cody Schneider5 min read

Setting up Google Analytics starts with one crucial step: adding a special piece of code, known as a tag, to your website. This tag is the bridge that connects your site to the Google Analytics platform, allowing it to collect valuable data about your visitors. This guide will walk you through exactly what this tag is, how to create it, and the best ways to install it on your website.

GraphedGraphed

Still Building Reports Manually?

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

Watch Graphed demo video

What is a Google Analytics Tag?

Simply put, the Google Analytics tag is a JavaScript code snippet that you place on your website. When a user visits your site, their browser runs this code, which then collects non-personally identifiable information about their session - like which pages they visited, how long they stayed, and their geographic location. This data is then sent to your Google Analytics account for you to analyze.

You'll often hear this tag referred to as the Global Site Tag (gtag.js). This is the current framework Google uses for tagging its analytics and advertising products. When you create a new Google Analytics 4 property, Google provides you with this gtag.js snippet, which includes a unique Measurement ID formatted like G-XXXXXXXXXX. This ID ensures that all the data collected from your site is sent to the correct GA4 property.

Getting this tag installed correctly is the foundation for all your future data analysis. Without it, Google Analytics can't see what's happening on your website.

GraphedGraphed

Still Building Reports Manually?

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

Watch Graphed demo video

Step 1: Create a Google Analytics 4 Property

Before you can get a tag, you need a place for the data to go. This place is called a "Property" within your Google Analytics account. If you're setting up a brand-new website, this is your first task.

A Google account can have one or more Accounts. For instance, you could have an agency with a separate GA Account per client. Each Account can have one or more Properties that correlate with individual websites or apps for a business. Follow these steps to create your GA4 Property:

  1. Log into the Google Analytics homepage. If this is your first time, it will prompt you to create an account. If you already have an existing account, click 'Admin' using the gear icon in the bottom-left corner of the page.
  2. In the ‘Property’ section (middle column), click the blue ‘+ Create Property’ button.
  3. Choose a name, reporting time-zone, and the main currency you do business in.
  4. Click ‘Next’, then fill out information about your business that helps Google benchmark you against similar ones.
  5. Agree to the terms: Check the box to confirm you accept Google Analytics Terms of Service. Then click "Create".

After completing these steps, you’ll have successfully created a GA4 property. Next, it’s time to set up the data stream.

GraphedGraphed

Still Building Reports Manually?

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

Watch Graphed demo video

Step 2: Find Your Google Analytics Tag (GA4 Tracking Code)

Now it's time to set up your ‘Data Stream’. This is the source from which a GA Property receives its data. A GA property could receive data from your Android or iOS app in addition to your company's website. We'll set up the ‘web’ data stream for your company website.

  1. Choose a platform: After creating the Property, select and configure your initial data stream. You'll see these choices:
  2. Click "Web".
  3. Fill out Website URL and Stream Name. Enter your domain (e.g., your-website.com), and give a name to your site (e.g., "Your Website").
  4. Click "Create Stream".

Once done, you'll see the Web Stream metrics page. The Measurement ID is in the top-right corner. To get your Google Analytics tag code, go to the 'Tagging instructions' at the bottom of the screen and click 'View tag instructions.'

Installing Your Google Analytics Tag

Your Google Analytics tag is now created and ready to be added to your website’s code. When you see the 'tagging instructions' window, there are several ways to install your tag, depending on your platform. Here are some methods:

Method 1: With a Website Builder

If you use common builders like Squarespace, Weebly, Wix, or WordPress, click 'Install with Website Builder,' and Google will show specific instructions for how to add the code on your platform.

GraphedGraphed

Still Building Reports Manually?

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

Watch Graphed demo video

Method 2: Manual Installation

If you prefer adding the tag code directly to your website’s HTML files, choose this technique. Copy the code snippet that starts with `<!-- Global Site Tag (gtag.js). --->

<!-- Global Site Tag (gtag.js) - Google Analytics -->
<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>

Paste the script immediately after the <head> element of your website. You want to load this script as early as possible so it does not miss any data. You might have to do this in the 'header.html' file depending on your system.

Method 3: Using Google Tag Manager

Google Tag Manager (GTM) is a powerful tool that centralizes all of your website’s tags in one place. This method is recommended as it provides great flexibility and does not require editing your HTML code each time you make a new change.

To install GTM:

  1. Create a Google Tag Manager account if you do not already have one.
  2. Create a new 'Workspace' and click ‘Tags’.
  3. Click Tag Configuration and choose 'Google Analytics GA4 Configuration' for the tag type.
  4. Enter your unique Measurement ID.
  5. Set the tag to trigger on 'All Pages' or 'Some Pages' based on your preference.
  6. Click 'Submit' to publish your changes.

Final Thoughts

Creating and installing your Google Analytics system initially sets up your website to have data-driven insights. The code gives you your first analytical tool to track your site's traffic, ultimately allowing for smarter business decisions. It simplifies the process as a seamless integration to your Google Analytics setup, providing an easy-to-use reporting process so you're always informed.

Related Articles