Google AdSense
Integrate Google AdSense through your site’s Astro layouts and static files. This path uses site code; it does not require an EmDash plugin. You need access to the site’s source and deployment, plus the verification code and publisher ID from your AdSense account.
Google controls site approval, ad delivery, and consent requirements. Follow Google’s site connection instructions for your account. The examples below show where that code belongs in EmDash, not a guarantee of AdSense approval.
Add verification and ad code
Section titled “Add verification and ad code”-
Open the shared layout used by the public pages you want to monetize. In the blog template, this is
src/layouts/Base.astro. Keep its existing<EmDashHead>and other head content. -
Paste the AdSense code into the layout’s
<head>. The following loader example uses a placeholder publisher ID; replace the entireca-pub-0000000000000000value with your own.src/layouts/Base.astro (inside <head>) <scriptis:inlineasyncsrc="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-0000000000000000"crossorigin="anonymous"></script>Astro’s
is:inlinekeeps the script as written rather than bundling it. Load it once per page, even when several ad units share the page. See Astro’s script handling documentation.If you choose AdSense’s meta-tag verification method, put the exact tag supplied by Google in the same
<head>. The following example shows the AdSense account tag with a placeholder ID.src/layouts/Base.astro (inside <head>) <meta name="google-adsense-account" content="ca-pub-0000000000000000" />The Google Verification field in EmDash’s Settings > SEO emits
google-site-verification, notgoogle-adsense-account. Do not put the AdSense publisher ID in that field. -
For Auto ads, configure placements in AdSense. For manual ad units, paste Google’s ad-unit markup and initialization script into an Astro component or page where the ad should appear. Add
is:inlineto any initialization<script>so Astro preserves it. Keep the shared loader in the layout, rather than repeating it for each unit.
Keep executable ad code in trusted site source, rather than post content. Apply any consent requirements before enabling ad scripts; this example does not implement a consent manager. If the site sets a Content Security Policy, configure it for the resources required by Google’s current instructions.
Serve ads.txt at the root
Section titled “Serve ads.txt at the root”Create public/ads.txt in your Astro site project, alongside the site’s src/ directory. Astro copies public files unchanged so the file is served at /ads.txt.
Copy the line supplied by AdSense into the file as plain text. The following example uses a placeholder publisher ID; use Google’s exact line for your account.
google.com, pub-0000000000000000, DIRECT, f08c47fec0942fa0If ads.txt already exists, add the AdSense line while preserving entries for other ad providers. Follow Google’s ads.txt guidance for the required domain and file contents. Store this file in the site project, not the EmDash media library.
Deploy and check
Section titled “Deploy and check”Deploy the site after changing its layout or public/ files. On the public domain registered with AdSense, check that:
- The page source contains the chosen verification tag or script in
<head>, with your publisher ID, and only one shared AdSense loader. https://your-domain.example/ads.txtreturns the expected plain text rather than a 404 or HTML page.- The browser’s network and console panels show no script errors or blocked requests from the site’s security policy. Ad blockers can prevent local checks from loading ads.
Return to AdSense to request verification and review. Successful script loading or a reachable ads.txt file does not itself mean the site is approved or ads will display.
Reuse the integration in a plugin
Section titled “Reuse the integration in a plugin”For an integration shared across sites, a trusted native plugin can contribute scripts through page:fragments. The host layout must render the corresponding EmDash insertion components. Sandboxed plugins cannot inject scripts or raw HTML. A static public/ads.txt file remains a site-level deployment concern.