How to make custom native IAB portrait ads
Portrait ads are vertical ads that have three expandable modules. The dimensions for a fixed size portrait ad is 300 x 1050. When the viewer clicks on one of the thumbnails, the ad expands to reveal the content, which can be another image, a gallery of images, a video, or other HTML content. You can use native templates to create IAB portrait ad items that are tailored to your needs.
If you'd rather sanitize the template and have only HTML inside it, you should make your portrait ad using a styled native ad template instead. For more information on the differences between custom native ads and styled native ads, read About native ad templates
You will learn:
- How to create a template for a custom portrait ad. You can customize the sample code to fit your needs.
- How to create a custom portrait ad item once you have a custom portrait template.
How to create a custom portrait ad template
This template will require the user to provide the URLs to where the image creatives are hosted when creating the portrait ad item. Our sample will contain only static images, but keep in mind that you can also put videos and other HTML content in each module. Define your variables accordingly based on the content that you want to have on each module.
- Click Native Ad Templates in the left navigation menu to go to the Templates section.
- Click Add Native Ad Template in the Native Ad Templates table. The New Native Template window will appear.
- Click Custom Rendering/API. The New Native Ad Template page will appear.
- Name the template then add an image URL variable for each image that will be in the ad: a logo, the ad creatives themselves, and the module backgrounds. In our sample code, we called the logo variable LogoURL. We called the ad creatives variables ImageURL, ImageURL2, and so on, up to ImageURL6. Finally, we called the module variables ModuleImageURL and ModuleImageURL2.
- Enter the code in the HTML Template (Custom Rendering) field, then click Save Changes.
Here's the code we used in our example:
<!DOCTYPE html>
<html lang="en">
<head>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<style>
.portrait-container {
box-sizing: border-box;
font-family: Arial;
position: relative;
width: 300px;
height: 1050px;
border: 1px solid #E5E5E5;
padding: 0 15px;
}
.portrait-container > * {
margin: 15px 0;
}
.portrait-logo {
height: 40px;
width: 270px;
}
.portrait-gallery-container {
height: fit-content;
}
.gallery-current-image-container {
position: relative;
}
.gallery-current-image {
height: 380px;
width: 270px;
margin: 15px 0;
background-repeat: no-repeat;
background-size: cover;
}
.expand-collapse-button {
position: absolute;
top: 5px;
left: 5px;
width: 28px;
height: 28px;
box-sizing: border-box;
cursor: pointer;
font-size: 16px;
color: black;
background: white;
border-radius: 28px;
display: flex;
align-items: center;
justify-content: center;
z-index: 2;
}
.collapse-button {
display: none;
}
.gallery {
height: 85px;
width: 270px;
display: grid;
grid-template-columns: repeat(3, auto);
align-items: center;
justify-content: space-between;
}
.gallery-groups-container {
height: 85px;
width: 220px;
position: relative;
overflow: hidden;
}
.gallery-group {
position: absolute;
top: 0;
width: 220px;
display: flex;
justify-content: space-around;
box-sizing: border-box;
transition: left 0.75s;
}
.gallery-group {
left: 0;
}
.gallery-group-2 {
left: 100%;
}
.gallery-image {
max-width: 60px;
min-height: 60px;
cursor: pointer;
}
.gallery-control-button {
font-size: 25px;
font-weight: 900;
color: black;
cursor: pointer;
transition: color 0.75s, background-color 0.75s;
border-radius: 5px;
}
.gallery-prev-button {
cursor: default;
color: grey;
padding: 0 5px;
}
.gallery-next-button {
padding: 0 5px;
}
.module {
width: 270px;
}
.module-image {
height: 225px;
width: 270px;
}
.portrait-close-button-container {
height: 16px;
position: absolute;
top: 0;
right: 0;
cursor: pointer;
margin: 0;
display: flex;
align-items: center;
}
.portrait-close-button {
width: 16px;
text-align: center;
display: inline-block;
color: #ffffff;
font-size: 14px;
background: #000000;
border-radius: 14px;
user-select: none;
}
</style>
</head>
<body>
<div class="portrait-container">
<div class="portrait-logo">
<img src="[%LogoURL%]">
</div>
<div class="portrait-gallery-container">
<div class="gallery-current-image-container">
<a target="_blank" href="[TRACKING_LINK]">
<div class="gallery-current-image"></div>
</a>
<div class="expand-collapse-button expand-button" onclick="expandImage()"><i class="fa fa-expand" aria-hidden="true"></i></div>
<div class="expand-collapse-button collapse-button" onclick="collapseImage()"><i class="fa fa-compress" aria-hidden="true"></i></div>
</div>
<div class="gallery">
<div class="gallery-control-button gallery-prev-button" onclick="showFirstGroup()">
<
</div>
<div class="gallery-groups-container">
<div class="gallery-group gallery-group-1">
<img class="gallery-image" src="[%ImageURL%]" onload="loadGalleryObject(this)" />
<img class="gallery-image" src="[%ImageURL2%]" onclick="loadGalleryObject(this)" />
<img class="gallery-image" src="[%ImageURL3%]" onclick="loadGalleryObject(this)" />
</div>
<div class="gallery-group gallery-group-2">
<img class="gallery-image" src="[%ImageURL4%]" onclick="loadGalleryObject(this)" />
<img class="gallery-image" src="[%ImageURL5%]" onclick="loadGalleryObject(this)" />
<img class="gallery-image" src="[%ImageURL6%]" onclick="loadGalleryObject(this)" />
</div>
</div>
<div class="gallery-control-button gallery-next-button" onclick="showSecondGroup()">
>
</div>
</div>
</div>
<div class="module">
<a target="_blank" href="[TRACKING_LINK]">
<img class="module-image" src="[%ModuleImageURL%]"/>
</a>
</div>
<div class="module">
<a target="_blank" href="[TRACKING_LINK]">
<img class="module-image" src="[%ModuleImageURL2%]"/>
</a>
</div>
<div class="portrait-close-button-container">
<span class="portrait-close-button" onclick="closeButton()">×</span>
</div>
</div>
<script>
function loadGalleryObject(tag) {
collapseImage();
var imageUrl = tag.getAttribute('src');
document.querySelector('.gallery-current-image').style['background-image'] = 'url(' + imageUrl + ')';
}
function expandImage() {
document.querySelector('.collapse-button').style.display = 'flex';
document.querySelector('.expand-button').style.display = 'none';
document.querySelector('.gallery-current-image').style.width = '460px';
}
function collapseImage() {
document.querySelector('.collapse-button').style.display = 'none';
document.querySelector('.expand-button').style.display = 'flex';
document.querySelector('.gallery-current-image').style.width = '270px';
}
function showFirstGroup() {
document.querySelector('.gallery-group-1').style.left = '0';
document.querySelector('.gallery-group-2').style.left = '100%';
document.querySelector('.gallery-prev-button').style.color = 'grey';
document.querySelector('.gallery-prev-button').style.cursor = 'default';
document.querySelector('.gallery-next-button').style.color = 'black';
document.querySelector('.gallery-next-button').style.cursor = 'pointer';
}
function showSecondGroup() {
document.querySelector('.gallery-group-1').style.left = '-100%';
document.querySelector('.gallery-group-2').style.left = '0';
document.querySelector('.gallery-prev-button').style.color = 'black';
document.querySelector('.gallery-prev-button').style.cursor = 'pointer';
document.querySelector('.gallery-next-button').style.color = 'grey';
document.querySelector('.gallery-next-button').style.cursor = 'default';
}
function closeButton() {
document.querySelector('.portrait-container').style.display = 'none';
}
</script>
</body>
</html>
You can now use this template to create a custom portrait ad item.
How to create a custom portrait ad item
- Go to the section of the relevant zone (Your AdButler > Publishers > Your Publisher > Your Zone) or campaign (Your AdButler > Advertisers > Your Advertiser > Your Campaign).
- Click Add Ad Item in the Ad Items table. The Add Ad Item window will appear.
- Click Native (Custom Rendering/API). The New Ad Item page will appear.
- Set the ad item's size to Dynamic.
- Select your portrait custom native template in the Template dropdown menu.
- Fill in the rest of the fields as needed, including the image URLs. If you entered a destination URL, you can test it by clicking Open Destination URL to the right of the field.
- Click Save Ad Item.