# Issue with Adsense and pageviews

**URL:** https://meta.discourse.org/t/issue-with-adsense-and-pageviews/276901
**Category:** Bug
**Tags:** advertising, fixed
**Created:** [August 28, 2023, 10:41am UTC](https://meta.discourse.org/t/issue-with-adsense-and-pageviews/276901 "2023-08-28T10:41:39Z")
**Posts on this page:** 13
**Page:** 3

<div class="post-metadata">

### Author: ![mentalstring](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mentalstring/32/168934_2.png) [@mentalstring](https://meta.discourse.org/u/mentalstring)
#### Post date: [January 23, 2024, 8:19pm UTC](https://meta.discourse.org/t/issue-with-adsense-and-pageviews/276901/66 "2024-01-23T20:19:13Z")

</div>

I came here with an issue related precisely about ads and pageviews, but from a different angle and I wonder if I might have just stumbled on the actual cause for this.

Some context: I’m using Google’s Ad Manager to show a mix of our own directly sold ads with AdSense as fallback. I’m using the official Ad Plugin.

We rarely have directly sold ads in our forum, but we currently have one. Over the last days I noticed something very odd with the ads the forum: Ad Manager was reporting the banners were having clicks, but reporting to have nearly zero impressions, causing Ad Manager to report a CTR in the thousands percent because it was seeing more clicks than actual impressions. 😅

While using Ad Manager feature to preview one of the banners directly on Discourse I noticed that these errors were being displayed on the console:

 ![Screenshot 2024-01-23 at 14.46.03](https://global.discourse-cdn.com/meta/original/4X/4/1/5/415e86f7ce7408892d89b6283355e600f0b9d417.png)

Expanding on one the errors, they seem related to the advertising.

 ![Screenshot 2024-01-23 at 14.48.06](https://global.discourse-cdn.com/meta/original/4X/f/1/a/f1aef3a3ad53f954b014b709fc2dccca73c24633.png)

Note that, as recommended by the Ad Plugin, we are using ‘https’ and ‘unsafe-inline’ for the CSP. I don’t know if the policy of ignoring ‘unsafe-inline’ is new, or if the hash was introduced recently by Discourse.

In any case, if I temporarily disable CSP, as expected, the errors go away and, importantly, Ad Manager started to properly report impressions.

So, it seems that in practice the ads (mostly) work, but the Google Ad Manager internal tracking to report back to thepage seems to be failing (when CSP is not disabled).

Could this issue with CSP’s ‘unsafe-line’ be the cause of the unreported ad pageviews reported on this topic?

---

<div class="post-metadata">

### Author: ![Firepup650](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firepup650/32/465200_2.png) [@Firepup650](https://meta.discourse.org/u/Firepup650)
#### Post date: [January 23, 2024, 8:30pm UTC](https://meta.discourse.org/t/issue-with-adsense-and-pageviews/276901/67 "2024-01-23T20:30:47Z")

</div>

It seems like it’s ignoring the unsafe-inline, because of a hash in your CSP policy:

> [@mentalstring](#):
>
> ![Screenshot 2024-01-23 at 14.46.03](https://global.discourse-cdn.com/meta/original/4X/4/1/5/415e86f7ce7408892d89b6283355e600f0b9d417.png)

Can you remove that hash somehow and see if it goes away?

---

<div class="post-metadata">

### Author: ![mentalstring](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mentalstring/32/168934_2.png) [@mentalstring](https://meta.discourse.org/u/mentalstring)
#### Post date: [January 23, 2024, 8:37pm UTC](https://meta.discourse.org/t/issue-with-adsense-and-pageviews/276901/68 "2024-01-23T20:37:34Z")

</div>

I’m not adding the hash myself as my CSP configuration is the default plus the [recommended](https://meta.discourse.org/t/discourse-advertising/33734#fixing-content-security-policy-issues-19) changes to run the Ad Plugin.

 ![Screenshot 2024-01-23 at 20.33.42](https://global.discourse-cdn.com/meta/original/4X/c/6/7/c677e2b4b070bf7eb895380253c7990369f60693.png)

I don’t know what’s adding that hash, but I suspect Discourse does as the CSP in meta also has one in it.

---

<div class="post-metadata">

### Author: ![Shaneod](https://avatars.discourse-cdn.com/v4/letter/s/85e7bf/32.png) [@Shaneod](https://meta.discourse.org/u/Shaneod)
#### Post date: [January 23, 2024, 8:42pm UTC](https://meta.discourse.org/t/issue-with-adsense-and-pageviews/276901/69 "2024-01-23T20:42:01Z")

</div>

> [@sam](#):
>
> > [@Shaneod](#):
> >
> > 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.

Well okay but when i moved to GA4 on Discourse my pageviews rocketed to 3 x times what they were on UA and after moving to a different platform they’re back to 30% of what I was getting on Discourse with GA4 and much more in line with my Discourse traffic on UA. No one seems to be able to explain why, so there’s potentially something miss there. 🤷‍♂️

---

<div class="post-metadata">

### Author: ![mentalstring](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mentalstring/32/168934_2.png) [@mentalstring](https://meta.discourse.org/u/mentalstring)
#### Post date: [January 24, 2024, 9:28am UTC](https://meta.discourse.org/t/issue-with-adsense-and-pageviews/276901/70 "2024-01-24T09:28:44Z")

</div>

> [@mentalstring](#):
>
> I don’t know what’s adding that hash, but I suspect Discourse does as the CSP in meta also has one in it.

Not sure if relevant here, but the hash is being added right after https://_discourse-host_/svg-sprite.

Apologies if this CSP issue is out of context here, although to me it seems related — feel free to move my posts to the Ad Plugin topic if this is off-topic here.

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [January 25, 2024, 7:07am UTC](https://meta.discourse.org/t/issue-with-adsense-and-pageviews/276901/71 "2024-01-25T07:07:23Z")

</div>

> [@mentalstring](#):
>
> Could this issue with CSP’s ‘unsafe-line’ be the cause of the unreported ad pageviews reported on this topic?

This is an interesting theory. I did a bit of digging to track down where the hash that cancels `unsafe-inline` is coming from and it looks like it is being added by the splash screen site setting. Can you try to disable that setting on your instance temporarily and see if there are any changes in the Ad Manager reports?

---

<div class="post-metadata">

### Author: ![mentalstring](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mentalstring/32/168934_2.png) [@mentalstring](https://meta.discourse.org/u/mentalstring)
#### Post date: [January 25, 2024, 3:40pm UTC](https://meta.discourse.org/t/issue-with-adsense-and-pageviews/276901/72 "2024-01-25T15:40:06Z")

</div>

Can already confirm that disabling the splash screen did remove the hash and no longer have errors on the console regarding the ads.

Tomorrow I’ll report if impressions are being counted normally on Ad Manager side of things.

---

<div class="post-metadata">

### Author: ![mentalstring](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mentalstring/32/168934_2.png) [@mentalstring](https://meta.discourse.org/u/mentalstring)
#### Post date: [January 26, 2024, 10:50am UTC](https://meta.discourse.org/t/issue-with-adsense-and-pageviews/276901/73 "2024-01-26T10:50:59Z")

</div>

I can now confirm that after disabling the splash screen (and re-enabling CSP), Ad Manager is now acting normal, with impressions being reported back for the ad campaign we have been running (previously showing ~0 impressions, although dozens of clicks).

So, at least for our case, we seem to have found a culprit and a hack of it. I don’t think this affects just us though as we have a pretty standard use of the Ad Plugin with Ad Manager, and the splash screen is enabled by default. I’m not sure if the instructions of the Ad Plugin need a tweak, or if the use of hashes on CSP can be addressed. Either way, I think it needs attention as it currently breaks running Ad Manager campaigns in Discourse when using the Ad Plugin.

Happy to provide more info or test something if it’s helpful as I know it can be tricky to debug these things without already having a Ad Manager account and running an actual campaign.

Having said that, given that I posted about this on this particular topic, I should also note that the number of impressions reported by AdSense (which is our fallback for our own campaigns and takes the majority of the traffic) has not changed substantially after these workarounds (e.g. disabling CSP or the splash screen). So it seems to affect only Ad Manager with directly sold campaigns, and not necessarily if its AdSense showing an ad — perhaps AdSense uses a different way to report the impression back to Google, if it does it at all. Hence, this CSP issue may not necessarily explain the big discrepancy reported on this topic — at least I can’t see it with our particular setup, although the same CSP issue may be breaking other google code when the Ad Plugin is used.

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [February 15, 2024, 9:41pm UTC](https://meta.discourse.org/t/issue-with-adsense-and-pageviews/276901/75 "2024-02-15T21:41:51Z")

</div>

A quick follow-up here, @mentalstring. @david has a PR in the works with a completely differect approach here, that is looking very promising:

[https://github.com/discourse/discourse/pull/25664](https://github.com/discourse/discourse/pull/25664)

We should be able to merge this in core shortly and test it out very soon. It promises to solve all sorts of CSP issues with ad management software (and script management tools like GTM). It might not affect AdSense impressions though, that seems to be a different issue.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [February 16, 2024, 1:34pm UTC](https://meta.discourse.org/t/issue-with-adsense-and-pageviews/276901/76 "2024-02-16T13:34:34Z")

</div>

Hi @mentalstring - here are some details on that new approach:

> [@(Superseded) Experimenting with a 'strict-dynamic' Content Security Policy (CSP)](https://meta.discourse.org/t/experimenting-with-a-strict-dynamic-content-security-policy-csp/295603):
>
> We’re experimenting with a new ‘strict-dynamic’ CSP, which should make it much easier to integrate themes, plugins and external scripts with Discourse in a secure way. You can try out the new mode by enabling the ‘content security policy strict dynamic’ site setting. Please let us know if you have any feedback! We hope to make this the default in the near future, and will make an #Announcements topic as we get closer to that goal. For more information, see below: scroll Background [Back in …](https://meta.discourse.org/t/mitigate-xss-attacks-with-content-security-policy/104243)

With that, you should be able to re-enable the splash screen, and all kinds of advertising / tag-management should ‘just work’ without any additional configuration. Please let us know how you get on!

---

<div class="post-metadata">

### Author: ![mentalstring](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mentalstring/32/168934_2.png) [@mentalstring](https://meta.discourse.org/u/mentalstring)
#### Post date: [February 18, 2024, 11:12am UTC](https://meta.discourse.org/t/issue-with-adsense-and-pageviews/276901/77 "2024-02-18T11:12:03Z")

</div>

This looks like a good approach, very likely to fix the issue with GAM, while perhaps even simplifying the CSP setup. 👍

It will be a little while until I can test this myself as we are still on 3.1.5, although we plan to update soon. Will report again here once I have a confirmation.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 18, 2024, 5:30am UTC](https://meta.discourse.org/t/issue-with-adsense-and-pageviews/276901/79 "2024-06-18T05:30:19Z")

</div>

I think we have the OP fixed now.

We added new counting to the product using the report:

`/admin/reports/consolidated_page_views_browser_detection`

Once your remove Crawler and Other Pageviews. we are seeing parity with other analytics tools.

Over the next few months we will be amending a lot of Discourse internal reporting to prioritize “browser page view” over the old “page view”

“browser page view” means a real browser booted the app.

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [July 2, 2024, 5:31am UTC](https://meta.discourse.org/t/issue-with-adsense-and-pageviews/276901/80 "2024-07-02T05:31:17Z")

</div>

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

[Previous page](https://meta.discourse.org/t/issue-with-adsense-and-pageviews/276901.md?page=2)
