Snippet injection

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.

You can pick between injecting the scripts before the closing </head> tag or before the closing </body> tag.

Note

Injected snippets will also show up on the password protection screen. This means you can verify that your analytics scripts are correctly configured without having to remove the password when your site is still under development.

Snippet injection UI

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).

API endpoints

You can use the API to get snippets, add snippets, and more.