DFP ads integration
This tutorial was contributed by Sanjeev Kumar G and Phaneendra
Steps to enable the ad:
- Open BlackKnight.
- Click on the config files and check for the
/app/config/ads.yml
file. If the file is not present, add the file. - Add the following key and respective values.
Sample /app/config/ads.yml
config file -
dfp_ads:
load_ads_synchronously: false
enable_ads: true
enable_lazy_load_ads: true
fetch_margin_percent: 0
render_margin_percent: 0
mobile_scaling: 0
delay_ad_script: 5.0
delay_ad_load: 5.0
network_id: "xxxxxxxxxx"
slots:
top_ad:
ad_unit: "/xxxxxxxxxx/BannerAd"
sizes: [[728, 90], [320, 50]]
view_port_size_mapping:
- viewport: [728, 0]
sizes: [[728, 90]]
- viewport: [0, 0]
sizes: [[320, 50]]
listing_page_ads:
ad_unit: "/xxxxxxxxxx/ListingPageAd"
sizes: [[728, 90], [300, 250]]
view_port_size_mapping:
- viewport: [728, 0]
sizes: [[728, 90]]
- viewport: [0, 0]
sizes: [[300, 250]]
story_page_ads:
ad_unit: "/xxxxxxxxxx/ScrollAdUnit"
sizes: [[728, 90], [300, 250]]
view_port_size_mapping:
- viewport: [728, 0]
sizes: [[728, 90]]
- viewport: [0, 0]
sizes: [[300, 250]]
Key | Type | Description |
---|---|---|
dfp_ads | object | Contain keys related to ads |
enable_ads | boolean | Toggle for enabling ads on the site |
load_ads_synchronously | boolean | Toggle for loading ads synchronously or asynchronously on the site |
delay_ad_script | number | Delays the ads script to reduce the impact of third party code which affects the page speed score. This arbitrary number might change depending upon the script parsing and the page rendering. |
delay_ad_load | number | Delays the DfpSlot |
enable_lazy_load_ads | boolean | Toggle for enabling lazy loading the ads on the site |
fetch_margin_percent | number | It fetches slots within specified viewports |
render_margin_percent | number | It renders slots within specified viewports |
mobile_scaling | number | It multiplies the specified value with the above values for mobile |
network_id | number | DFP network id |
slots | object | Contain all the ad units required for the site |
Slots
This object contains ad units with respective sizes.
Key | Description |
---|---|
top_ad | Key required to get the ad config related to the top ad. |
ad_unit | It is the dfp network id followed by inventory name. |
sizes | Sizes of respective inventory. |
view_port_size_mapping | Used to map the ad unit based on the viewport. In the above sample config of top_ad , the ad unit of size 728x90 is served on viewport above 728 pixels and the ad unit of size 320x50 is served on viewport between 0 pixels to 728. |
Loading Ads Asynchronously or Synchronously
-
If load_ads_synchronously is
false
: it will be loading the script related to ads on the frontend with a delay of few seconds. Here, the ads will not be loaded on the initial page load, so there will be no impact on site performance. -
If load_ads_synchronously is
true
: it will be loading the script related to ads on the initial page render and this will impact the site performance.
Lazy Loading
Lazy loading enables pages to load faster, reduces resource consumption and contention, and improves view-ability rate by pausing the requesting and rendering of ads until they approach the user’s viewport.
Sample code -
googletag.pubads().enableLazyLoad({
fetchMarginPercent: fetch_margin_percent , ( If fetch_margin_percent is 500, fetch slots within 5 viewports )
renderMarginPercent: render_margin_percent, ( If render_margin_percent is 200, render slots within 2 viewports )
mobileScaling: mobile_scaling ( If mobile_scaling is 2.0, it doubles the above values on mobile, where viewports are smaller and users tend to scroll faster )
});
The values for the above parameters fetch_margin_percent
, render_margin_percent
and mobile_scaling
, by default is 0
.
Key-Value Pairing
Key-values can be used to target ads more granularly than ad units.
For each ad request, you may pass one or more keys, each with one or more associated values. These key-values will be evaluated against targeting options configured at the line item-level in Ad Manager. For example, if you pass a custom key-value of pageType="home-page"
, line items targeted to the pageType, home-page
will be eligible to serve.
Sample code -
googletag.cmd.push(function() {
const responsiveAdSlot = googletag.defineSlot(path, size, id);
if (responsiveAdSlot) {
responsiveAdSlot
.addService(googletag.pubads())
.setTargeting("pageType", pageType)
.setTargeting("environment", environment)
.setTargeting("sectionSlug", sectionSlug)
.setTargeting("sectionId", sectionId)
.setTargeting("storyId", storyId)
.setTargeting("sectionList", sectionList)
.setTargeting("tagList", tagList);
}
})
Responsive ads
Responsive ads extend multi-size ads and allow you to specify the size of the creatives to serve based on the size of the viewport of the browser making the request. This functionality can be used to control the size of creatives served to different types of devices (desktop, tablet, mobile, etc.).
This is accomplished by defining a mapping between viewport size and ad size, then associating that mapping with an ad slot.
var mapping =
googletag.sizeMapping()
.addSize([1024, 768], [[750, 200], [728, 90]])
.addSize([640, 480], [300, 250])
.addSize([0, 0], [])
.build();
responsiveAdSlot.defineSizeMapping(mapping);
In the above sample code, the mapping specifies:
- When viewport >= 1024x768, ads sized 750x200 or 728x90 may serve.
- When 1024x768 > viewport >= 640x480, ads sized 300x250 may serve.
- When viewport < 640x480, no ads will serve.
Ad Units
Top Ad ( top_ad )
- This ad shows up at the top of every page. Which looks like below on the Home page -
Listing Page Ads ( listing_page_ads )
- These Ads will be displayed after each collection on all listing pages.
Story Page Ads ( story_page_ads )
- This Ad will be displayed after the first card in a story.
For more info on DFP Ads implementation check here
Google Ad Manager
Terms
-
Network - Company representing multiple advertisers and agencies.
-
Advertiser - Advertising organization purchasing your site inventory.
-
Ad serving - The process by which DFP chooses the best ads to serve to an ad request, and then returns the corresponding creative code
-
Ad tag - HTML tags or JavaScript code generated and then included in the webpage or app source where the ads should be displayed.
-
Ad unit - Discrete spaces on your site for ads. You can define an ad unit on your site with a name, description, and dimensions.
-
Company - An advertiser, agency, or organization that buys ad space and supplies the creatives for line items. Each order is associated with a company, and you can invite company contacts to view reports about their campaigns.
-
Creative - A code snippet, file, or link that generates an ad. (The terms creative and ad may be used interchangeably.) DFP supports a variety of creative types, including Third-party, Image, DoubleClick tag, and DoubleClick Rich Media.
-
Creative assignment - Type of assignment used to specify characteristics of how the creative is served, such as the click-through URL, the position of the creative in a sequential rotation, and so on.
-
Creative association - The assignment of one or more creatives to a line item.
-
Creative rotation - The technique by which multiple creatives assigned to a line item are displayed, either evenly, weighted, sequential, or optimized.
-
Line item - An advertiser’s commitment to purchase a specific number of ad impressions (CPM), user clicks (CPC), or time (CPD), on certain dates at a specified price. A line item specifies where an advertiser’s ads will appear and may specify when an ad may be shown.
-
Order/Campaigns - An agreement between an interactive advertising seller and a buyer that specifies the details of an advertising campaign. Orders contain one or more line items.
Let’s see how to create ad units, orders, line items, and add creatives for the line items for the creative to get displayed on the pages. An ad-unit is just a space that doesn’t start to serve immediately after it’s created. An order needs to be created which should have a line item, and the creatives for the ad to start delivering.
How to create an ad-unit in Google Ad manager?
ad-units are a part of the inventory section of the Ad Manager.
- Click on the dropdown for inventory and click on Ad units.
- Click on the new ad unit.
.
- Choose the parent ad unit as
Top Level
, enter the details and save.
How to create an order for an ad-unit?
-
Orders are a part of the delivery section of the ad manager.
-
Click on the delivery dropdown and click on orders.
.
- Click on
New order
, enter the details and click onSave
.
- Once saved, the line item needs to be added to the created order.
How to create a line item for the created order?
- Click on the new line item button and the ad type window would be shown.
.
- Click on
Select Display Ad
and enter the details.
.
- Scroll down to the targeting part and choose the ad-unit that needs to be targeted from the inventory, add any custom targeting if any, and click on
Save
.
.
- Once Saved after entering all the details, creatives need to be added.
How to add creatives to the line items?
- Click on
Manage Creatives
on the right-hand corner.
.
- Click on
Add Creatives
orBulk Upload Creatives
and choose the appropriate creatives of the respective sizes.
.
-
Once the creatives are uploaded, click on continue.
-
Set the destination URL.
.
-
Click on
Done
and save. -
The order needs to be approved.
-
Click on the created order, select the line item and click on
Approve
.
.
The ads start to render once the status of the line items become Delivering
.
The rendering of ads can be verified from the URL.
https://pubads.g.doubleclick.net/gampad/adx?iu=/{ad-manager-id}/{ad-unit-name}&sz={creative-size}&c=213123123&m=text/html&cust_params={custom-target}%3D{custom-target-type}
Parametres | Description |
---|---|
ad-manager-id | The account ID of the ad manager. |
ad-unit-name | The ad-unit. |
creative-size | the size of the creative to be displayed.Ex: 728x90, 320x50 |
c | Correlator (or, cache-busting) value. This must be a random number (letters are not permitted) generated by a publisher to ensure a fresh call to the ad server happens each time the page loads to avoid impression-counting discrepancies. |
m | Mime-type value on the HTTP header. Ex: text/html |
custom-target | the target. Ex:pageType, sectionSlug etc. |
custom-target-type | the targeted page. Ex: home-page, section-page, {section-slug} etc |
There could be other targeting parameters as well. The URL needs to be appended with &
other targeting parameters that can be added.
Ex: https://pubads.g.doubleclick.net/gampad/adx?iu=/{ad-manager-id}/{ad-unit-name}&sz={creative-size}&c=213123123&m=text/html&cust_params={custom-target}%3D{custom-target-type}&{custom-target}%3D{custom-target-type}
More documentation on the URL.
https://support.google.com/admanager/answer/2623168?hl=en#optional-parameters.
https://support.google.com/admanager/answer/2623168?hl=en#required-parameters.