Skip to main content

Display Ads (Banners)

Integrate banner advertisements into your platform.

How It Works

  1. Send request to API
  2. Receive JavaScript code
  3. Insert code into page container
  4. Banner renders automatically

Request Example

<?php
$placement_code = 'your_placement_id';
$token = 'your_api_key';
$user_id = get_user_id();

$data = [
'id' => 'banner_search_' . time(),
'container' => 'mageads-banner-container', // Container ID on page
'user' => [
'id' => $user_id
],
'site' => [
'page' => $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
'cat' => [],
'keyword' => 'buty'
],
'device' => [
'ua' => $_SERVER['HTTP_USER_AGENT'],
'ip' => $_SERVER['REMOTE_ADDR'],
'w' => 1920,
'h' => 1080
],
'bvendor' => [],
];

$ch = curl_init('https://delivery.mageads.com/products?pc=' . $placement_code);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 500);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $token
]);

$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
?>

Response

{
"id": "banner_search_12345",
"code": "<script>console.log(\"banner code\");</script>"
}

Implementation

1. Create Container

<div id="mageads-banner-container"></div>

2. Insert Code

<?php
if (!empty($result['code'])) {
echo $result['code'];
}
?>

The JavaScript code will automatically render the banner in the container.