snapshotpl/zf-snap-google-adsense

There is no license information available for the latest version (1.0.1) of this package.

Google Adsense view helper for Zend Framework 2

1.0.1 2014-02-26 21:50 UTC

This package is auto-updated.

Last update: 2024-10-29 04:18:28 UTC


README

Google AdSense view helper for Zend Framework 2

Module helps to manage yours AdSense units on page. Keep them all in one place and use renderers!

The simplest usage

Add ad unit (one or more) and publisher ID (you can find it here) to your config:

return array(
  'zf-snap-google-adsense' => array(
    'publisher-id' => 'pub-1234567890123456',
    'ads' => array(
      'home-page' => array(
        'id' => 1234567890,
        'size' => '336x280',
      ),
    ),
  ),
);

And then render ad in your view by view helper. You can use googleAdsense or adsense name:

echo $this->adsense('home-page');

That's all! In default adsense use asynchronous code. You can change it by using predefined view renderers.

How to install?

Via composer.json

{
  "require": {
    "snapshotpl/zf-snap-google-adsense": "1.*"
  }
}

Renderers

You can use renderes (by implements ZfSnapGoogleAdSense\View\Helper\Renderer\RendererInterface) to render your ads. In default module provides simple view renderer with very useful views:

  • asynchronous (default): official asynchronous script,
  • synchronous: official synchronous script,
  • placeholdit: fake placeholer is using placehold.it service to generate image, perfect for dev or test eviroments, you can customize it, to details see config/module.config.php and overwrite options,
  • html: generates html div, perfect for dev or test eviroments, you can customize it, to details see config/module.config.php and overwrite options,

To add own view to view render create view (in view you can use ad property which it's instance of \ZfSnapGoogleAdSense\Model\AdUnit by default) add it to view_manager with prefix zf-snap-google-adsense-renderer-view-*:

return array(
  'view_manager' => array(
    'template_map' => array(
      'zf-snap-google-adsense-renderer-view-customview' => __DIR__ . '/my-awesome-custom-view.phtml',
    ),
  ),
);

To change current view renderer pass view name to renderer option:

return array(
  'zf-snap-google-adsense' => array(
    'renderer' => 'zf-snap-google-adsense-renderer-view-customview',
  ),
);

If you wrote your own renderer pass intance name from service_manager. You can also set custom parameters into view. To see how it works look into renderers array in config/module.config.php and view renderers source.

Options

ads defines ad units

  • id (required): Ad ID,
  • size (required): You can define size by string or array,
  • type: content and link. Content unit is default. You can use constats or strings,
  • name: It's used in custom renderes (placeholdit and html). If name is not defined, ad gets name by key name,
return array(
  'zf-snap-google-adsense' => array(
    'ads' => array(
      'link-ad-by-constat' => array(
        'id' => 1234567890,
        'size' => '336x280',
        'type' => \ZfSnapGoogleAdSense\Model\AdUnit::TYPE_LINK,
      ),
      'link-ad-by-string' => array(
        'id' => 1234567890,
        'size' => array(
          'width' => 336,
          'height' => 280,
        ),
        'type' => 'link',
      ),
      'content-ad' => array(
        'id' => 1234567890,
        'size' => '336x280',
        'type' => \ZfSnapGoogleAdSense\Model\AdUnit::TYPE_CONTENT,
        'name' => 'Content ad under header',
      ),
    ),
  ),
);

enable if equals false, than disable ads on page.

return array(
  'zf-snap-google-adsense' => array(
    'enable' => false,
  ),
);

publisher-id (required) publisher ID - you can find it here

unit-limit limits ads on page. Default values:

return array(
  'zf-snap-google-adsense' => array(
    'unit-limit' => array(
      AdUnit::TYPE_CONTENT => 3,
      AdUnit::TYPE_LINK => 3,
    ),
  ),
);