Sub topic 9
Testing and Debugging Your Tracking
Tracking that you have not tested is a guess. A missing script, a typo in an event name, or a consent default that blocks everything can leave your reports empty or wrong for weeks before anyone notices. This chapter gives you a repeatable way to check that social traffic and conversions reach GA4 correctly, and a way to find the cause when they don't.
You should already know how to install GA4 with gtag.js, send events with gtag('event', ...), build UTM-tagged links, and mark key events. This chapter assumes those steps are done. It also assumes you can open your browser's developer tools.
What you are testing
Tracking can fail at four points. Test each one separately, so you know where a problem is.
- The link. The URL a social post sends people to must carry the right UTM values.
- The page. The GA4 library must load and the page must send a request.
- The event. The action you care about must produce an event with the right name and parameters.
- The report. GA4 must process the event and attribute it to the right source, medium, and campaign.
Work from left to right. If step 2 fails, checking step 4 only wastes time.
Check the link first
Before you publish a post or launch an ad, open the final URL and read it. Most UTM mistakes are visible in the address bar.
Look for these common errors:
- Case differences.
utm_source=Instagramandutm_source=instagramappear as two different sources in reports. - Spaces and special characters. A space in
utm_campaign=spring salebecomes%20or breaks the link in some apps. Use lowercase letters, digits, and underscores. - Missing parameters. GA4 can still attribute a visit with only
utm_source, but reports become hard to read withoututm_mediumandutm_campaign. - Lost parameters after a redirect. A link shortener, a login page, or a country redirect can drop the query string. Click the link from a real post and check the address after the page settles.
- Tags on internal links. Putting UTM parameters on links inside your own site starts a new session and overwrites the original source. Use them only on links that come from outside.
You can also confirm what the page sees by running this in the browser console after landing on a tagged URL:
const params = new URLSearchParams(window.location.search);
console.log(Object.fromEntries(params.entries()));If the object printed in the console is empty, the parameters never reached the page, and no later step can fix that.
Check that the page sends data
Open your site in a browser, then open developer tools and go to the Network tab. Reload the page and filter by collect. GA4 sends hits to a URL that contains /g/collect.
For each request, select it and read the query parameters:
| Parameter | Meaning | What to check |
|---|---|---|
| `tid` | Measurement ID | Matches your `G-XXXXXXXXXX` value |
| `en` | Event name | `page_view`, `sign_up`, or your custom name |
| `dl` | Document location | Includes your `utm_` parameters on the landing page |
| `gcs` | Consent state | Shows whether analytics storage is granted |
| `cid` | Client ID | Stable across pages in the same browser |
If no collect request appears, check these causes in order:
- The snippet is missing from this page, or it sits in a template that this page does not use.
- A browser extension such as an ad blocker is blocking the request. Test in a private window with extensions off.
- A script error earlier on the page stopped
gtagfrom running. Look at the Console tab for red errors. - Consent defaults are set to denied, and your banner never grants them. In this case you may see a request with limited data, or none at all.
You can also type dataLayer in the console. It should print an array that includes your config call and any events you have pushed.
Use DebugView for events
The Network tab shows raw requests. DebugView in GA4 shows the same events as they arrive, grouped by device and with their parameters. You find it in Admin, under Data display.
To send events to DebugView, set debug mode on the page you are testing. With gtag.js, add the debug_mode parameter:
gtag('config', 'G-XXXXXXXXXX', { debug_mode: true });You can instead install the Google Analytics Debugger browser extension, which turns debug mode on without a code change. Remove debug_mode from production code when you finish, so test traffic does not mix with real data.
In DebugView, walk through the journey a social visitor would take:
- Open your tagged URL in a private window.
- Confirm
session_startandpage_viewappear. - Perform the action, for example submit the sign-up form.
- Confirm the event, such as
sign_up, appears withmethod: email. - Select the event and read its parameters. Check names for typos, since GA4 treats
Sign_Upandsign_upas different events.
If you use Google Tag Manager, use Preview mode. It opens a panel that shows which tags fired on each page and which did not. For a tag that did not fire, the panel lists each trigger condition and whether it passed. This is the quickest way to find a trigger that listens for the wrong event name or the wrong form_id.
Check attribution in Realtime
The Realtime report shows activity from the last 30 minutes. Open your tagged link in a private window and watch for your visit. You should see it under the traffic source you tagged. If the visit shows as (direct) / (none), the UTM parameters were lost or ignored somewhere between the link and the page.
Realtime confirms that data arrived and which source it carries. It does not confirm that standard reports will look right, because those go through processing.
Know the delays
Different reports update at different speeds, and this causes many false alarms.
- DebugView and Realtime: seconds to a few minutes.
- Standard reports: commonly 24 to 48 hours before data is complete.
- Key event counts: an event marked as a key event applies going forward. Past events are not recounted.
- Newly created custom definitions: a custom dimension can take a day before it appears in reports.
If an event appears in DebugView but not in a report the same afternoon, wait before you change anything. Changing working code because of a normal delay is a common way to introduce a real bug.
Debug the server-side and consent cases
Two setups need extra checks.
Measurement Protocol events. If you send conversions from your server, a request with a wrong secret or ID can still return a success status, because the endpoint accepts requests without validating the contents. To check the payload, send it to the validation endpoint instead, which returns messages describing problems:
curl -X POST "https://www.google-analytics.com/debug/mp/collect?measurement_id=G-XXXXXXXXXX&api_secret=YOUR_API_SECRET" \
-H "Content-Type: application/json" \
-d '{"client_id":"CLIENT_ID_FROM_BROWSER","events":[{"name":"generate_lead","params":{"value":25,"currency":"USD"}}]}'An empty validationMessages list means the payload is well formed. It does not mean the event is attributed correctly. The client_id must match the one the browser used, or the event will not join the visitor's session and will lose the social source.
Consent. Test the page three times: before choosing, after accepting, and after declining. On decline, confirm that analytics storage stays denied and no identifying cookies are set. Check the Application tab in developer tools for _ga cookies. If a decline still produces cookies, your banner and your consent defaults are not connected.
A debugging checklist by symptom
| Symptom | Likely cause | First check |
|---|---|---|
| Social visits show as direct | UTM lost in redirect, or app strips the referrer | Read the final URL after redirects |
| Same source split into several rows | Inconsistent capitalization or naming | Compare `utm_source` values |
| Event in DebugView, missing in reports | Normal processing delay | Wait 24 to 48 hours |
| Event fires twice | Snippet loaded twice, or both gtag and a tag manager send it | Count `collect` requests per action |
| No events at all | Blocked request or script error | Network and Console tabs |
| Conversions lack a source | Server event used a different `client_id` | Compare IDs in browser and server |
| Test traffic in real reports | Debug or team visits not excluded | Add an internal traffic filter |
Duplicate events deserve special attention. A very common cause is installing the snippet in the page template and also adding a GA4 tag in Tag Manager. Pick one installation method per property.
Keep your own test traffic out
Your team's visits count as real visits unless you exclude them. In GA4 Admin, define internal traffic by IP address, then activate the internal traffic data filter. Start the filter in Testing state, check that internal visits get labeled, and then activate it. Data excluded by an active filter cannot be recovered, so do not skip the testing state.
A second approach is to use a separate GA4 property for development and staging sites, with its own measurement ID. This keeps test data out of production reports entirely.
Build a test routine
Run the same short routine whenever you launch a campaign or change the site:
- Read each tagged URL for case, spacing, and missing parameters.
- Click it from a private window and confirm the landing page keeps the parameters.
- Confirm one
page_viewrequest in the Network tab. - Complete the conversion action and confirm one event in DebugView with correct parameters.
- Check Realtime for the expected source and medium.
- Two days later, confirm the key event count in a standard report by source and medium.
Exercise
You launch an Instagram ad and, an hour later, your sign-up key event shows zero in the standard report. DebugView showed the sign_up event when you tested. What do you check first, and why?
Show answer
Check whether this is only processing delay. Standard reports can take 24 to 48 hours, so an hour-old gap is expected. Meanwhile, confirm the event in Realtime and make sure the event is marked as a key event, since that setting applies only to events received after you mark it. If the event is still missing after two days, compare the event name in DebugView with the name marked as a key event, looking for case or spelling differences.
Exercise
Your reports show instagram, Instagram, and ig as separate sources for the same campaign. Which step of the testing routine would have caught this, and how do you prevent it?
Show answer
Step 1, reading each tagged URL, would have caught the inconsistent utm_source values. Prevent it by writing a naming convention that fixes lowercase values and one allowed name per platform, and by building links from a shared template or spreadsheet instead of typing them by hand.