Google Analytics 4 code not working

Hello. I created a Google Analytics 4 account today for my website.

After creating the account it gives you a code snippet to add to every page on your website.

Right now I just have a splash page while I am coding everything else.

Oh, I have my own VPS with access to cPanel.

Here is a modified version f what I have…

<!DOCTYPE HTML>
<html lang="en">
  
<head>
  <!-- GOOGLE ANALYTICS 4 -->
  <!-- Global site tag (gtag.js) - Google Analytics -->
  <script async src="https://www.googletagmanager.com/gtag/js?id=G-9999"></script>
  <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', 'G-9999');
  </script>

  <!-- METADATA -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">

  <!-- TITLE -->
  <title>My Site</title>

  <!-- CSS STYLES -->  
  <link type="text/css" rel="stylesheet" href="css/main.css" />
</head>

<body>
</body>

1.) Does my HTML header code look okay?

2.) Any idea why this isn’t working?

It says that it can take 10-15 minutes for Analytics to start working, but I added this code over an hour ago.

And I checked obvious things like making sure my updated index.html file was in production on my server and not just local.

The Realtime report should show whenever I access my website after like 15 seconds but it stills shows “0” visitors. :frowning:

1 Like

Did you set and check the Google site verification/validation?

@John_Betong,

What do you mean by that?

Google suggests checking the “Realtime Analytics” and I did that and don’t see any visitors which is why I am here.

Not sure f you are referring to some other validator?

I’m not on my desktop at the moment and cannot check…

Google has three options to validate that you are the site owner. I always select to download their html file, upload to the root of the server then request Google to validate their html file exists with the relevant data.

Edit:

I think the html file must remain and cannot be deleted.

@John_Betong,

Many years ago I set up Google Analytics on a website, but it sounds like Google has changed how things are done recently.

Yes, I recall doing that years ago, but I didn’t see anything mentioned about that when I followed their setup wizard. (To be honest, I have always found Google’s “help” to be very unhelpful… It always seems like they take simple questions and make them uch harder to resolve.)

So you think that is the issue?

How does the HTML that I posted look?

Since I copied and pasted it, the only thing I could have screwed up is not putting it in the right place, and since Google insists that their code goes first in the < head > tag, I asume that I did that correctly.

Did Google require the site ownership to be validated? Was validation successful?

What do you think would happen if I uploaded your file to one of my sites?

Here is what I recall…

Many years ago when you signed up for Google Analytics, you gave Google your domain name and they created a script for you that you pasted into a .js file and you placed that in your public_htm folder. (It as ether code or the final Javascript file.)

That file then pointed back to Google and that is how they knew who you were. (I believe this is what you are talking about.)

However, now it seems that Google has tweaked things, and after you enter your domain name, they again generate code, but this time you paste it in the header of ever file you want tracked.

Again, this shows web page and website ownership.

Well, right now I have a single index.php file and I have included their code as shown in my OP.

If you look closer, you’ll see they gave me an ID that I changed to 9999 for privacy reasons posting here.

So it boggles my mind what could be wrong?!

What do you think would happen if I uploaded your file to one of my sites?
[/quote]

This thread may be useful.

https://support.google.com/analytics/thread/14066291?hl=en

Best of luck with getting a Google reply because I’ve been waiting since May for Google to update their books quota :frowning:

Oh the pain…

That thread appears to be for UA which is the old version.

Why does Google makes things so difficult?!

I went into Chrome and turned on Google Tag Assistant and then surfed to my website.

It says…

Result of Tag Analysis:
1. Global site tag (gtag.js)
G-my-code-here

Then lower in the window I see…

Where to optimize
Add Google Analytics

WTF?

When I go into my Google Analytics account, I now see “1” user in the last 30 minutes but when I click on the various menu choices it seems like they all sa “No data”.

i know that this UI is much more complicated than what I dealt with years ago, where you went into GA and you had all of these tables and graphs showing you stats that made sense.

Anyone have experience with Google Analytics in 2020?

i am lost… :frowning:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.