Skip to content

lmonk72/revive_ads

Repository files navigation

Revive Ads

A Drupal 10 module that integrates Revive Adserver into Drupal's block layout system. Each configured ad zone becomes an independently placeable block, with server-side campaign detection and a developer mode for local layout work.

Requirements

  • Drupal 10
  • Drupal core block module
  • A running Revive Adserver instance (only required in production mode)

Installation

  1. Place this module in web/modules/custom/revive_ads/.
  2. Enable it: drush en revive_ads (or via Extend).
  3. Visit Admin > Configuration > Web services > Revive Ads (/admin/config/services/revive-ads) to configure.

Configuration

Server settings

Setting Description
Revive server URL Base URL of your Revive instance, e.g. https://ads.example.com. No trailing slash.
Zone status cache lifetime How long (5 min – 4 hours) each zone's active/empty result is cached before re-checking Revive.

Developer mode

Enable Developer mode to bypass all Revive requests. Each ad block renders a local SVG placeholder instead of making HTTP calls. Use this on local and staging environments.

When developer mode is on, blocks always render regardless of whether a campaign is active — so skyscraper detection and layout work correctly without a live ad server.

Ad zones

Each zone row creates one placeable block in Drupal's block layout UI (Admin > Structure > Block layout).

Column Description
Block title Display name shown in the block layout UI.
Zone ID Numeric zone ID from your Revive Adserver.
Dev placeholder SVG image shown when developer mode is active.

Drag rows by their handle to reorder zones. The order is cosmetic only (for the admin form) — it does not affect front-end rendering.

Adding a custom placeholder: Drop any .svg file into images/placeholders/ and clear caches. It will appear automatically in the dev placeholder select.

Pre-configured zones

The module ships with nine default zones that match a standard news site layout:

Block title Zone ID Placeholder
Left Skyscraper 19 Skyscraper
Right Skyscraper 20 Skyscraper
MPU One 2 MPU
MPU Two 4 MPU
MPU Three 6 MPU
Leaderboard One 22 Leaderboard
Leaderboard Two 29 Leaderboard
Large Banner (set your zone ID) Large Banner
Standard Banner (set your zone ID) Standard Banner

How it works

  • Block derivation — The deriver (ReviveAdBlockDeriver) reads revive_ads.settings and creates one block plugin derivative per zone. Derivatives are rebuilt on cache clear.
  • Zone checkingReviveZoneChecker makes a server-side GET request to Revive's asyncspc.php endpoint and checks whether the response contains any ad HTML. Results are cached per zone for the configured TTL. On any HTTP error the service fails open (returns true) so a Revive outage never collapses the layout.
  • Rendering — In production, blocks output an <ins> tag and the Revive async JS. In developer mode, blocks render a local SVG placeholder.

Running tests

# Kernel tests (fast, no browser)
ddev drush php:script --script-path=. -- phpunit web/modules/custom/revive_ads/tests/src/Kernel

# Functional tests (requires a site install)
ddev exec ./vendor/bin/phpunit web/modules/custom/revive_ads/tests/src/Functional

Or from the project root via PHPUnit directly:

ddev exec ./vendor/bin/phpunit --group revive_ads

File structure

revive_ads/
├── config/
│   ├── install/revive_ads.settings.yml   # Default config (zones, server URL, etc.)
│   └── schema/revive_ads.schema.yml      # Config schema
├── images/placeholders/                  # SVG placeholder images for developer mode
├── js/revive-callback.js                 # Handles the Revive ad-empty callback
├── src/
│   ├── Form/ReviveAdsSettingsForm.php    # Admin settings form
│   ├── Plugin/Block/ReviveAdBlock.php    # Block plugin
│   ├── Plugin/Deriver/ReviveAdBlockDeriver.php
│   └── Service/ReviveZoneChecker.php    # Zone active-campaign checker
├── templates/revive-ad-block.html.twig
└── tests/
    ├── src/Functional/ReviveAdsSettingsFormTest.php
    └── src/Kernel/
        ├── ReviveAdBlockDeriverTest.php
        └── ReviveZoneCheckerTest.php

About

A Drupal 10 module that integrates Revive Adserver into Drupal's block layout system. Each configured ad zone becomes an independently placeable block, with server-side campaign detection and a developer mode for local layout work.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors