https://github.com/isamrish/gatsby-plugin-google-adsense
A Gatsby plugin to easily add a google adsense to your gatsby site
https://github.com/isamrish/gatsby-plugin-google-adsense
gatsby-plugin gatsby-site google-adsense javascript
Last synced: 3 months ago
JSON representation
A Gatsby plugin to easily add a google adsense to your gatsby site
- Host: GitHub
- URL: https://github.com/isamrish/gatsby-plugin-google-adsense
- Owner: isamrish
- License: mit
- Created: 2019-08-04T06:43:27.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T08:10:20.000Z (over 2 years ago)
- Last Synced: 2024-03-23T04:22:50.829Z (about 1 year ago)
- Topics: gatsby-plugin, gatsby-site, google-adsense, javascript
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@isamrish/gatsby-plugin-google-adsense
- Size: 882 KB
- Stars: 11
- Watchers: 2
- Forks: 5
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
gatsby-plugin-google-adsense
Add Google Adsense to your Gatsby site.
![]()
![]()
## Install
```
npm install @isamrish/gatsby-plugin-google-adsense
```or
```
yarn add @isamrish/gatsby-plugin-google-adsense
```## Usage in Gatsby website
```javascript
// In your gatsby-config.js
module.exports = {
plugins: [
{
resolve: `@isamrish/gatsby-plugin-google-adsense`,
options: {
googleAdClientId: "YOUR_GOOGLE_ADSENSE_TRACKING_ID",
head: false // Optional
}
}
]
};
```## Options
### `googleAdClientId`
Here you place your Google Adsense tracking id.
### `head`
Here you can define where to place the tracking script. With `head:true` it will placed in the header, with `head:false` it will placed in the body. Default is `false`.
Google adsense recommends to put script in [head tag](https://support.google.com/adsense/answer/9274516).
## Example of Adsense component
```javascript
// In your adsense component
import React from "react";export default function AdSense() {
React.useEffect(() => {
if (process.env.NODE_ENV !== "development") {
if (window) {
try {
(window.adsbygoogle = window.adsbygoogle || []).push({});
} catch (error) {
console.log(error, "adsenese error");
}
}
}
}, []);return (
);
}
```