In this beginner tutorial you’ll learn how to properly add the analytics code to your website.

When you want to add the analytics tracking code for data collection, you place the code inside the header of the website which is the head tag. The head tag is where you add the code that you have copied from the third-party sites, so you can use its services.

A code example

Let’s say you have a tracking code from Plausible Analytics, and you want to use it on your website. The tracking code looks something like this:

<script defer data-domain="yourdomain.com" src="<https://plausible.io/js/plausible.js>"></script>

All you have to do is insert the code anywhere between the opening <head> tag and the closing </head> tag. Here’s an example of how it’s done:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script defer data-domain="yourdomain.com" src="<https://plausible.io/js/plausible.js>"></script>
    <title>Example site</title>
  </head>
  <body>...</body>
</html>

Once you added the code and upload it to the live server, go to your analytic tool’s dashboard and check if you are receiving the data. If yes, it is a success. And if not, you may have to wait few minutes before the analytic tool starts collecting the data.

And that’s how you add the tracking code to your website. This approach works for all website analytic tools like Google, Plausible, Fathom, and so on.