> For the complete documentation index, see [llms.txt](https://docs.humblytics.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.humblytics.com/how-to-get-started/astro.md).

# Astro

Add Humblytics to your Astro site in about 5 minutes.

{% hint style="info" %}
**You need:** access to your layout file and a production deploy. `npm run dev` won't verify.
{% endhint %}

## 1. Copy your tracking code

In Humblytics, open **Site settings → Install** and click **Copy tracking code**. Adding a new site? Click **Add site** on **Home** and the code appears in the install step.

## 2. Add it to your layout

Open your shared layout, such as `src/layouts/Layout.astro`, and paste the snippet before `</head>`. Add `is:inline` to **both** `<script>` tags so Astro doesn't bundle or move them:

```astro
<head>
  <!-- your existing meta tags -->

  <!-- Start Humblytics Tracking Code -->
  <style>html.hmbl-pending body{opacity:0!important}</style>
  <script is:inline>
    (function(){
      var w=window,l=location,d=document.documentElement,done=false;
      function k(p){p=String(p||'/').toLowerCase();while(p.length>1&&p.charAt(p.length-1)==='/')p=p.slice(0,-1);for(var h=5381,i=0;i<p.length;i++)h=((h*33)^p.charCodeAt(i))>>>0;return h.toString(36);}
      function r(){if(done)return;done=true;d.classList.remove('hmbl-pending');if(d.style.opacity==='0')d.style.opacity='';}
      w._hmblReveal=r;
      if(document.readyState!=='loading'||/[?&](hmblEditor|hmblSessionRecording|humblytics_heatmap_token)=|#preview-humblytics-/.test(l.search+l.hash))return;
      var st=new URLSearchParams(l.search).get('_st'),ref=document.referrer,same=!ref;
      try{same=same||new URL(ref).host===l.host;}catch(e){same=true;}
      if(st&&same&&st===k(l.pathname)){
        w._hmblSt=st;
        if(!(w.fbq||w.google_tag_manager||w.ttq)){var u=new URL(l.href);u.searchParams.delete('_st');history.replaceState(history.state,'',u.href);}
        return;
      }
      d.classList.add('hmbl-pending');
      function cap(){setTimeout(function(){if(!w.HumblyticsRedirectRunning)r();},2000);setTimeout(r,4000);}
      if(document.prerendering)document.addEventListener('prerenderingchange',cap,{once:true});else cap();
      w.addEventListener('pageshow',function(e){if(e.persisted)r();});
    })();
  </script>
  <script is:inline async src="https://app.humblytics.com/hmbl.min.js?id=YOUR_SCRIPT_ID" onerror="window._hmblReveal&&window._hmblReveal()"></script>
  <!-- End Humblytics Tracking Code -->
</head>
```

Replace `YOUR_SCRIPT_ID` with the Script ID from your snippet.

* **Several layouts?** Put the snippet in a component, such as `src/components/Humblytics.astro`, and include it in each layout's `<head>`.
* **Using `<ClientRouter />` (view transitions)?** No extra code. Humblytics tracks client-side navigation on its own.

## 3. Build, deploy, and verify

1. Build and deploy to production.
2. Back in Humblytics, click **Verify install** (during first-time setup, **Check my site now**).
3. Open your live site in a private window and click around. Your visit appears in **Observe → Analytics → Overview** under **Live Activity** within about a minute.

**Not verifying?**

* Both script tags have `is:inline`. Without it, Astro processes the script and the tracking code can break.
* Every page uses a layout that includes the snippet.

Still stuck? See [Verify & Troubleshoot Tracking](https://docs.humblytics.com/how-to-get-started/verify-and-troubleshoot-tracking.md).
