npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-google-ads-advanced

v1.0.5

Published

A React component for integrating Google Ads with capability to suppress ads which are unfilled or not loaded, enhancing user experience by avoiding empty ad spaces.

Downloads

17

Readme

npm version   package size minified   jsdelivr package   JavaScript Style Guide

total downloads   total downloads per year   total downloads per week   total downloads per month   download-image  

react-google-ads-advanced


📦 Installation

npm i react-google-ads-advanced

# or
yarn add react-google-ads-advanced

# or
pnpm i react-google-ads-advanced

# or
bun add react-google-ads-advanced

🚀 Features

  • Easy to use React component
  • Automatically loads Google AdSense ads
  • Observes ad fill status and hides unfilled ads
  • Fully customizable with className and style props
  • Lightweight and zero dependencies
  • Supports responsive ads out of the box

🧠 Usage

Before doing any of this, you must make sure Adsense Ads Script is in your project according to the framework guidelines.

React (CRA)

If you’re using Create React App or a plain React setup, first import the global observer in the App.tsx or App.jsx:

// src/App.tsx|jsx
import React from "react";

import { GoogleAdsObserver } from "react-google-ads-advanced";

// VERY IMPORTANT
import "react-google-ads-advanced/dist/index.css";

function App() {
  return (
    <div className="App">
      {/* Place observer once globally */}
      <GoogleAdsObserver />
    </div>
  );
}

Vite + React

For Vite, you can use it the same way:

// src/main.tsx|jsx
import React from "react";

import { GoogleAdsObserver } from "react-google-ads-advanced";

// VERY IMPORTANT
import "react-google-ads-advanced/dist/index.css";

function Main() {
  return (
    <>
      <GoogleAdsObserver />
    </>
  );
}

export default Main;

Next.js Pages Router

If your app uses pages/ (classic router):

// pages/_app.tsx|jsx
import type { AppProps } from "next/app";

import { GoogleAdsObserver } from "react-google-ads-advanced";

// VERY IMPORTANT
import "react-google-ads-advanced/dist/index.css";

function MyApp({ Component, pageProps }: AppProps) {
  return (
    <>
      {/* Global ad observer */}
      <GoogleAdsObserver />
      <Component {...pageProps} />
    </>
  );
}

export default MyApp;

Next.js (App Router)

If your app uses the new app/ directory:

// app/layout.tsx|jsx
import "./globals.css";

import { GoogleAdsObserver } from "react-google-ads-advanced";

// VERY IMPORTANT
import "react-google-ads-advanced/dist/index.css";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        <GoogleAdsObserver />
        {children}
      </body>
    </html>
  );
}

NOTE: After all the initial setup according to your framework, now you can place the ad anywhere in you app:

<GoogleAd
    clientId="<your-client-id>"
    slot="<your-slot-id>"
    {/* OTHER PROPS */}
/>

⚙️ Props

| Prop | Type | Default | Description | | ----------------------- | --------------------- | ------------ | ----------------------------------------------------- | | clientId | string | Required | Your Google AdSense client ID (ca-pub-XXXXXXXXXXXX) | | slot | string | Required | Ad slot ID from AdSense | | adFormat | string | "auto" | Format of the ad (auto, rectangle, etc.) | | adFullWidthResponsive | string | "true" | Enables full-width responsive ads | | className | string | "" | Additional custom CSS classes | | style | React.CSSProperties | {} | Inline styles for the ad block | | ...rest | any | — | Other props passed to the <ins> element |


Components Overview

🪄 GoogleAds

Renders a Google AdSense <ins> tag and automatically pushes it to the adsbygoogle queue.

<GoogleAds clientId="<your-client-id>" slot="<your-slot-id>" adFormat="auto" />

GoogleAdsObserver

Watches for dynamically loaded ads and hides empty or unfilled ad blocks automatically.

  • Uses a MutationObserver to track attribute changes on all <ins> tags.
  • If the ad is marked as "done" but "unfilled" or has no children (iframe missing), it hides the element.

You only need one instance globally:

<GoogleAdsObserver />

💡 Notes

  • Must include Google AdSense script in your app according to your framework guideline:
<script
  async
  src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"
  crossorigin="anonymous"
></script>
  • Make sure your AdSense account and slots are approved before testing.
  • Ads do not work in the development mode.

🧑‍💻 Author

Built and maintained by Farasat Ali