# How the Optibase Script Works

The Optibase Custom Script is the engine that powers your entire optimization suite. It is a lightweight JavaScript snippet that handles live testing, behavioral tracking (Heatmaps/Recordings), and conversion attribution in real time.

Without this script installed, Optibase cannot run tests, capture heatmaps, or track conversions.

***

### Core Technical Functions

#### 1. Dynamic Test Logic

On every page load, the script performs a secure handshake with Optibase servers to:

* Identify active experiments for the specific URL.
* Evaluate Audience Restrictions (Geo-location, Browser type, OS, etc.).
* Determine if the user should be included in a test or a personalization campaign.

#### 2. A/B & Multivariate Testing (No-Flicker Technology)

To ensure a seamless user experience, the script:

* Scans the page for elements containing `data-optibase-test-id` and `data-optibase-variant-id`.
* Assigns the user to a specific variant.
* Instant Reveal: It removes the `display:none` style from the chosen variant and deletes non-selected variants from the DOM.
* Pro-Tip: Ensure your "Main Variant" is the only one visible by default in your Webflow or WordPress editor to prevent a flash of unstyled content.

#### 3. URL-Based Split Testing

For redirect-based experiments, the script:

* Checks if the current URL is a "Split Test" entry point.
* Decides whether to keep the user on the current page or trigger an immediate redirect.
* Context Preservation: If a redirect occurs, it appends `splitTestId` and `splitVariantId` parameters to the URL so the destination page knows which experiment is active.

#### 4. Behavioral Intelligence & Analytics

The script is also responsible for your site’s "Intelligence" features:

* Heatmaps: Maps user clicks, scrolls, and mouse movements.
* User Recording Sessions: Captures the visual journey of a user to find friction points.
* Analytics: Collects page view data and interaction events.

> Note: Page views only count toward your plan limits if an active or eligible test is present on the page.

#### 5. Conversion Attribution

The script automatically attaches event listeners to track:

* Click Conversions: (`data-optibase-click-conversion-id`)
* Form Submissions: (`data-optibase-submit-conversion-id`)
* Event Logic: When a user converts, the script attributes that success to all active A/B variants the user has seen during that session.

***

### Debugging and Developer Controls

You can control how the script behaves in your specific browser using URL parameters. This is essential for testing your setup before going live.

| **Action**          | **URL Parameter**           | **Result**                                       |
| ------------------- | --------------------------- | ------------------------------------------------ |
| Enable Debug Mode   | `?optibaseEnableDebugMode`  | Shows step-by-step logic in the browser console. |
| Disable Debug Mode  | `?optibaseDisableDebugMode` | Stops logging to the console.                    |
| Disable All Scripts | `?optibaseDisableScript`    | Blocks all tests and tracking in your browser.   |
| Re-enable Script    | `?optibaseEnableScript`     | Restores normal script behavior.                 |

***

### Summary of Capabilities

The Optibase script is a multi-purpose tool that:

1. Determines test eligibility based on audience and URL.
2. Renders the correct A/B or Multivariate variant instantly.
3. Redirects users for Split Tests.
4. Records heatmaps and user session replays.
5. Tracks conversions and sends data to your Optibase Dashboard.


---

# 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.optibase.io/basics/how-the-optibase-script-works.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.
