AdSense Snippet injection into Gatsby/React app - Netlify

In order to inject AdSense snippet into your Gatsby/React app which is deployed using Netlify follow the below process.

  1. Login to your Netlify account here's what it looks like: netlify_account Select the site where you want to inject AdSense. In my case, I'd like to inject into the site www.pratapsharma.io.

  2. Click on Site Settings -> and then on Build and Deploy (in the left pane)

  3. Scroll down and find Post-processing -> Snippet Injection and then add on click snippet.

![SnippetInjection](../screenshots/Screen-shot-2020-04-16 at 3.02.49 PM.png "Snippet Injection")

  1. Select the tag from dropdown where you want to insert the script. In our case we'll select Insert before </head>. Then give the name AdSense(you can give any name you like). Finally, paste the link HTML script which you get from Google Adsense in HTML text field. Click on Save.

Snippet

The process of adding AdSense snippet usually takes a few days, but in some cases, it can take up to 2 weeks. Google will notify you when everything's ready.

You've successfully injected Google Adsense into Gatsby/React app.

This has worked great for me, and I personally really like this feature. Especially, for site generator like Gatsby which doesn't include a default index.html file where you can include your scripts.

💌 If you’d like to receive more tutorials in your inbox, you can sign up for the newsletter here.

Discussions

Up next