---
title: "Google Adsense · Nuxt Scripts"
description: "Show Google Adsense ads in your Nuxt app."
canonical_url: "https://scripts.nuxt.com/scripts/v0/ads/google-adsense"
meta:
  "og:description": "Show Google Adsense ads in your Nuxt app."
  "og:image": "https://scripts.nuxt.com/_og/d/c_Docs%2Ctitle_Google%2BAdsense%2Cdescription_Show%2BGoogle%2BAdsense%2Bads%2Bin%2Byour%2BNuxt%2Bapp.%2Cheadline_Ads%2Cp_Ii9zY3JpcHRzL3YwL2Fkcy9nb29nbGUtYWRzZW5zZSI%2Cs_puaE9D9yyvQomLYe.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/d/c_Docs%2Ctitle_Google%2BAdsense%2Cdescription_Show%2BGoogle%2BAdsense%2Bads%2Bin%2Byour%2BNuxt%2Bapp.%2Cheadline_Ads%2Cp_Ii9zY3JpcHRzL3YwL2Fkcy9nb29nbGUtYWRzZW5zZSI%2Cs_puaE9D9yyvQomLYe.png"
---

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

**Ads**

# **Google Adsense**

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

[**Google AdSense**](https://www.google.com/adsense/start/) allows you to monetize your website by displaying relevant ads from Google.

Nuxt Scripts provides:

- `**useScriptGoogleAdsense**`: A composable to manage Google AdSense dynamically.
- `**<ScriptGoogleAdsense>**`: A headless component to embed ads directly in your Nuxt app.

## Global Setup

You can configure Google AdSense **globally** in your `**nuxt.config.ts**` so that the script is automatically loaded on all pages.

nuxt.config.ts

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

## Where to Find `**<your-id>**` (Publisher ID)

Your **Google AdSense Publisher ID** (also known as `**ca-pub-XXXXXXX**`) can be found in your **Google AdSense Account**:

1. Log in to your **Google AdSense** account.
2. Navigate to **Account > Settings** (click on your profile icon > "Account information").
3. Locate the **Publisher ID** under **Account Information**.
4. Replace `**<your-id>**` in the config above with your actual ID.

[Open related resource on adsense.google.com](https://adsense.google.com/start/)You can also manage **Auto Ads settings** from your **Google AdSense Dashboard** to control *ad types, placements, and revenue optimization*.

## Site Ownership Verification

### Automatic Meta Tag Insertion

If a `**client**` is provided, a **meta tag** will be inserted on the page **automatically** 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
        },
      },
  },
});
```

### Using `**ads.txt**` for Verification

Google recommends adding an `**ads.txt**` file for **ad revenue eligibility**.

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

**Why use `**ads.txt**`?** It helps **prevent ad fraud** and ensures that **only your site** can display your ads.

## Enabling Auto Ads

Auto Ads allow Google to **automatically** place ads for **better optimization**.

nuxt.config.ts

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

## Using `**ScriptGoogleAdsense**` Component

It provides a simple way to **embed ads** in your Nuxt app.

```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**`, `**in-feed**`, `**fixed**`). |
| `**data-full-width-responsive**` | **Set to `**true**`** to make the ad responsive. |

#### **Example Usage with **`**data-ad-layout**`

To specify a layout for your ads (such as "in-article"), you can use the `**data-ad-layout**` attribute:

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

## How to Handle Ad-Blockers?

If a user has an **ad-blocker enabled**, you can show **fallback content**.

```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 `**useScriptGoogleAdsense**` Composable

The `**useScriptGoogleAdsense**` composable allows **fine-grain control** over the AdSense script.

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

See the [**Registry Scripts Guide**](https://scripts.nuxt.com/docs/v0/guides/registry-scripts) for advanced usage.

## GoogleAdsenseApi Interface

This interface defines the structure of the Google Adsense API for better TypeScript support.

```ts
export interface GoogleAdsenseApi {
  adsbygoogle: any[] & { loaded: boolean };
}
```

## GoogleAdsenseInput

You can define the input options for the `**useScriptGoogleAdsense**` composable using the following structure:

```ts
export const GoogleAdsenseOptions = object({
  /**
   * The Google Adsense Publisher ID.
   */
  client: optional(string()),
  /**
   * Enable or disable Auto Ads.
   */
  autoAds: optional(boolean()),
});
```

[Open related resource on support.google.com](https://support.google.com/adsense)Need more help? Check out the official **Google AdSense Guide**

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

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

[**Carbon Ads** Show carbon ads in your Nuxt app using a Vue component.](https://scripts.nuxt.com/scripts/v0/ads/carbon-ads) [**Cloudflare Web Analytics** Use Cloudflare Web Analytics in your Nuxt app.](https://scripts.nuxt.com/scripts/v0/analytics/cloudflare-web-analytics)

**On this page **

- [Global Setup](#global-setup)
- [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 ScriptGoogleAdsense Component](#using-scriptgoogleadsense-component)
- [How to Handle Ad-Blockers?](#how-to-handle-ad-blockers)
- [Using useScriptGoogleAdsense Composable](#using-usescriptgoogleadsense-composable)
- [GoogleAdsenseApi Interface](#googleadsenseapi-interface)
- [GoogleAdsenseInput](#googleadsenseinput)

```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/v0/ads/google-adsense#webpage","@type":"WebPage","description":"Show Google Adsense ads in your Nuxt app.","name":"Google Adsense","url":"https://scripts.nuxt.com/scripts/v0/ads/google-adsense","breadcrumb":{"@id":"https://scripts.nuxt.com/scripts/v0/ads/google-adsense#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/scripts/v0/ads/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/v0/ads/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":"V0","item":"https://scripts.nuxt.com/scripts/v0","position":3},{"@type":"ListItem","name":"Ads","item":"https://scripts.nuxt.com/scripts/v0/ads","position":4},{"@type":"ListItem","name":"Google Adsense","item":"https://scripts.nuxt.com/scripts/v0/ads/google-adsense","position":5}]},{"@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.
