How to Create a Google Analytics Tag
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.
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.
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:
- 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.
- In the ‘Property’ section (middle column), click the blue ‘+ Create Property’ button.
- Choose a name, reporting time-zone, and the main currency you do business in.
- Click ‘Next’, then fill out information about your business that helps Google benchmark you against similar ones.
- 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.
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.
- Choose a platform: After creating the Property, select and configure your initial data stream. You'll see these choices:
- Click "Web".
- 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").
- 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.
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:
- Create a Google Tag Manager account if you do not already have one.
- Create a new 'Workspace' and click ‘Tags’.
- Click Tag Configuration and choose 'Google Analytics GA4 Configuration' for the tag type.
- Enter your unique Measurement ID.
- Set the tag to trigger on 'All Pages' or 'Some Pages' based on your preference.
- 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
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.
How to Create a Photo Album in Meta Business Suite
How to create a photo album in Meta Business Suite — step-by-step guide to organizing Facebook and Instagram photos into albums for your business page.