How to Send Data to Google Analytics
Sending the right data to Google Analytics is the first step toward understanding how people interact with your website or app. This guide will walk you through the primary methods for getting your data into Google Analytics 4, from the basic website setup to sending custom events and tracking offline conversions.
Understanding How Google Analytics Collects Data
Before you start sending data, it’s helpful to know how Google Analytics 4 actually receives and processes it. Unlike its predecessor which was built around sessions and pageviews, GA4 uses a flexible, event-based model. Everything a user does - from viewing a page to clicking a button - is tracked as an event.
Data gets into your GA4 property through a few key mechanisms:
- The Google Tag (gtag.js): This is a JavaScript library that you add to your website. It's the simplest way to get data flowing. It automatically collects some events and allows you to send your own custom events.
- Google Tag Manager (GTM): A more powerful and flexible tool that acts as a middleman. Instead of adding multiple code snippets to your site for analytics, ads, and other tools, you just add the GTM snippet. Then, you manage all your other "tags" (like the Google Analytics tag) within the GTM interface.
- The Measurement Protocol: This is an advanced method that lets you send data directly to Google's servers from any internet-connected device, like a point-of-sale system or a CRM. This is ideal for tracking offline interactions and server-side events.
- Firebase SDK: For mobile apps (iOS and Android), the Firebase Software Development Kit (SDK) is the standard way to send user interaction data to Google Analytics.
For most website owners, you'll be choosing between the direct Google Tag (gtag.js) installation or using Google Tag Manager. We’ll cover both in detail.
Method 1: Direct Installation with the Google Tag (gtag.js)
This is the most straightforward method. It involves finding your GA4 tracking code and placing it directly into the HTML of your website. This is a good option if you have a simple website, only need basic tracking, and are comfortable editing your site's code.
Step 1: Find Your Measurement ID and Tracking Snippet
First, you need to get the unique code snippet for your GA4 property.
- Log in to your Google Analytics account.
- If you have multiple accounts or properties, make sure you've selected the correct GA4 property.
- In the bottom-left corner, click Admin (the gear icon).
- In the Property column, click on Data Streams.
- Select your web data stream. If you don't have one, you'll need to create it by clicking "Add stream" and choosing "Web."
- Under Tagging instructions, you'll see "Install your Google tag." Click on View tag instructions.
- On the installation screen, click the Install manually tab. Here you will find your Google tag snippet, which includes your unique Measurement ID (it starts with "G-").
Step 2: Add the Code Snippet to Your Website
You need to place this entire JavaScript snippet on every page of your website that you want to track. The code must be placed immediately after the opening <head> tag of your HTML.
Here’s an example of what the code looks like:
<!-- 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>Simply copy the code from your GA4 account and paste it in the correct location on your website. If you're using a website builder like WordPress, Squarespace, or Shopify, they often have a dedicated field in their settings (usually under "Scripts," "Code Injection," or "Integrations") where you can paste this snippet without having to edit theme files directly.
Once you've added the code, GA4 will automatically start collecting "Enhanced measurement" events like page views, scrolls, outbound link clicks, and video views. But for anything more advanced, you'll want to use Google Tag Manager.
Method 2: Using Google Tag Manager (Recommended)
Google Tag Manager (GTM) is the preferred method for most marketers and developers because it’s much more flexible and scalable. It allows you to manage your GA4 tracking - and other marketing tags - from one central place without having to repeatedly edit your website's code.
Step 1: Set Up Google Tag Manager
If you don't already have one, create a GTM account and container for your website at tagmanager.google.com. GTM will give you a code snippet that needs to be placed on every page of your site. This is the only time you'll need to touch your site's code for tracking purposes.
Step 2: Create a GA4 Configuration Tag
With GTM installed on your site, you now tell it to send data to GA4.
- Inside your GTM container, navigate to Tags on the left-hand menu and click New.
- Give your tag a descriptive name, like "GA4 Configuration - Main."
- Click on Tag Configuration and choose Google Analytics: GA4 Configuration from the list.
- In the Measurement ID field, paste your "G-" Measurement ID that you found earlier.
- Keep the "Send a page view event when this configuration loads" box checked. This automatically handles page view tracking.
Step 3: Set Up a Trigger
The tag needs a "trigger" to tell it when to fire. For the main configuration tag, you want it to fire on every page.
- Under the Triggering section, click and select All Pages.
- Click Save.
This tells GTM, "On all pages of the website, load this GA4 configuration tag."
Step 4: Preview and Publish
Before making your new tag live, use GTM's Preview mode. Click the Preview button in the top-right corner, enter your website URL, and connect. A new tab of your website will open in debug mode. In your GTM preview tab (or window), you should see your "GA4 Configuration - Main" tag listed under the "Tags Fired" section. If you see it there, it's working!
Once you’ve confirmed it's working, go back to your GTM workspace and click Submit, then Publish. That’s it! Your site is now sending page view data to GA4.
How to Send Custom Event Data
The real value of GA4 comes from tracking custom events - actions that are specific and meaningful to your business, like a newsletter signup, a product added to a cart, or a "Request a Demo" button click. The process for sending these events differs slightly between gtag.js and GTM.
Sending Custom Events with gtag.js
To send a custom event with a direct gtag.js installation, you need to add another small snippet of JavaScript code to fire when the action occurs. For example, to track a click on a specific button, you might add an onclick attribute to the button’s HTML.
The basic syntax is:
gtag('event', 'your_event_name', {
'parameter_1': 'value_1',
'parameter_2': 'value_2'
}),For a newsletter signup button, your HTML might look like this:
<button onclick="gtag('event', 'newsletter_signup', {'source':'footer_cta'}),">Sign Up</button>When a user clicks this button, an event named newsletter_signup will be sent to GA4, along with a custom parameter source showing where the signup happened.
Sending Custom Events with GTM (the easier way)
This is where GTM's power shines. Let's create a custom event tag that fires when someone clicks our "Request a Demo" button.
- Create a Trigger:
- Create the Event Tag:
Now, preview and publish your changes. You’ve just set up custom event tracking without touching a single line of your website's code.
Verifying Your Data in Google Analytics
After setting everything up, you need to confirm that Google Analytics is actually receiving the data. There are two primary tools for this inside GA4:
- Realtime Report: Found under the Reports section, this shows activity that has happened on your site in the last 30 minutes. It's a great initial check to see if basic data is flowing.
- DebugView: This is a more powerful, specialized report found in the Admin > DebugView section. When you use Preview mode in GTM or use a Chrome extension like the "Google Analytics Debugger," your browser session is flagged for debug mode. DebugView will then show you a real-time, granular stream of every single event and parameter coming from your browser. This is essential for troubleshooting custom event tracking and ensuring your parameters are being sent correctly.
Final Thoughts
Learning how to send data to Google Analytics is a fundamental skill for anyone involved in digital marketing or web analytics. Whether you choose the quick gtag.js setup or the more robust Google Tag Manager method, getting events and user interactions flowing into your GA4 property is the first step toward generating actionable insights.
Once your data is connected and streaming in, the next challenge is turning it into clear dashboards and reports. Instead of grappling with complex reporting interfaces or manually building charts, we built Graphed to do the heavy lifting for you. You can connect your Google Analytics account in seconds and use simple, natural language - like "Show me a chart of user engagement by traffic source for the last month" - to instantly create the dashboards you need without the learning curve.
Related Articles
How to Enable Data Analysis in Excel
Enable Excel's hidden data analysis tools with our step-by-step guide. Uncover trends, make forecasts, and turn raw numbers into actionable insights today!
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.