Issue with Adsense and pageviews

I’m sorry there hasn’t been more movement on this yet. We do have people looking into it, but I’m afraid I don’t have any updates to share. :frowning:

I appreciate it may not be moving fast enough for you, but we do care about all Discourse sites. :discourse: If I could wave and wand and make it all come good I would certainly do that.

I wish you the best of luck with your move though, and I’m sorry to see you go.

3 Likes

Thanks for your help @JammyDodger - The reason I said it feels like no one cares is due to the tumbleweed through this thread and previous iterations of this issue on here unfortunately. Not expecting a magic wand but after 2 months, there’s little to no sign that anyone is looking into it and I really need to be up and running before January.

Over the last few months, I have been in talks with two large ad agencies and when they saw/heard I was on Discourse they ended the talks, I tried the AdButler integration with self serve ad system, and while AdButler counted a load of impressions the self-serve ad system only registering a tiny fraction of the pageviews/ad requests.

I am currently running with an ad provider who claimed they had worked with Discourse before but when I spoke with their dev he said they hadn’t actually used Discourse, but they had success with SPAs previously. Currently, the ads are running and while they are getting decent impressions it’s still far short of what it should be, unfortunately.

Sorry to have to go after 7 years on Discourse but I have wasted day after day trying to get this to work and was making no progress.

2 Likes

Hi Shane,

We hear you and have this prioritized. It is a very tough one to work on cause we need full access to both our Discourse logs and Google logs.

@MarkDoerr has a relationship now and access to one of our customers that has this configured, we are investigating where it takes us. It could take weeks or even months to work out.

We will certainly update here as we come up with various findings. We want ads to work great on the Discourse platform, but need to know exactly what needs improving.

4 Likes

I’ve been waiting a long time to see this problem taken care of. I can’t wait for the work to be finished. I hope there will be some progress. I would be grateful if the problem is fixed. @sam

We are currently at… we tried on a local customer of ours and are not seeing a repro at all. Looking for another customer.

We did some debugging here and one issue that is glaring is that transitions from “topic” → “topic” are effectively broken in this plugin.

  1. Visit topic X
  2. From suggested, link, whatever … click a link to topic Y
  3. Ads do not change, it seems a new pageview is not logged in adsense.

Instead we should be refreshing ads when you go to a different topic and ensure this triggers a adsense pageview.

We will have a look at fixing this over the next few weeks.

5 Likes

I just merged this fix which means that transitions between similar pages (e.g. topic → topic, or topic-list → topic-list) will now correctly reload any ad units on the page. That should lead to a slight increase in impressions - the precise amount will depend on usage patterns.

I can’t find any information from Google about how they calculate the pageview metrics for Adsense.

Discourse is a Single Page Application (SPA) which means that navigations around the forum are not ‘real’ pageviews. Google Analytics and Discourse’s own metrics understand this, and track the fake pageviews.

It’s possible that Adsense only counts ‘real’ pageviews. If so, then that would explain the lower numbers when compared to GA/Discourse.

8 Likes

It is very hard to make progress here without help from Google.

@david did fix 2 bugs today, which can help a bit, but fundamentally the APIs we get from adsense are leaving our hands pretty tied up.

