3

I have a user set up as follows with Google tag, gtag.js:

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

This appears first in the <head> element as it should. However, weeks on, no data is showing up. I have checked and double checked the code. When I go into the admin for this property I see this message:

Data collection isn't active for your website. If you installed tags more than 48 hours ago, make sure they are set up correctly.

Yet, when I test the site in admin (using the option to set up the property manually) using the 'Test your website' option, I get a green tick. I see that in similar questions asked here there can be issues of mismatches between Universal Analytics, GA4 (and even earlier systems) and gtag.js. Both Universal Analytics and GA4 had their own ways of handling user_ids, and I am indeed still using GA4 in older websites, with no problems.

Help, anyone!

4
  • If this is a vote to close the question, presumably on the grounds that it duplicates other questions: I have done a thorough review of related questions/answers and none addresses the specific issue here.
    – peter
    Commented Mar 31 at 12:34
  • I've close-voted as need more details, however I'm not even sure if your question is actually on-topic here on StackOverflow. Did you check the console if any errors are present?
    – DarkBee
    Commented Mar 31 at 12:39
  • Yes I did. No console errors at all. I'm not sure what further details are relevant. The code is installed into each html page dynamically according to the user_id, but I can't see how this affects things. I'm adding a few words about GA4 etc.
    – peter
    Commented Mar 31 at 12:43
  • This question indeed lacks details. It lacks a lot of debugging. Did you check your network tab? Do you see properly formed collect requests to Google endpoint using the correct measurement id? Do you get a proper server response? I also really don't like how you hardcode the user_id to a static string, but that should only result in there being 1 user in GA. Maybe that's exactly what GA doesn't like.
    – BNazaruk
    Commented Apr 5 at 18:57

2 Answers 2

1

If you're a visitor in the EU. The new cookie policy (consent mode) can maybe be the issue here.

Try to specify 'consent' mode:

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

    // Consent defaults BEFORE loading GA
    gtag('consent', 'default', {
        'ad_storage': 'denied',
        'analytics_storage': 'denied'
    });

    // Load GA
    gtag('js', new Date());

    // Setup config with user_id
    gtag('config', 'G-LXXXXXXX', {
        'user_id': 'DRCUSASK'
    });
</script>

And then later when the cookies are accepted (or to test) add this later on in your code:

<!-- Later, when user consents -->
<script>
  // Triggered after cookie consent is accepted
  gtag('consent', 'update', {
    'ad_storage': 'granted',
    'analytics_storage': 'granted'
  });
</script>

You can also try to create an event, to check if the event is triggered after the consent mode is granted:

<script>
  gtag('event', 'send_user_id', {
    user_id: 'DRCUSASK'
  });
</script>

You should now see the event "send_user_id" being fired with the key "user_id" and the value "DRCUSASK".

0

Problem:

Your GA4 gtag.js snippet appears correctly implemented, includes a user_id, and passes the real-time configuration test in the GA4 Admin interface (Test your website shows a green tick). However, no data is appearing in your GA4 reports weeks later, and you see the "Data collection isn't active" warning.

Likely Causes & How to Troubleshoot:

The successful admin test usually just verifies that the tag syntax is detectable on the URL provided. It doesn't always guarantee that data is being successfully transmitted and processed from your live site during normal user visits. The most common reasons for this discrepancy are:

Hits Not Sent from Live Site:

  • Action: Open your live website. Use your browser's Developer Tools (F12). Go to the Network tab. Refresh the page.

  • Verify: Filter the requests for collect?v=2&tid=G-Lxxxxxxx (replace G-Lxxxxxxx with your Measurement ID). Do you see requests with a 200 or 204 status code being sent to Google Analytics when pages load? If no requests are appearing here, the tag isn't firing correctly on the live site, potentially due to:

  • Incorrect Deployment: The code isn't actually live in the on all pages, or there's a typo only on the live version. Double-check the live source code.

  • JavaScript Errors: Check the Console tab in Developer Tools for unrelated JS errors that might be halting script execution before the gtag runs.

Hits Blocked:

  • Action: Test your live site using an Incognito/Private browsing window with browser extensions (especially ad/tracking blockers) disabled.

  • Verify: If requests now appear in the Network tab (or data appears in DebugView - see next point), the issue is likely client-side blocking by browser extensions or privacy settings for many of your users.

  • Check Content Security Policy (CSP): Look in the Console tab for errors related to CSP blocking *.googletagmanager.com or *.google-analytics.com. If you have a CSP header, ensure these domains are allowed in script-src and connect-src.

Hits Not Received/Processed by GA:

  • Action: Use GA4's DebugView.

Install the "Google Analytics Debugger" Chrome extension and turn it ON.

In your GA4 Property, go to Admin > Data display > DebugView.

Visit your live website in Chrome (with the extension ON).

  • Verify: Do you see events (page_view, first_visit, etc.) appearing in the DebugView interface within a few seconds?

If YES: Data is reaching Google. The problem might be significant reporting delays (unlikely after weeks), or Data Filters (Admin > Data Settings > Data Filters) accidentally excluding all your traffic (check if 'Developer Traffic' filters are misconfigured or too broad).

If NO: Combined with seeing no hits in the Network tab, this strongly points to the tag not firing or hits being blocked client-side (Points 1 & 2).

In summary: Focus first on the Network tab on your live site and GA4 DebugView. These will quickly tell you if the browser is sending data and if GA is receiving it, narrowing down whether the issue is tag implementation/firing, client-side blocking, or GA filtering. The passing admin test can be misleading in these scenarios.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.