# Cross-Domain Tracking & Whitelisting

{% hint style="info" %}
Cross-domain tracking allows you to track page views, form submissions, and click events across multiple domains while having all data appear in your main website's dashboard. This is especially useful for ecommerce sites with separate checkout domains or multi-domain setups.
{% endhint %}

Track user interactions across multiple domains and subdomains while maintaining a unified view in your primary Humblytics dashboard. Whether you're running an ecommerce site with a separate checkout domain or managing multiple related websites, cross-domain tracking ensures complete visibility into your user journeys.

***

## How Cross-Domain Tracking Works

Cross-domain tracking enables you to:

* **Track checkout processes** on separate domains (e.g., `yourdomain.com` → `checkout.yourdomain.com`)
* **Monitor multi-step funnels** that span different domains
* **Attribute conversions** from external domains back to your main site
* **Maintain unified analytics** across your entire digital ecosystem

**Key Benefits:**

| Benefit               | Detail                                                       |
| --------------------- | ------------------------------------------------------------ |
| **Unified Dashboard** | All cross-domain events appear in your main site's analytics |
| **Complete Funnels**  | Track user journeys across domain boundaries                 |
| **Cookie-Free**       | No cross-domain cookies or complex consent management        |
| **Privacy-Compliant** | Maintains GDPR compliance across all domains                 |

***

## Cross-Domain Event Tracking

You can track three types of events across domains using the `domain` parameter:

### Page Views

Track when users visit pages on external domains:

```javascript
window.Humblytics.trackPageView("/checkout", {
  domain: "yourdomain.com",
});
```

### Form Submissions

Track form completions on external domains:

```javascript
window.Humblytics.trackFormSubmission("checkout-form", {
  domain: "yourdomain.com",
});
```

### Click Events

Track button clicks and link interactions on external domains:

```javascript
window.Humblytics.trackClickEvent("purchase-button", {
  domain: "yourdomain.com",
});
```

> **Important:** The `domain` parameter should specify the main website domain where you want the event data to appear in your dashboard.

***

## Setup Instructions

### Step 1: Install Humblytics on Both Domains

Both your main domain and the external domain need the Humblytics tracking script:

```html
<!-- Add to <head> of both domains -->
<script
  async
  src="https://app.humblytics.com/hmbl.min.js?id=YOUR_HUMBLYTICS_ID"
></script>
```

### Step 2: Whitelist External Domains (If Required)

For some integrations, you may need to whitelist external domains in your Humblytics dashboard:

1. Navigate to **Settings → Domains**
2. Add the external domain to your whitelist
3. Save the changes

### Step 3: Implement Cross-Domain Tracking

On the external domain, use the tracking methods with the `domain` parameter:

**Example: Ecommerce Checkout Flow**

```javascript
// On checkout.yourdomain.com - track checkout page view
window.Humblytics.trackPageView("/checkout-start", {
  domain: "yourdomain.com",
});

// Track form submission on checkout completion
window.Humblytics.trackFormSubmission("checkout-complete", {
  domain: "yourdomain.com",
});

// Track purchase button clicks
window.Humblytics.trackClickEvent("purchase-cta", {
  domain: "yourdomain.com",
});
```

***

## Common Use Cases

### Ecommerce with Separate Checkout

**Scenario:** Main site on `store.com`, checkout on `checkout.store.com`

```javascript
// On checkout.store.com
window.Humblytics.trackPageView("/checkout", {
  domain: "store.com",
});

window.Humblytics.trackFormSubmission("purchase-form", {
  domain: "store.com",
});
```

### Multi-Domain Company Website

**Scenario:** Main site on `company.com`, blog on `blog.company.com`, support on `help.company.com`

```javascript
// On blog.company.com
window.Humblytics.trackPageView("/blog-post", {
  domain: "company.com",
});

// On help.company.com
window.Humblytics.trackFormSubmission("support-ticket", {
  domain: "company.com",
});
```

### Third-Party Integration Tracking

