Partially deprecated
This article refers to an old implementation, in most cases new ad servers must be implemented following the Ad Server Providers standard.
More information: Using an ad server provider.
# Create an ad server extension
WARNING
Creating a custom extension for a single tenant should stay an exceptional use case. Custom ad servers do not benefit from the speed of chunked ads and don't work on all platforms.
If an ad server is not supported by Marfeel core, you can create a new implementation. If it's the first occurrence of this ad server at Marfeel, create the extension in the site code repository as a custom ad server. Otherwise, implement the extension in Marfeel core to be available by default.
You can research if this ad server already has a custom implementation via Github with this search URL, replacing ${AD_SERVER_NAME}
with the one you're looking for.
https://github.com/search?q=org%3AMarfeel+filename%3Ainventory+extension%3Ajson+${AD_SERVER_NAME}&type=Code
For example for adOcean: https://github.com/search?q=org%3AMarfeel+filename%3Ainventory+extension%3Ajson+adOcean&type=Code (opens new window)
# Custom ad server
WARNING
Custom ad servers are not compatible with AMP. This is not an implementation choice from Marfeel, AMP pages don't support custom javascript.
WARNING
In order to compile the custom implementation, in the JS folder you need to have the main.js, main.s.js and main.xl.js files
- Write a Javascript class with all the required behavior, following the ad server's implementation guidelines.
The file must be in under src/js/features/adservers/
in the site code repository.
You can extend the AdServer
core class or, if it doesn't fit your needs, write everything from scratch.
- Reference the ad server you created in the
inventory.json
file:
{
"placements": {},
"adServers": {
"awesomeCustomAdServer": {
"type": "custom",
"file": "awesomeCustomAdServer",
"json": {
"id": "12345677890048484820228.q7",
"mode": "old",
"preview":"123456789abced.E7"
}
}
}
}
- In
adServers
, the key property is the name under which the ad server is registered. - The
file
property points to the file name. The whole path and extension are automatically added, in this case, it will be:src/js/features/adservers/awesomeCustomAdServer.js
- The content of the
json
object will be passed to thebuildFromJson
static method.
TIP
Find the complete list of available attributes for a custom ad server in the custom ad server json schema (opens new window).
# Recommended methods
It is recommended to extend the AdServer
class and to override the following methods:
import AdServer from 'marfeel/touch/adservers/AdServer';
class AwesomeCustomAdServer extends AdServer {
constructor();
loadMad();
buildFromJson();
destroyMad();
}
constructor
is where you initialize everything the ad server will need to load: library loading, class attributes...loadMad
is the function that loads the ad depending on the parameters received. It contains the implementation details of the ad server to load ads, depending on slots and possible targeting. The logic may be directly referred to within this context or passed on to an external template to be loaded within an iframe.
It receives the following arguments:
madId
sectionId
madType
htmlNode
platform
layout
virtualPage
customClass
level
The method doesn't return anything, but should call Mad.madLoaded(madId, madAvailable, sold)
as a callback once all the logic executed.
madAvailable
istrue
unless you want to completely abort loading ads for this placementsold
istrue
if an impression is loading,false
otherwise.buildFromJson
receives as parameters everything set in theinventory.json
and must return a new instance of theAdServer
.
static buildFromJson({ json }) {
const { id, mode, preview } = json || {};
return new AwesomeCustomAdServer(id, mode, preview);
}
WARNING
Every placement on a page executes buildFromJson
, so a custom ad server must be created as a Singleton.
destroyMad
is an optional function, which should contain code to destroy an ad slot.
# Example of a custom ad server implementation
- ziaruldeiasi.ro's implementation of AdOcean (opens new window)
- upworthy.com's implementation of Teads TV (opens new window)
# Promote a custom ad server to Marfeel Core
Deprecated
It is not possible anymore to promote custom ad servers to Marfeel Core.
You must create a new Ad server provider and create an adapter. See the usage guide.
# Update an existing Core ad server
Deprecated
It is not possible anymore to update existing core ad servers.
You must create a new Ad server provider and create an adapter. See the usage guide.