# Cross-domain tracking

During your first few weeks on Flip.to's Discovery, we conduct A/B tests that rely on cross-domain tracking to measure results accurately. Discovery supports this tracking out-of-the-box. For the Control (your current booking flow without Discovery), you may need an additional snippet of code to set your website up for tracking.

If you use JavaScript to navigate users from your website to your booking engine, this guide will help you complete your implementation of Discovery.

{% hint style="warning" %}
**Before you begin**: your Flip.to code snippets should already be added to your website. See the guide to [set up your website](broken://pages/vXGa5c2N9VuJXAgTv3Ax) if you haven't completed this step.
{% endhint %}

***

## Setting up cross-domain tracking&#x20;

There are specific ways to set up tracking based on different JavaScript navigation approaches. Look for the approach that you use on your website and apply the appropriate code.

### Approach 1: Delayed redirects

If you use the location.href property to redirect users (can also be **location.assign**, **location.replace**, **window\.open**, **$.post**, or similar), and there is a delay or a user action is required before redirecting:

Add the following code before you redirect the user (using **location.href** as an example).

```javascript
if ('function' == typeof window.fliptoDecorate) {
    bookingEngineUrl = fliptoDecorate(bookingEngineUrl);
}

location.href = bookingEngineUrl;
```

### Approach 2: Form element redirects

If you use a **formObject** to redirect users (can also be **document.form\[0].submit()**, **document.querySelector(“nav.form”).submit,** or similar):

Add the following code before you redirect the user (using **formObject.submit()** as an example).

```javascript
if ('function' == typeof window.fliptoDecorate) {
   fliptoDecorate(formObject);
}

formObject.submit();
```

### Approach 3: Immediate redirects

If you use **location.href** to redirect users (can also be **location.assign**, **location.replace**, **window\.open**, **$.post**, or similar), and there is no delay and no user action is required before redirecting:

Replace your existing redirect with the following code. Adjust the code for your specific redirect property and preferred timing options (using **location.href** as an example).

```javascript
(function(url, delay, max){
    var i = 0;
    var interval = window.setInterval(function() {
    if ('function' == typeof window.fliptoDecorate) {
        window.clearInterval(interval);
        window.location.href = window.fliptoDecorate(url);
    } else if (i++ >= max){
        window.clearInterval(interval);
        window.location.href = url;
    }
}, delay);
})(bookingEngineUrl, 100, 20);
```

*The above shows waiting on fliptoDecorate up to 2 seconds, checking every 100ms.*


---

# 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.flip.to/developers/integrations/websites/cross-domain-tracking.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.
