AdEngine with WordPress

Overview

WordPress is one of many publishers' most commonly used content management systems. AdEngine integration works with WordPress as seamlessly as with any other web page. However, some known issues can be avoided due to the use of plugins. Following those simple guidelines will help with smooth implementation.

AdEngine implementation

AdEngine implementation in WordPress should be done directly in page codes for the best effectiveness. In the header and body, plugins are allowed; however, please notice the possible limitations listed below.

This integration guide applies if all ads are delivered by Snigel on a site with a simple page layout.

For this integration guide, we assume the example of a website with the following two ads on every page:

  • "Top Leaderboard"

    • ad-unit-name: topleaderboard

    • div-name: adngin-topleaderboard-0

  • "Sidebar"

    • ad-unit-name: sidebar

    • div-name: adngin-sidebar-0

Header code

The head section modifications are the fundamental part of the integration. Without adding the AdEngine script and configuration to the head, the ads won't render.

As outlined below, a few code tags need to be implemented to have an optimized and effective setup to bid on the site.

If there are specific pages where only a subset of the ads are shown, it is important to declare the ad tags used on the current page. If ad tags are not correctly declared, ad units will be auctioned, even if not used. This will lead to false ad impressions, negatively affecting page performance and user experience.
You can declare ad units using the snigelPubConf element.

Please remember:

  • ad-unit-name: topleaderboard

  • div-name: adngin-topleaderboard-0

The following example assumes that a page has the Top Leaderboard and Sidebar. Create the following tags in the <head> element of the page:

<script data-cfasync="false" type="text/javascript"> window.snigelPubConf = { "adengine": { "activeAdUnits": ["topleaderboard","sidebar"] } } </script> <script data-cfasync="false" async src="https://cdn.snigelweb.com/adengine/**site.domain**/loader.js" type="text/javascript"></script>

Note:

  • Replace **site.domain** with the actual site domain

  • Place the script at the very top of the header to ensure the best possible performance

  • Keep the correct order of the tags: first configuration and then loading of AdEngine

 

Header edition in WordPress

Most WordPress plugins don’t allow editing of a header - only allowing to inject code into the body.

It’s required to edit WordPress template files to update the header.php file and enter the AdEngine code. It should be added just before closing the head element using the template editor.

If you use standard themes, please remember that an automatic update can change the main files. It’s recommended to use edit and use child themes instead.

 

<?php wp_head(); ?> <script data-cfasync="false" type="text/javascript"> window.snigelPubConf = { "adengine": { "activeAdUnits": ["topleaderboard","sidebar"] } } </script> <script data-cfasync="false" async src="https://cdn.snigelweb.com/adengine/**site.domain**/loader.js" type="text/javascript"></script> </head>

Body codes

 

The page body needs to define div elements to be filled with ads. They need to be placed where the ad should be displayed.
The div elements should reserve the maximum width and height of the displayed ad to prevent Cumulative Layout Shift (CLS). If you are using ad labeling, reserve an additional 15px of height for the label. Please consult your account manager to get the exact ad sizes to reserve the proper space.

For each div element name provided by your account manager, create tags like in the example:

<div id="adngin-topleaderboard-0"></div> <div id="adngin-sidebar-0"></div>

Note:

  • If div elements need to be reused, provide the information to your account manager.

Keep in mind when implementing AdEngine in WordPress

  1. Ensure that both codes for snigelPubConf and loader.js have the elements:

    • data-cfasync="false"

    • async

  2. Do not place scripts from Snigel in minify and cache plugins; if it can't be avoided, place them in exclude from minify and cache section.

  3. Clear the cache on both the server and CDN to get an accurate view of whether the implementation is correct and not causing any issues. When this step is missed, problems often only become apparent days or even weeks after implementation.

How to run an A/B test on WordPress

An A/B test on WordPress between AdEngine and AdSense, for example, requires a 50/50 traffic split. The decision on which script to inject should be made in the <header>, while the <body> can include both tags to simplify the test. This is just one approach for executing a 50/50 A/B test in this scenario.

 

Is it possible to condition if AdEngine works depending on my plugin settings?

 

It’s possible to condition how AdEngine will be called - using pubConfig. If a specific plugin gives the possibility to read the settings from the PHP level, it can allow steering the snigelPubConf elements.

 

For example, Plugin to manage Memberships - can have functions that allow checking membership levels. In this example, we want to show a limited amount of ads to users with specific membership levels and all ads to other members.

Settings for membership level and used function depend on the plugin - please read your plugin documentation for the correct elements.

 

Using WordPress functions can help to manage the display of ads depending on different conditions like page template, category, etc. Please read WordPress documentation for the correct functions.

 

Limitations of Cache and Minify Optimization Plugins

Minification Plugins
Minification plugins scan your page content and combine all JavaScript (JS) and CSS files, often disregarding their order or dependencies. After merging, they inject the code into the page and compress it. This process can disrupt the functionality of several elements, particularly the ad stack loader.

Caching Plugins
Caching plugins store old versions of scripts. When updates or fixes are made, the new versions may not load correctly, causing the fixes to be ineffective.

Common Issues Caused by These Plugins

  • Ads stop displaying.

  • CMP (Consent Management Platform) is called multiple times.

  • Scripts stop functioning entirely.

  • Negative impact on A/B testing with various partners.

  • Changes are not reflected due to old scripts being cached.

To avoid these issues, it’s recommended to exclude Snigel ad scripts from optimization in your plugin settings. Below are instructions for popular plugins:

Plugin-Specific Exclusion Instructions

Autoptimize
Autoptimize Plugin

  • Exclude CSS and JS from aggregation and minification by adding them to the comma-separated exclusion list.

Async JavaScript
Async JavaScript Plugin

  • Skip specific CSS and JS code by adding theim to Async JavaScript > Settings > Script Exclusion.

Breeze
Breeze Plugin

  • Exclude JS from optimization under Breeze > File Optimization > JS Settings. Ensure that JS Minify is disabled.

Debloat
Debloat Plugin

  • Exclude CSS: Go to Debloat > Optimize CSS > Exclude Styles and add the CSS exclusions.

  • Exclude JS: Go to Debloat > Optimize JS > Exclude Scripts and add the necessary scripts.

Flying Scripts
Flying Scripts Plugin

  • Navigate to Flying Scripts > Settings > Include Keywords, and ensure that keywords such as "snigelweb," "adengine," "loader.js," or any others that reference the scripts needing exclusion are not listed.

NitroPack
NitroPack Plugin

  • Go to Exclusions > Excluded Resources and add the scripts that need to be excluded.

Perfmatters
Perfmatters Plugin

  • Add scripts to the exclusion list under Perfmatters > Assets > JavaScript > Exclude for Deferral and Perfmatters > Assets > JavaScript > Excluded from Delay.

RocketLauncher
RocketLauncher Guide

  • Ensure scripts are excluded by adding the attribute data-cfasync="false" to your scripts, e.g., <script data-cfasync="false" src="/javascript.js"></script>.

WP Fastest Cache
WP Fastest Cache Plugin

  • Navigate to WP Fastest Cache > Exclude > Exclude JS and add the scripts to the exclusion list.

WP Rocket
WP Rocket Plugin

  • Go to WP Rocket > File Optimization > JavaScript Files > Excluded JavaScript Files and add the necessary scripts.

W3 Total Cache
W3 Total Cache Plugin

  • By default, W3 Total Cache does not cache external scripts. However, if files are being minified, go to Performance > Minify > Advanced > Never Minify following JS files and add the required exclusions.