Join us at JAMstack Conf San Francisco, October 16-18. Register today

Injecting JavaScript Snippets

Often you want to inject JavaScript snippets into all pages of your site, either in the <head> or at the end of the <body> tag.

Most analytics providers, retargeting services, and A/B testing services will give you an HTML snippet and ask you to add it to every page on your site.

Netlify lets you do this without having to pollute the source code for the site with production specific analytics snippets.

From the site Build & Deploy Settings page, find the “Snippet Injection” section in the “Post processing” portion of the page, and click “Add Snippet”. Then give your script a name and paste the script body (including any <script> tags, etc).

Netlify lets you pick between injecting the scripts in before the closing </head> tag or before the closing </body> tag.

Note, scripts injected in this way will also show up on the password protection screen. This means you can easily verify that your analytics scripts are correctly configured without having to remove the password when your site is still under development.

Notice something is incorrect or outdated?

First off, great catch! We appreciate your discovery and want to ensure it gets addressed immediately. Please let us know here.

Want to have a conversation?

Visit the Netlify Community to discuss ideas and questions with your fellow Netlify users.

Want to get started quick?