Repository navigation
fix(ads): stop loading Ezoic and AdSense scripts for premium users - #254
Merged
Merged
Conversation
The root layout loaded the ad scripts for every visitor. AdWrapper hides the React placements for premium users, but Ezoic injects anchor, side rail, interstitial and video ads by itself, outside React. AdScripts is a server component. It reads the session and renders no script for a premium user. A session error keeps the ads on.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Paying users still see ads.
The cause
app/[locale]/layout.tsxput the AdSense and Ezoic scripts in<head>for every visitor.AdWrapperhides the React placements for premium users, and that part works. But Ezoic places anchor, side rail, interstitial and video ads by itself, outside React, soAdWrappernever sees them. Those formats were turned on in 15360f2 and 77f25a9.AdBlockerForPremiumonly targets AdSense auto ads, and it runs after the scripts have loaded.Ruled out: every ad component goes through
AdWrapper, no caller passesforceShow,customSessionreadsisPremiumfrom the database on eachget-session, and no active subscriber hasisPremium = false.The fix
AdScriptsis a server component. It callsserverAuth()and renders no script for a premium user. The layout renders<AdScripts />in place of the inline block. If the session lookup throws, the ads stay on, so a database error cannot take every page down.Sign-in goes through
callbackURL, which is a full page load, so the layout is rendered again after login. Pages were already rendered per request (cache-control: no-storein production), so this costs no static generation.Verified
tscandeslintexit 0, 31 tests pass. Onnext dev, an anonymous visitor still gets all the ad scripts in the HTML.The premium case is covered by
AdScripts.test.tsxwith a mocked session. The test fails when the premium check is removed. It was not exercised with a real premium session: after deploy, check with a premium account that the HTML has nosa.min.js.vitest.config.tsgains the@alias and*.test.tsx. This test needs both.Not done here
AdBlockerForPremiumandAdSenseAutoAdshave no job left. Left alone deliberately, worth their own change.