StatelessID

Directory

When your tracked site lives at example.com/blog/ instead of its own domain, the snippet still goes in the page template — the subdirectory path is just another part of the URL your dashboard will show.

Subdirectories are part of the same origin

Unlike subdomains, subdirectories do not create a new origin. https://example.com/blog/ and https://example.com are both the https://example.com origin. A single site registration for example.com covers all paths under it, including /blog/, /shop/, /docs/, or any other directory.

This means you do not need a separate site registration for a subdirectory install. Use the same key you already use for example.com. Paste the snippet in the template for the subdirectory section, or — better — keep it in the shared sitewide template so every path on the domain is measured together.

Your dashboard will show page views for each distinct URL. The Pages column breaks down traffic by full path, so you can see /blog/post-one, /blog/post-two, and / all as separate rows in the same site view.

Installing in a WordPress subdirectory

If WordPress runs at example.com/blog/ and your main site is a separate application at example.com/, they may use different template systems. The WordPress install at /blog/ has its own theme. Paste the snippet in the WordPress theme's footer.php or use the theme customizer's custom HTML section to add the tag.

Use the same site key as your main domain unless you want blog traffic counted separately. If you want separate counts, register a new site in your dashboard with a name like "example.com/blog" and use its distinct key only in the WordPress theme.

After installing, load a blog post and watch the dashboard. The page view should appear with the full path — /blog/the-post-slug — in the Pages breakdown.

Installing in a static subdirectory

If the subdirectory is a folder of static HTML files — for example a documentation site generated by a tool like MkDocs or Docusaurus — find the base layout template that wraps every page and paste the snippet there.

For MkDocs, that is the docs/overrides/main.html override or the mkdocs.yml extra_javascript setting. For Docusaurus, it is the src/theme/Root.js component or the docusaurus.config.js scripts array. For most static site generators, there is a single layout file that controls what goes in the <head> of every output page.

Build the site, deploy the output folder, and open a page under the subdirectory. Check the Network tab in browser developer tools for the asset.js request and the /t/c beacon to confirm both fired.

Separating subdirectory data from the rest of the site

Even if both the main site and the subdirectory use the same key, your dashboard already separates them by path in the Pages column. You can filter to /blog/* paths to see only blog traffic without registering a separate site.

If you do want completely separate charts, cycle counts, and quotas for the subdirectory, register a new site and use a dedicated key only inside the subdirectory template. The only cost is maintaining two dashboard entries instead of one.

There is no wrong answer here. For a simple site where the blog and the homepage belong to the same operation, one key and one dashboard entry is cleaner. For an agency managing a client's blog on a subdirectory of their own domain, a separate entry gives the client a clean view of their content traffic.

Troubleshooting

I installed the snippet in a subdirectory and now I see page views in the dashboard but I cannot tell which URLs are from that directory. Open the Pages tab in your dashboard and look at the path column. Every page view shows its full path, so /blog/post-title will appear as a distinct row.

The snippet is in my subdirectory template but page views from the main domain stopped showing up. Confirm the main domain template still has the snippet too. If you removed it from the shared layout and only added it to the subdirectory template, pages outside that directory lost tracking.

My subdirectory app and main site show different page view counts for the same day. If they use different keys, they are counted separately — that is expected. If they use the same key, the counts combine. Check which key is in each template to confirm the setup is what you intended.

Similar pages