**Scenario:** Main site on `business.com`, booking system on `bookings.thirdparty.com`

```javascript
// On bookings.thirdparty.com
window.Humblytics.trackFormSubmission("appointment-booking", {
  domain: "business.com",
});
```

***

## Foxycart Integration Example

This cross-domain tracking functionality powers our Foxycart integration:

```html
<!-- In Foxycart custom footer -->
<script
  async
  src="https://app.humblytics.com/hmbl.min.js?id=YOUR_HUMBLYTICS_ID"
></script>

{% if context == 'checkout' %}
<script>
  window.Humblytics.trackPageView("/foxycart-checkout", {
    domain: "your-main-domain.com",
  });
</script>
{% endif %} {% if context == 'receipt' and first_receipt_display %}
<script>
  window.Humblytics.trackPageView("/foxycart-receipt", {
    domain: "your-main-domain.com",
  });
</script>
{% endif %}
```

***

## Best Practices

### Consistent Naming

Use clear, consistent naming for cross-domain events:

* **Page paths:** Use descriptive paths like `/checkout-start`, `/payment-complete`
* **Event labels:** Use descriptive names like `checkout-form`, `newsletter-signup`
* **Domain references:** Always use your primary domain in the `domain` parameter

### Event Organization

Structure your cross-domain events logically:

```javascript
// Good: Descriptive and organized
window.Humblytics.trackPageView("/ecommerce/checkout", { domain: "main.com" });
window.Humblytics.trackFormSubmission("ecommerce-purchase", {
  domain: "main.com",
});

// Avoid: Generic or unclear naming
window.Humblytics.trackPageView("/page1", { domain: "main.com" });
window.Humblytics.trackFormSubmission("form", { domain: "main.com" });
```

### Testing Your Implementation

1. **Install tracking** on both domains
2. **Trigger test events** on the external domain
3. **Verify in dashboard** that events appear under your main domain
4. **Check attribution** by following the complete user journey

***

## Viewing Cross-Domain Data

All cross-domain events appear in your main dashboard exactly like native events:

* **Page Views:** Dashboard → Pages
* **Form Submissions:** Dashboard → Conversions → Forms
* **Click Events:** Dashboard → Clicks
* **Funnels:** Include cross-domain steps in funnel analysis
* **Split Tests:** Use cross-domain events as conversion goals

***

## Using Cross-Domain Events in Split Tests

Beyond just tracking cross-domain interactions, you can use these events as **conversion goals in split tests**. This enables sophisticated A/B testing scenarios where the conversion happens on external domains.

### When to Use Cross-Domain Event Goals

**Instead of simple destination page tracking**, use cross-domain events when:

* **Complex conversion flows:** The conversion involves multiple steps or specific interactions on external sites
* **Precise tracking:** You need to track the actual conversion action, not just page arrival
* **External checkout processes:** Track completed purchases on separate checkout domains
* **Third-party integrations:** Monitor conversions through external booking systems, forms, or apps

### Setup Process

**Step 1: Implement Cross-Domain Event Tracking**

Set up the appropriate tracking on your external domain:

```javascript
// Example: Track checkout completion on external domain
window.Humblytics.trackFormSubmission("checkout-complete", {
  domain: "yourmainsite.com",
});

// Example: Track specific page interactions
window.Humblytics.trackClickEvent("external-signup-button", {
  domain: "yourmainsite.com",
});

// Example: Track custom page view events
window.Humblytics.trackPageView("/external-conversion-step", {
  domain: "yourmainsite.com",
});
```

**Step 2: Create Split Test with Event Goal**

1. Navigate to **Split Testing** → **Start New Experiment**
2. Choose the appropriate **event goal type**:
   * **Form Submission Event** for `trackFormSubmission()` calls
   * **Click Event** for `trackClickEvent()` calls
   * **Page View Event** for `trackPageView()` calls
3. **Enter the exact event name** from your tracking code (e.g., "checkout-complete", "external-signup-button")

**Step 3: Configure Variants and Launch**

