rtCamp / amp-admanager

Easy and hassle free Google Admanager amp-ad tags integration for all WordPress sites. (AMP and Non-AMP)
5 stars 3 forks source link
admanager amp amp-ad google-admanager research-development wordpress wp-plugin

AMP AdManager 1.0.0

Project Status: Active – The project has reached a stable, usable state and is being actively developed.

AMP ads for all WordPress sites (AMP and Non-AMP). This plugin generates <amp-ad> code for your ads with breakpoints for responsive display of ad with Single Request Architecture (SRA). Works without AMP plugin as well for Non-AMP pages.

Contributors: rtCamp, Vishal Dodiya, Pradeep Sonawane, Sagar Nasit

Tags: amp, mobile Requires at least: 4.9
Tested up to: 5.1
License: GPLv2 or later
Requires PHP: 5.4+

Setup

  1. Set network/publisher id in the plugin settings. Dashboard > AMP AdManager
  2. Select Load AMP Resources for Non-AMP site to load amp-runtime and amp-boilerplate css.

Usage

Pass different ad sizes as attributes for mobile, tablet, and desktop ads. The plugin uses the width of the specified size to determine which device ad should be displayed.

  1. Width equal to or more than 728 will be considered as desktop sizes eg. 980x250,970x90.
  2. Width between 300 and 600 will be considered as a tablet sizes eg.320x50,300x100,468x60.
  3. Width less than 300 will be considered as mobile sizes eg. 250x50,150x150.

In case of unusual sizes for desktop, tablet and mobile specific device size attribute, like

As Shortcode

[ampad ad-unit="<ad-unit-name>"
sizes="320x50,300x100,300x50,468x60,980x250,970x90"
custom-targeting="key1:value1, key2:value2" ad-refresh="30"]
Custom sizes attributes example
[ampad ad-unit="<ad-unit-name>"
desktop-sizes="320x100,300x100"
tablet-sizes="468x60,300x100"
mobile-sizes="300x100,320x50"
custom-targeting="key1:value1, key2:value2"]
Custom sizes example sizes with sizes attribute
[ampad ad-unit="<ad-unit-name>"
sizes="300x100,320x50,910x150"
desktop-sizes="320x100,300x100"
custom-targeting="key1:value1, key2:value2"]

sizes attribute and custom sizes attrubutes can be used simutanously where custom sizes attributes overtake sizes attribute.

In above example 300x100 and 320x50 are for tablet and 910x150 is for desktop as per caculation on width. But since we defined desktop-sizes as well, it will override previous desktop size of 910x150 and new desktop sizes will be 320x100 and 300x100. Other sizes for mobile and tablet will remain intact as we have not specified custom sizes for mobile and tablet.

In Template

With sizes attribute example
$attr = [
    'ad-unit'   => '<ad-unit-name>',
    'sizes'     => '320x50,300x100,300x50,468x60,980x250,970x90',
    'layout'    => 'responsive',
    'custom-targeting' => 'key1:value1, key2:value2'
];

AMP_AdManager\AMP_AdManager::get_ads( $attr, true );
With custom or unusual sizes
$attr = [
    'ad-unit'           => '<ad-unit-name>',
    'mobile-sizes'      => '320x50,300x100',
    'tablet-sizes'      => '300x50,468x60',
    'dekstop-sizes'     => '980x250,970x90',
    'layout'            => 'responsive',
    'custom-targeting'  => 'key1:value1, key2:value2'
];

AMP_AdManager\AMP_AdManager::get_ads( $attr, true );
Parameters:
  1. $attr (Array) These are passed directly to the get_ads via template tag shown above or via shortcode.

    Default value: array

    [
        'network-id'       => '',
        'ad-unit'          => '',
        'mobile-sizes'     => '320x50,300x100', // consider for mobile
        'tablet-sizes'     => '300x50,468x60',  // consider for tablet
        'dekstop-sizes'    => '980x250,970x90', // consider for desktop
        'sizes'            => '320x50,300x50,468x60,980x250,970x90',
        'layout'           => 'fixed',
        'custom-targeting' => '',
        'ad-refresh'       => 30, // refresh ad every 30 seconf.
    ]
  2. $echo (Boolean) Outputs amp-ad tag if true, returns amp-ad html as value otherwise.

Notice:

Available targeting variables

Targeting Variable Description
author - post author username (string - lowercase)
contentType - type of content e.g homepage, listingpage, post, page, cpt-name (string - lowercase)
authorPage - archive author page name (string - lowercase)
categoryPage - archive category page name (string - lowercase)
tagPage - archive tag page name (string - lowercase)
postCategories - post categories list (array) ["cat1", "cat2"] (all lowercase - slugs)
postTags - post tags list (array) ["tag1", "tag2"] (all lowercase - slugs)
postName - post name slug (string - lowercase)
postId - post id (numeric)

Development Flow

Change Log

v1.0.0 (27-09-2019)

v0.9 (27-09-2019)

v0.8 (20-09-2019)

v0.7 (03-09-2019)

v0.6 (28-08-2019)

v0.5 (17-05-2019)

v0.4 (10-05-2019)

v0.3 (29-04-2019)

v0.2 (14-04-2019)

v0.1

Does this interest you?

Join us at rtCamp, we specialize in providing high performance enterprise WordPress solutions