I recently came across the amp-ad-custom format. But there is not much documentation. If I understand correctly, the amp-ad-custom tag can be used to manage a custom ad network on a website, leveraging the speed capabilities of the AMP standard. By reading the documentation. I tried the following:
I need an endpoint that would be the ad server placed directly in the amp-ad-custom tag. If my server is https://example.site/ad-server/, it would look something like this:
<amp-ad-custom width="300" height="250" src="https://example.site/ad-server/">
This same https://example.site/ad-server/ should respond with JSON containing the configurations and path to a valid AMP4ADS ad page. It should also include the required headers. Here's an example of the ad server response:
Example PHP header:
$origin = origin_validator();
header("Access-Control-Allow-Origin: $origin");
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin, AMP-Access-Control-Allow-Source-Origin, amp-ad-response-type, AMP-Ad-Template-Extension");
header("AMP-Access-Control-Allow-Source-Origin: $origin");
header("AMP-Ad-Response-Type: template");
header("AMP-Ad-Template-Extension: amp-mustache");
header("Content-Type: application/json; charset=utf-8");
Response from the page with the URL of the AMP4ADS ad page:
{ "data": { "impression_id": "c9996325e618c7726496dc1eb79a23d7"},"templateUrl": "https:\/\/example.site\/ad-server\/ad\/lanka.php" }
Example of the ad page that the server points to, and its content, which is considered valid by the AMP4ADS validator:
<!doctype html>
<html ⚡4ads>
<head>
<!-- content -->
</head>
<body>
<div>Ad template example</div>
<template type="amp-mustache">
<amp-img src="https://validator.example.site/logo-blue.svg" width="250px" height="150px" layout="responsive"></amp-img>
</template>
<amp-img src="https://validator.example.site/logo-blue.svg" width="250px" height="150px" layout="responsive"></amp-img>
<amp-analytics type="googleanalytics"></amp-analytics>
</body>
</html>
When checking the page where I install the <amp-ad-custom> tag, it makes a request to the ad server at https://example.site/ad-server/, which shows the URL of the ad page. After that, it seems to attempt to load the cached version directly from the AMP cache servers, which returns a 404 error:
https://example-site.cdn.ampproject.org/ad/s/example.site/ad-server/ad/lanka.php
I want to know why AMP doesn't cache the ad and it doesn't load. Is this available to everyone, or just big advertising companies?