# Codeblocks

### Overview

**Codeblocks** allow you to execute custom JavaScript code at specific points in the data processing flow, based on defined triggers. They are designed to give you full flexibility in handling data, firing pixels, or extending tracking behavior.

***

### What is a Codeblock?

A **codeblock** in JENTIS is a JavaScript function that is executed **automatically** when a specified trigger is successfully evaluated.

Use cases include:

* Injecting small tracking pixels
* Executing Data Layer commands
* Bridging between multiple Data Layers
* Injecting custom JavaScript logic
* Handling tool-specific API interactions

***

### Trigger-Based Execution

Each codeblock is linked to a **trigger**. When that trigger condition is met, the associated codeblock(s) will be executed.

If multiple codeblocks are attached to the same trigger, you can control the execution sequence using the **Order** property.

#### Order Property

* Set the `Order` value to define execution priority.
* Codeblocks with **lower order numbers** run **before** those with higher numbers.
* The default execution order is ascending by number.

Example:

| Order | Codeblock Name       | Executed First? |
| ----- | -------------------- | --------------- |
| `1`   | Inject Pixel         | ✅ Yes           |
| `2`   | Push to Data Layer   | ✅ After #1      |
| `5`   | Custom Cleanup Logic | ✅ After #2      |

***

### JavaScript Function Structure

Each codeblock must define a valid **JavaScript function**. This function will be executed by the JENTIS runtime environment.

#### Example:

```javascript
function () {
  console.log("Hello from the codeblock!");
}
```

> No parameters are required — the JENTIS system handles execution.

***

### JENTIS Public Function Scope

Every codeblock is automatically provided with access to a **public function scope**, which includes predefined JENTIS utility functions. These allow you to interact with the system, manipulate values, and communicate with external tools.

A detailed list of available functions and their documentation can be found on the next pages.
