---
title: "Google AdSense"
description: "Show Google AdSense ads in your Nuxt app."
canonical_url: "https://scripts.nuxt.com/scripts/google-adsense"
last_updated: "2026-08-10T04:32:14.008Z"
---

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

Choose the API that matches the placement:

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

<script-stats>



</script-stats>

<script-docs>



</script-docs>

## 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.

<callout icon="i-heroicons-light-bulb" target="_blank" to="https://adsense.google.com/start/">

Manage ad types and placements from the **Auto ads** settings in your AdSense dashboard.

</callout>

## 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.

<tabs>
<div icon="i-heroicons-code-bracket-square" label="Example">

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

</div>

<div icon="i-heroicons-magnifying-glass-circle" label="Output">

```html
<meta name="google-adsense-account" content="ca-pub-<your-id>" />
```

</div>
</tabs>

### 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**.

<callout icon="i-heroicons-light-bulb" target="_blank" to="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.

</callout>

## 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.

<tabs>
<div icon="i-heroicons-code-bracket-square" label="Example">

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

</div>

<div icon="i-heroicons-magnifying-glass-circle" label="Output">

```html
<script>
(adsbygoogle = window.adsbygoogle || []).push({
  google_ad_client: "ca-pub-<your-id>",
  enable_page_level_ads: true,
});
</script>
```

</div>
</tabs>

## Using the [`<ScriptGoogleAdsense>`](/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

<table>
<thead>
  <tr>
    <th>
      Prop
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        data-ad-client
      </code>
    </td>
    
    <td>
      Your <strong>
        Google AdSense publisher ID
      </strong>
      
       (<code>
        ca-pub-XXXXXXXXXX
      </code>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        data-ad-slot
      </code>
    </td>
    
    <td>
      Your <strong>
        Ad Slot ID
      </strong>
      
       (available in AdSense dashboard).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        data-ad-format
      </code>
    </td>
    
    <td>
      Ad format type (<code>
        auto
      </code>
      
      , <code>
        rectangle
      </code>
      
      , <code>
        horizontal
      </code>
      
      , <code>
        vertical
      </code>
      
      , <code>
        fluid
      </code>
      
      , <code>
        autorelaxed
      </code>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        data-ad-layout
      </code>
    </td>
    
    <td>
      Layout (<code>
        in-article
      </code>
      
      , <code>
        in-feed
      </code>
      
      , <code>
        fixed
      </code>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        data-full-width-responsive
      </code>
    </td>
    
    <td>
      <strong>
        Set to <code>
          true
        </code>
      </strong>
      
       to make the ad responsive.
    </td>
  </tr>
</tbody>
</table>

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

Set `data-ad-layout` for layouts such as `in-article`:

```vue
<template>
  <ScriptGoogleAdsense
    data-ad-client="ca-pub-<your-id>"
    data-ad-slot="1234567890"
    data-ad-format="fluid"
    data-ad-layout="in-article"
  />
</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()`](/scripts/google-adsense) composable

Use [`useScriptGoogleAdsense()`](/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](/docs/guides/registry-scripts) for trigger and loading options.

<callout icon="i-heroicons-light-bulb" target="_blank" to="https://support.google.com/adsense">

See the official **Google AdSense guide**.

</callout>

<script-types>



</script-types>
