Skip to content

Commit

Permalink
Use latest method of adding adsense script provided by google adsense
Browse files Browse the repository at this point in the history
Signed-off-by: isamrish <[email protected]>

In latest script, google adsense cliend id is being provided by data attributes
  • Loading branch information
isamrish committed Jun 3, 2020
1 parent 3eaaf4e commit 6c65e0c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 290 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ 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).
14 changes: 2 additions & 12 deletions src/gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,10 @@ export const onRenderBody = (
: setPostBodyComponents;
return setComponents([
<script
key={`gatsby-plugin-google-adsense`}
data-ad-client={`${pluginOptions.googleAdClientId}`}
async
type="text/javascript"
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"
/>,
<script
key={`gatsby-plugin-google-adsense`}
dangerouslySetInnerHTML={{
__html: `
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: ${pluginOptions.googleAdClientId},
enable_page_level_ads: true
});
`
}}
/>
]);
};
Loading

0 comments on commit 6c65e0c

Please sign in to comment.