Set up your page variants as normal and launch the test. The cross-domain events will be attributed to the correct split test variant based on the user's session.

### Real-World Examples

**Ecommerce Checkout Optimization**

```javascript
// Split test: Optimize product pages for checkout completion
// Goal: Track actual purchases, not just checkout page visits

// On external checkout domain
window.Humblytics.trackFormSubmission("purchase-complete", {
  domain: "store.com",
});

// Split test goal: Form Submission Event = "purchase-complete"
```

**Lead Generation with External Forms**

```javascript
// Split test: Optimize landing pages for form completions
// Goal: Track successful form submissions on third-party platform

// On external form platform
window.Humblytics.trackFormSubmission("lead-qualified", {
  domain: "business.com",
});

// Split test goal: Form Submission Event = "lead-qualified"
```

**SaaS Trial Activation**

```javascript
// Split test: Optimize signup flow for trial activation
// Goal: Track when users complete onboarding on external app

// On external app domain
window.Humblytics.trackPageView("/onboarding-complete", {
  domain: "marketing-site.com",
});

// Split test goal: Page View Event = "/onboarding-complete"
```

### Advanced Attribution

Cross-domain event goals maintain proper attribution throughout complex user journeys:

1. **User visits** your split test page variant
2. **User navigates** to external domain (checkout, booking, etc.)
3. **Cross-domain event** fires on external domain
4. **Attribution preserved** back to original split test variant
5. **Conversion counted** for the correct test group

This enables testing of complete conversion funnels that span multiple domains while maintaining accurate statistical analysis.

### Best Practices for Split Test Goals

**Event Naming:**

* Use descriptive, unique event names
* Maintain consistency across domains
* Document your event naming convention

**Timing:**

* Ensure events fire after the Humblytics script loads
* Place tracking calls at the actual conversion moment
* Test event firing across different user scenarios

**Validation:**

* Test the complete flow from split test variant to cross-domain conversion
* Verify events appear in your dashboard with correct attribution
* Monitor for any attribution delays or issues

***

## Hash Fragment Support

Multi-step forms using URL fragments (`#step-1`, `#step-2`) now track properly across domains. This ensures accurate funnel tracking for:

* **Multi-step checkout flows** with hash-based navigation
* **Progressive forms** that use URL fragments for step tracking
* **Single-page applications** with hash routing

Enable hash fragment tracking in your site settings to capture these interactions accurately.

## Troubleshooting

### Events Not Appearing

**Check the following:**

1. Humblytics script is installed on the external domain
2. The `domain` parameter matches your main domain exactly
3. External domain is whitelisted (if required)
4. Events are being triggered after the Humblytics script loads
5. Hash fragment tracking is enabled in site settings (for multi-step forms)

### Incorrect Attribution

**Verify:**

1. The `domain` parameter value is correct
2. Timing of event tracking (wait for script to load)
3. Network connectivity from external domain to Humblytics

***

## Advanced Implementation

### Dynamic Domain Detection

For complex setups, you can dynamically set the domain parameter:

```javascript
// Automatically detect main domain
const mainDomain = window.location.hostname.includes("checkout")
  ? "yourdomain.com"
  : window.location.hostname;

window.Humblytics.trackPageView("/current-page", {
  domain: mainDomain,
});
```

### Conditional Cross-Domain Tracking

Only track cross-domain when necessary:

```javascript
function trackEvent(eventType, eventName, options = {}) {
  const isExternalDomain = window.location.hostname !== "yourdomain.com";

  if (isExternalDomain) {
    options.domain = "yourdomain.com";
  }

  if (eventType === "pageView") {
    window.Humblytics.trackPageView(eventName, options);
  } else if (eventType === "formSubmission") {
    window.Humblytics.trackFormSubmission(eventName, options);
  }
}
```

***

**Questions or need help with complex cross-domain setups?** Email **<support@humblytics.com>** for guidance on advanced implementations and custom attribution models.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.humblytics.com/cross-domain-tracking-and-whitelisting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
