Source: https://datafa.st/docs/subdomain-tracking
Markdown source: https://datafa.st/docs/subdomain-tracking.md
Description: Learn how to track visitors seamlessly across multiple subdomains with DataFast for unified analytics data.

# Track visitors across subdomains

DataFast automatically tracks visitors across any subdomains of your main domain for maximum analytics accuracy.

> Need to track across completely different domains? Check out [cross-domain tracking](/docs/cross-domain-tracking) for tracking between different root domains.

![Hostname tracking screenshot](/blog-subdomains.jpg)

## Setting up subdomain tracking

1. Create a website in DataFast using your **root domain** (e.g., `example.com`)
2. Install the tracking script on all your subdomains (e.g., `app.example.com`, `blog.example.com`)
3. Use the same website ID and domain parameter across all installations

```html
<script
  defer
  data-website-id="dfid_******" 
  data-domain="your_domain.com"
  src="https://datafa.st/js/script.js"
></script>
```

> Important: Always use your root domain in the `data-domain` attribute, not the specific subdomain.

## Benefits of cross-subdomain tracking

- **Unified visitor journey**: Track users as they navigate between your marketing site, app, blog, and other subdomains
- **Accurate attribution**: Properly attribute conversions to marketing campaigns even if users move between subdomains
- **Advanced filters**: Filter your analytics by subdomain for better insights

## Common use cases

- Track user journeys from your marketing site (`example.com`) to your app (`app.example.com`)
- Attribute conversions to the correct marketing channel when users navigate across subdomains
- Analyze how content on your blog (`blog.example.com`) drives traffic to your main site

DataFast handles all the cross-domain cookie synchronization automatically, so you don't need to write any additional code to track users across subdomains.

> Note: Need to track across completely different root domains? See the [cross-domain tracking](/docs/cross-domain-tracking) guide. For advanced proxy configurations, check the [Proxy through Next.js](/docs/nextjs-proxy) guide.
