Skip to main content

RTB JavaScript Response Processing

D
Written by Denise Abdullah
Updated over 2 months ago

FEATURE ENHANCEMENT RELEASE
RTB JavaScript Response Processing
Location: Routing → RTBs → RTB Steps

Overview
We’ve enhanced MojaAI’s RTB engine with JavaScript-based response processing, giving you far more flexibility in transforming and shaping RTB responses before routing decisions occur. This improvement unlocks dynamic business logic, deeper control, and greater consistency across multiple buyers or data sources — all without engineering support.

What’s New
Custom JavaScript Processing
You can now write JavaScript directly within an RTB step to transform the API response in real time. This lets you:
Add or modify fields
Apply conditional business rules
Normalize responses across different buyers
Filter and reshape data structures
Build dynamic logic that reacts to real-time bid values
Enhanced Visibility & Testing
The RTB editor now includes:
A built-in JavaScript editor
Test execution using live or example RTB responses
Clear output panels for execution results
Validation and error reporting to help catch mistakes immediately
Secure Execution Environment
Your code runs inside a hardened sandbox with:
No external network access
No timers, async functions, or Node.js APIs
Automatic fallback to the original response on error
Strict performance and safety limits

Why This Matters
This enhancement gives Moja customers the ability to implement complex business logic without engineering involvement. It enables:
Faster setup for multi-buyer RTB workflows
More accurate and consistent routing decisions
Tailored transformations based on each buyer’s unique response structure
Power-user flexibility for advanced routing strategies
Campaign operators can now move significantly faster while maintaining reliability and full control.

Example Use Cases
Here are a few practical ways teams can use RTB JavaScript Response Processing:

  1. Conditional Routing Based on Bid Value
    if (response.bid_amount > 5) {
    response.route_priority = "premium";
    }
    return response;

  2. Normalizing Buyer Responses
    response.normalized_payout = Number(response.payout) || 0;
    return response;

  3. Filtering Available Offers
    return response.offers.filter(o => o.active);

  4. Array Transformation for Next Steps
    response.offers = response.offers.sort((a, b) => b.payout - a.payout);
    return response;

Getting Started

  1. Open an RTB
    Navigate to Routing → RTBs and select your desired RTB.

  2. Select a Step
    Pick the step whose API response you want to customize.

  3. Open “Process Response (JavaScript)”
    Scroll to the code editor within the step configuration.

  4. Test Your Script
    Run your JavaScript against:
    A real test RTB call
    A sample response you paste in
    You’ll see:
    Execution output
    Validation results
    Any errors in your script

  5. Save & Apply
    Once validated, save the change.
    Your script will now automatically run during every RTB execution.

Did this answer your question?