Implementation wise:

  1. We place these <ins elements in places where we want ads:
    {{#if showAd}}
    <div class="google-adsense-label"><h2>{{i18n
          "adplugin.advertisement_label"
        }}</h2></div>
    <div
      class="google-adsense-content"
      id={{if isResponsive "google-adsense__responsive"}}
      style={{adWrapperStyle}}
    >
      <ins
        class="adsbygoogle"
        style={{adInsStyle}}
        data-ad-client="ca-pub-{{publisher_id}}"
        data-ad-slot={{ad_code}}
        data-ad-format={{autoAdFormat}}
      >
      </ins>
    </div>
  {{/if}}
  1. We call: window.adsbygoogle.push({}) when we are ready for adsense to populate ads.

This is pretty much all the fidelity we have here.

What I have observed:

  1. Google tends to fill in the same ad over and over after a push call. It’s like you need a “sleep for 5 seconds call, so iframe loads up” prior to a next push call (and next <ins element) to get different ads.

  2. When scrolling through long topics … eventually ads break, when they break, it is no more ads from that point onwards until you reload the page, the error is not surfaced to us, when catching exceptions I see it here in the obfuscated code:

  1. I can see that under normal circumstances the URL of the page is being reported to Google:

This also updates as you are scrolling provided we did a replaceState:

What Google could help us with?

  1. Non minified adsense so we can help debug what this exception is and why adsense goes into 100% broken mode

  2. Possibly a .reset() API that we could call on route transitions. Javascript can not be unloaded and we have no way of resetting internal state in adsense.

  3. Better public guidelines for PWA usage and richer APIs

We have some contacts at Google, will see if we can send this through and if they can help.

Situation should be a bit better post David’s fixes, but I think we just hit a brick wall.

Live repro of this eventually breaking is at: https://forum.freecodecamp.org/t/welcome-to-freecodecamps-forum/92385 just keep scrolling downwards…

12 Likes

Hey Guys,

Glad to see some progress on this, although it sounds like Google is not going to play ball.

just to add to this now on my new site, it appears that Discourse drastically overestimates the PageViews on GA4 as well, it’s hard to tell exactly as midweek is the quieter time on my site and I’m basically at the end of the season for my niche, but even so i think my pageviews were inflated by 20-40% - compared to a more traditional setup (which basically works the same).

Of course, some of the discrepancies could be down to the move, etc, but just adding here as it might be a clue that helps someone figure something out hopefully.

2 Likes

Just for full disclosure, there is no aspect of estimation when discourse counts a page views, we count based on server side activity, GA counts based on what users decide to tell it

1 Like

To clarify, I didnt mean the difference between Discourse PageViews and GA4 page views.

I mean GA4 running on Discourse seems to overinflate the number of page views compared to GA4 running on a more traditional Forum setup with the same number of users.

I think GA4 on Discourse is seeing lots of phantom pageviews. Having just changed over, I think I’m now getting a much closer number to the levels discourse was counting as page views, but actually minus the crawler total, on my GA4 now.

I think this might be more Google trouble.

Switched on November the 7th

Page views have taken an immediate dive, but user_enguagement has gone up

But still roughly the same number of users

I know switching system etc could casue a wobble and the season is winding down so i expect the site to get a little less busy but seems a huge dive in PageViews, we had maintained the URL structure as much as possible to minimise distuption.

Actually looking back at my Google analytics from the year before, using Universal Analytics on Discourse they’re much more in keeping with my traffic since Tuesday, so I actually think there’s an issue with GA4 and the pageview data it is seeing on Discourse.

… and confusingly, Google AdSense is seeing only a fraction of them as well.

I feel this is kind of going in lots of directions Shane, so let me summarize some stuff:

  1. Pageview numbers from adsense should be ignored. According to Google, adsense does not play nicely with SPAs, it only counts 1 page view per visit.
  2. We have a reproducible bug with adsense, where it just 100% stops working after a certain amount of scrolling, we are working with Google to try to find a workaround.
  3. We attempt to align pageviews in GA4 with page views in Discourse. You get a page view when
    1. You first visit the site
    2. Within the SPA you change routes … meaning you go from one topic to another topic.
    3. Ad blockers etc… will undo all our alignment work, given GA4 is managed via the browser calling google and our counting is done server side.

Traditional non SPA forums, will count multiple page views per topic, one for each page… we only count 1 per topic, no matter how much scrolling you do. Maybe we should re-think this… I am not sure…

5 Likes

Is there a mechanism that will emulate “next page” for the purposes of pageviews when the n+15 topic displays on screen and when n+10 post displays?

Nothing out of the box, but I think there is a possibility to do so in a theme component. You would unalign Discourse page views to a degree if you did so.

1 Like

A post was split to a new topic: GA4 page views are inflated compared to Discourse page views

Hello, for me, the problem is not completely over, it still continues. Especially from 2024, adsense is coming to a completely different ad earning system. Adsense will now pay for impressions. In this case, it will negatively affect the sites using discourse. I will be glad if you can look at this situation in the coming days

The word from Google is:

  1. Adsense does not work 100% right on SPAs, it is simply not designed for it
  2. There is not alternative from Google
  3. Page views are not to be trusted on SPA with adsense

Sorry I don’t have better news, but there is simply nothing we can do here.

5 Likes

Or with Google Analytics judging from my experience.

I disagree with this, our implementation is google analytics friendly.

clearly … google analytics does not count a giant pile of page view

  • Crawlers / API calls count for nothing unless they run JS
  • Our implementation is very conservative, we only ever count 1 page view per topic regardless of how long it is
  • Browsers such as brave may block this traffic, various plugin browsers can as well

Caveats aside, this does work as advertised


If you really really need exact counts, the NGINX logs is what will give you much more accurate number.