Coder Social home page Coder Social logo

shriekdj / nextjs13_google_adsense Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 302 KB

Google Adsense package for working into the nextjs 13 and above.

License: MIT License

TypeScript 100.00%
google-adsense nextjs nextjs13 react shriekdj nextjs13-google-adsense

nextjs13_google_adsense's Introduction

nextjs13_google_adsense

This Package Helps reload ad on Every Page change in the nextjs 13 application and above.

Before using this package add this code in head of your root layout file.

<Script
  async
  src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234567890123456"
  crossOrigin="anonymous"
  strategy="lazyOnload"
/>

From Google You May Get this type code for ad unit which should be changed.

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234567890123456" crossorigin="anonymous"></script>
<!-- Homepage Leaderboard -->
<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-1234567890123456" data-ad-slot="1234567890"></ins>
<script>
(window.adsbygoogle = window.adsbygoogle || []).push({});
</script>

It should be changed to like this in your page

import GoogleAdUnit from 'nextjs13_google_adsense'

export default function MyPage() {
  return <>
  <div>Test Title</div>
  <GoogleAdUnit>
    <ins
          className="adsbygoogle"
          style={{ display: 'block', width: '100%' }}
          data-ad-client="ca-pub-1234567890"
          data-ad-slot="123456"
          data-ad-format="auto"
          data-full-width-responsive="true"
        ></ins>
  </GoogleAdUnit>
  <div>Test Content</div>
  <>;
}

If any errors occured then errors will be displayed on client or your browser's console.

nextjs13_google_adsense's People

Contributors

shriekdj avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

anhgeeky

nextjs13_google_adsense's Issues

Ads shows only on first page load

Thank you for your google adsense package. I am suing the package in Next js 14 and everything works fine except it only works on first page load. I have it installed on the home page (/app/page.js). However, when I navigate away from the home page and come page, the Ads do no show anymore.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.