@frontity/smart-adserver
API reference of `@frontity/smart-adserver` package
Smart Adserver is an ad serving network and they provide an API for displaying the ads which is described here.
The @frontity/smart-adserver
package will load a third-party Smart Adserver library which adds certain properties on the global window
object. Then you as the developer can render the exposed <SmartAd>
component, which will use those properties to make the "ad call" (which are basically API calls to the Smart Adserver).
In response, the Smart Adserver dynamically loads some code which will modify the DOM to insert the ad in the place that the <SmartAd>
component was rendered.
The package has 3 main components:
The "Root" component. It includes the
<Head>
that loads the Smart Adserver library. When the user adds the@frontity/smart-adserver
to theirfrontity.settings.js
file, this library will be loaded automatically.The
SmartAd
component. This component is exposed inlibraries.fills.SmartAdserver.SmartAd
. The users can just use this component directly to display ads by passing it relevant props. The component takes care of calling the Smart Adserver API and injecting the ad into the DOM in the relevant placeAbility to specify the ads in
fills
in thefrontity.settings.js
file. Ads can be placed in specific slots in a theme by using that approach.
Table of Contents
Installation
The package can be installed like:
Settings
This package can be included in your frontity.settings.js
file as one of the packages that will be part of your Frontity project.
The namespace for this package is smartAdserver
. To use the Slot and Fill pattern with this package we should add a settings object to state.fills
under the smartAdserver
namespace.
Each fill in the smartAdserver
namespace is an object which should be assigned to an arbitrarily named key. The structure should be as follows:
Object properties
To define a SmartAd using the Slot & Fills pattern we use the standard FilL properties
The props
property
props
propertyAn object with props that will be passed to the <Slot>
component.
Examples
Usage
Using the Slot & Fill
pattern
Slot & Fill
patternThe recommended usage of this component is using the Slot and Fill pattern. The configuration of the fill(s) is done in the state.fills.smartAdserver
namespace in frontity.settings.js
as explained above.
With this configuration we can then insert the Slots representing the Ads in any React component.
Using the Ad component directly
Alternatively, since the Ad component is exposed in libraries
, you can get the SmartAd
component from libraries
and render it wherever you wish.
Last updated