Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Overview

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

...

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

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

...

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.

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

If there are specific pages where only a subset of the ads are shown, it is important to declare the ad tags , that are used in on the current page. If ad tags are not properly 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.

...

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

Code Block
breakoutModewide
<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>

...

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

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

  • If Google Analytics is used, place the AdEngine tag after the Google Analytics tag

  • 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.

Code Block
breakoutModewide
languagephp
<?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>
Image Added

Body codes

The page body needs to define div elements that will 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. To reserve the proper space please 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:

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

Note:

  • If there are existing div elements that should need to be reused, provide the information to your account manager.

...

  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, or ; if it can't be avoided, place them in exclude from minify and cache section.

  3. Clear cache - both server and CDN to have a real overview if the implementation is correct and is not causing any issues. It's often when this step is missed; an issue is visible only days or weeks after implementation.

How to run an A/B test on WordPress

A/B test on WordPress between AdEngine and, in this example, AdSense. An A/B test - in this case, 50%/50% requires a decision in the header on which script should be injected. The Body, to make the test easier, should contain both tags. This is just an example of how the A/B test 50/50 could be executed in such a situation.

Code Block
breakoutModewide
languagejs
<script type="text/javascript">
        function appendScript(url){
            var head = document.getElementsByTagName('head')[0];
            var script = document.createElement('script');
            script.type = 'text/javascript';
            script.setAttribute('async', 'async');
			script.setAttribute('data-cfasync', 'false');
            script.src = url;
            head.appendChild(script);
        }
        if (Math.random() >= 0.5) {
            appendScript('https://cdn.snigelweb.com/adengine/**domain.com**/loader.js');
        } else {
			appendScript('https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js');
        }
    </script>

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 pubConfig 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.

Code Block
breakoutModewide
languagejs
<script data-cfasync="false" type="text/javascript">

    <?php if(plugin_hasMembershipLevel(array('1','2'))) { ?>
		  
	  window.snigelPubConf = {
        "adengine": {
          "activeAdUnits": ["incontent_1","sidebar_1","sidebar_2"]
        }
      }
    <?php } else { ?>
      window.snigelPubConf = {
        "adengine": {
          "activeAdUnits": ["incontent_1","incontent_2","sidebar_1","sidebar_2","sidebar_3"]
        }
      }
    <?php } ?>
</script>
<script async data-cfasync="false" src="https://cdn.snigelweb.com/adengine/**domain.com**/loader.js" type="text/javascript"></script>

(info) 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.

Anchor
Cache
Cache
Cache and Minify Plugins

While very useful, multiple WP plugins used for code optimization can create a lot of many problems with ad stack performance and implementation.

...