---
title: "Google AdSense · Nuxt Scripts"
description: "Show Google AdSense ads in your Nuxt app."
canonical_url: "https://scripts.nuxt.com/scripts/google-adsense"
meta:
  "og:description": "Show Google AdSense ads in your Nuxt app."
  "og:image": "https://scripts.nuxt.com/_og/s/o_21eb0065466ac07e.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Google AdSense · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/s/o_21eb0065466ac07e.png"
---

> Index of every page on this site: [llms.txt](https://scripts.nuxt.com/llms.txt)

**Scripts**

# **Google AdSense**

[Copy for LLMs](https://scripts.nuxt.com/scripts/google-adsense.md)

[**Google AdSense**](https://www.google.com/adsense/start/) serves Google ads on your site.

Choose the API that matches the placement:

- [`**useScriptGoogleAdsense()**`](https://scripts.nuxt.com/scripts/google-adsense) loads the `**adsbygoogle**` queue.
- `**<ScriptGoogleAdsense>**` renders an ad unit.

**Google Adsense**

[**View source **](https://github.com/nuxt/scripts/blob/main/packages/script/src/runtime/registry/google-adsense.ts)

## Nuxt Config Setup

Add this to your `**nuxt.config.ts**` to load Google Adsense globally. Alternatively you can use the **useScriptGoogleAdsense** composable for more control.

```
export default defineNuxtConfig({
  scripts: {
    registry: {
      googleAdsense: {
        client: 'ca-pub-1234567890123456',
        trigger: 'onNuxtReady',
      }
    }
  }
})
```

This config automatically enables **first-party mode ** (bundle + proxy). See below to customise.

## useScriptGoogleAdsense()

The `**useScriptGoogleAdsense**` composable lets you have fine-grain control over when and how Google Adsense is loaded on your site.

```
const { proxy } = useScriptGoogleAdsense()

// ad slots render automatically
```

Please follow the [**Registry Scripts **](https://scripts.nuxt.com/docs/guides/registry-scripts) guide to learn more about advanced usage.

## First-Party Mode: Privacy Focused Proxy

No extra config needed. The script is bundled from your domain (faster loads, no extra DNS lookup) and runtime requests are reverse-proxied through your server with automatic anonymisation (user IPs stay hidden from Google Adsense, works with ad blockers). [**Learn more. **](https://scripts.nuxt.com/docs/guides/first-party)

**Mode**

Bundle Proxy

**Privacy**

IP, language, and hardware fingerprints are anonymised. Screen dimensions pass through so heatmaps render accurately.

```
export default defineNuxtConfig({
  scripts: {
    // ✅ First-party mode: bundled + proxied
    registry: {
      googleAdsense: {
        client: 'ca-pub-1234567890123456',
        trigger: 'onNuxtReady',
      },
    },
  },
})
```

## Example

Using Google Adsense in a component with the proxy to send events .

ConversionButton.vue

```
<script setup lang="ts">
const { proxy } = useScriptGoogleAdsense()

// noop in development, ssr
// just works in production, client
function handleAction() {
  // ad slots render automatically
}
</script>

<template>
  <div>
    <button @click="handleAction">
      Send Event
    </button>
  </div>
</template>
```

## Where to find `**<your-id>**` (publisher ID)

Find your [**Google AdSense publisher ID**](https://support.google.com/adsense/answer/2923881?hl=en) under **Account > Settings > Account information**. It appears as `**pub-…**` in your account and as `**ca-pub-…**` in ad code. Replace `**<your-id>**` below with that value.

[Open related resource on adsense.google.com](https://adsense.google.com/start/)Manage ad types and placements from the **Auto ads** settings in your AdSense dashboard.

## Site ownership verification

### Automatic meta tag insertion

If you provide a `**client**`, Nuxt automatically inserts a **meta tag** on the page for Google to verify your site ownership.

nuxt.config.ts

```ts
export default defineNuxtConfig({
  scripts: {
    registry: {
      googleAdsense: {
        client: 'ca-pub-<your-id>', // AdSense Publisher ID
      },
    },
  },
})
```

### Adding `**ads.txt**`

Google recommends adding an `**ads.txt**` file to identify the advertising systems authorized to sell your inventory and reduce counterfeit inventory.

#### **Steps**

1. Create a new file: `**public/ads.txt**`
2. Add the following content:

   ```plaintext
   google.com, pub-<your-id>, DIRECT, f08c47fec0942fa0
   ```

3. Replace `**<your-id>**` with your **AdSense Publisher ID**.

[Open related resource on support.google.com](https://support.google.com/adsense/answer/12171612)An `**ads.txt**` file does not replace AdSense's site review. After publishing it, check the file's status in your AdSense dashboard.

## Enabling Auto ads

[**Auto ads**](https://support.google.com/adsense/answer/9261805?hl=en) let Google choose placements based on the page's layout, content, and existing ads. You can still control formats and exclude pages or areas in AdSense.

nuxt.config.ts

```ts
export default defineNuxtConfig({
  scripts: {
    registry: {
      googleAdsense: {
        client: 'ca-pub-<your-id>', // AdSense Publisher ID
        autoAds: true, // Enable Auto Ads
      },
    },
  },
})
```

## Using the [`**<ScriptGoogleAdsense>**`](https://scripts.nuxt.com/scripts/google-adsense) component

`**<ScriptGoogleAdsense>**` renders one ad unit:

```vue
<template>
  <ScriptGoogleAdsense
    data-ad-client="ca-pub-<your-id>"
    data-ad-slot="1234567890"
    data-ad-format="auto"
  />
</template>
```

### Component Props

| **Prop** | **Description** |
| --- | --- |
| `**data-ad-client**` | Your **Google AdSense publisher ID** (`**ca-pub-XXXXXXXXXX**`). |
| `**data-ad-slot**` | Your **Ad Slot ID** (available in AdSense dashboard). |
| `**data-ad-format**` | Ad format type (`**auto**`, `**rectangle**`, `**horizontal**`, `**vertical**`, `**fluid**`, `**autorelaxed**`). |
| `**data-ad-layout**` | Layout: `**in-article**`, or `**image-top**`, `**image-side**`, `**text-only**` for in-feed. |
| `**data-ad-layout-key**` | Layout key generated by AdSense for an in-feed unit. |
| `**data-full-width-responsive**` | **Set to `**true**`** to make the ad responsive. |

#### **Example using **`**data-ad-layout**`

Set `**data-ad-layout**` for an in-article unit:

```vue
<template>
  <ScriptGoogleAdsense
    data-ad-client="ca-pub-<your-id>"
    data-ad-slot="1234567890"
    data-ad-format="fluid"
    data-ad-layout="in-article"
  />
</template>
```

#### **Example using **`**data-ad-layout-key**`

Copy the layout key from the in-feed unit generated by AdSense:

```vue
<template>
  <ScriptGoogleAdsense
    data-ad-client="ca-pub-<your-id>"
    data-ad-slot="1234567890"
    data-ad-format="fluid"
    data-ad-layout-key="-6t+ed+2i-1n-4w"
  />
</template>
```

## Handling ad blockers

Use the `**error**` slot for visitors whose ad blocker stops the script:

```vue
<template>
  <ScriptGoogleAdsense data-ad-client="ca-pub-..." data-ad-slot="...">
    <template #error>
      <!-- Fallback content -->
      <p>Please support us by disabling your ad blocker.</p>
    </template>
  </ScriptGoogleAdsense>
</template>
```

## Using the [`**useScriptGoogleAdsense()**`](https://scripts.nuxt.com/scripts/google-adsense) composable

Use [`**useScriptGoogleAdsense()**`](https://scripts.nuxt.com/scripts/google-adsense) when you need the `**adsbygoogle**` queue without an ad-unit component.

```ts
export function useScriptGoogleAdsense<T extends GoogleAdsenseApi>(
  _options?: GoogleAdsenseInput
) {}
```

See the [**Registry Scripts guide**](https://scripts.nuxt.com/docs/guides/registry-scripts) for trigger and loading options.

[Open related resource on support.google.com](https://support.google.com/adsense)See the official **Google AdSense guide**.

`**client**``string`

The Google Adsense ID.

`**autoAds**``boolean` = false

Enable or disable Auto Ads.

[Edit this page](https://github.com/nuxt/scripts/edit/main/docs/content/google-adsense.md)

[Markdown For LLMs](https://scripts.nuxt.com/scripts/google-adsense.md)

[**Fathom Analytics** Load Fathom Analytics and track page views, goals, and custom events.](https://scripts.nuxt.com/scripts/fathom-analytics) [**Google Analytics** Send Google Analytics page views and events with typed consent controls.](https://scripts.nuxt.com/scripts/google-analytics)

**On this page **

- [Where to find \<your-id> (publisher ID)](#where-to-find-your-id-publisher-id)
- [Site ownership verification](#site-ownership-verification)
- [Enabling Auto ads](#enabling-auto-ads)
- [Using the \<ScriptGoogleAdsense> component](#using-the-scriptgoogleadsense-component)
- [Handling ad blockers](#handling-ad-blockers)
- [Using the useScriptGoogleAdsense() composable](#using-the-usescriptgoogleadsense-composable)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://scripts.nuxt.com/#website","@type":"WebSite","description":"Nuxt Scripts lets you load third-party scripts with better performance, privacy, security and DX. It includes many popular third-parties out of the box.","name":"Nuxt Scripts","url":"https://scripts.nuxt.com/","publisher":{"@id":"https://scripts.nuxt.com/#identity"}},{"@id":"https://scripts.nuxt.com/scripts/google-adsense#webpage","@type":"WebPage","description":"Show Google AdSense ads in your Nuxt app.","name":"Google AdSense","url":"https://scripts.nuxt.com/scripts/google-adsense","breadcrumb":{"@id":"https://scripts.nuxt.com/scripts/google-adsense#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/scripts/google-adsense"]}],"primaryImageOfPage":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/#identity","@type":"Organization","name":"Nuxt Scripts","url":"https://scripts.nuxt.com","logo":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/scripts/google-adsense#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Nuxt Scripts","item":"https://scripts.nuxt.com/","position":1},{"@type":"ListItem","name":"Scripts","item":"https://scripts.nuxt.com/scripts","position":2},{"@type":"ListItem","name":"Google AdSense","item":"https://scripts.nuxt.com/scripts/google-adsense","position":3}]},{"@id":"https://scripts.nuxt.com/#logo","@type":"ImageObject","caption":"Nuxt Scripts","contentUrl":"https://scripts.nuxt.com/logo.svg","inLanguage":"en","url":"https://scripts.nuxt.com/logo.svg"}]}
```

## Sitemap

See the full [sitemap](https://scripts.nuxt.com/sitemap.md) for all pages.
