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.

A sample portrait ad

In this guide, we're going to create a simple portrait ad using a custom native ad template. This type of native template has all the code - HTML, JavaScript, and style element - necessary to display the ad properly.

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

Templates for custom native ad items are not compatible with styled native ad items, and vice-versa.

You will learn:

  1. How to create a template for a custom portrait ad. You can customize the sample code to fit your needs.
  2. 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.

  1. Click Native Ad Templates in the left navigation menu to go to the Templates section.
  2. Click Add Native Ad Template in the Native Ad Templates table. The New Native Template window will appear.
  3. Click Custom Rendering/API. The New Native Ad Template page will appear.

Selecting a native template type

  1. 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.
  2. Enter the code in the HTML Template (Custom Rendering) field, then click Save Changes.

Creating a custom native portrait ad template

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.

Back to top

How to create a custom portrait ad item

  1. Go to the section of the relevant zone (Your AdButler > Publishers > Your Publisher > Your Zone) or campaign (Your AdButler > Advertisers > Your Advertiser > Your Campaign).
Custom native portrait ad items can be assigned only to Standard zones with their size set to Dynamic. The zone size can be configured only when creating a zone and cannot be changed afterward.
  1. Click Add Ad Item in the Ad Items table. The Add Ad Item window will appear.
  2. Click Native (Custom Rendering/API). The New Ad Item page will appear.

Creating a native (custom rendering/API) ad item

  1. Set the ad item's size to Dynamic.
  2. Select your portrait custom native template in the Template dropdown menu.
  3. 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.
  4. Click Save Ad Item.

Creating a custom native portrait ad item in AdButler

Back to top


Can't find what you're looking for?

Send us an email

hello@adbutler.com

Visit the blog

For more ad serving tips, industry news and AdButler insights.