Countdown Component

Updated: 02/04/2019. Version: 2.0.0

Example of Countdown Component (Image-based):

Example of Countdown Component (Text-based):

MPU Template in HTML5 Studio

Leaderboard Template in HTML5 Studio

Description

The following guidelines describes Countdown Component implementation and setup. Please follow instructions below in order to correctly setup component and change available parameters.

Initialization

Load component in <head></head> inside index.html:

<head>
...

<script src="//s1.adform.net/banners/scripts/components/Adform.Countdown.js"></script>

...
</head>

Note:
- roll.png or other graphics which represents numbers counting in countdown component should be placed inside Additional Assets folder. This applies only if the countdown is image-based. Detailed instructions Countdown Component Setup (Image-based)

Mandatory settings

These are the properties that have to be present in Countdown Component:

Name Type Default Description
placement string ‘adf-banner’ element id in which Countdown will be drawn

Optional Settings

Optional settings are not mandatory and have default values.

Name Type Default Description
action function null callback that will be executed on countdown click or end
actionOnClick boolean false set to ‘true’ in order to get action invoked on click
initializeOn string ‘load’ set to ‘hover’ or ‘load’ to choose how countdown gets initialized in banner
counterImage string path of countdown image if countdown is image-based
counterText string provide a countdown text if countdown is text-based
textPosition string ‘bottom right’ position of text-based counter in banner
label string text which will be shown above image countdown
counter integer 3 duration of countdown

Options need to be set inside var countdown = new Adf.Countdown({});

Note: choose between counterImage and counterText options, depending on type of Countdown that is being created (image-based or text-based).

Example of Countdown Component Setup

Examples below shows how to setup component in different scenarios.

Countdown Component Setup (Image-based)

Example below displays a default caller with Countdown functionality. It uses an image from assets folder, counter number appears over the provided image. Countdown gets toggled on hover, user can click to dismiss the counter and invoke action, which in this case calls the floating banner.

<script>

        var countdown = new Adf.Countdown({
            placement: 'adf-banner', // set countdown placement element
            action: showFloat, // action or function that gets called after countdown
            actionOnClick: true, // if true, action gets invoked on click, counter is then dismissed
            initializeOn: 'hover', // set to 'hover' or 'load' to choose how countdown gets initialized in banner
            counterImage: Adform.getAsset(1), // set counter image
            counter: 3 // set countdown time in seconds
        });

        countdown.init();

</script>

Important: Countdown graphical image should be set in Additional Assets and asset number should be defined via counterImage: parameter.

Countdown Component Setup (Text-based)

Provided text-based Countdown example uses default actionOnClick and initializeOn options. It is only required to set counterText value in order to start using a text-based Countdown. Additionaly, default text position can be changed adding a textPosition option.

<script>

        var countdown = new Adf.Countdown({
            placement: 'adf-banner', // set countdown placement element
            action: close, // action or function that gets called after countdown
            counterText: 'Ad will close in {count} seconds', // set counter text
            counter: 15 // set countdown time in seconds
        });

        countdown.init();

</script>

Note: It is mandatory to place {count} in counterText string to indicate counter placement in text.

Countdown Component Setup With Video Banners

In order to make Countdown component responsive to video events, simply add event listeners to your banner video element as portrayed in example below:

    video.addEventListener("play", function(){
        countdown.pause();
    });

    video.addEventListener("pause", function(){
        countdown.resume();
    });

Use provided exposed component methods to control Countdown in your code.

Example of Countdown Full Setup

Code below shows how Countdown component could be setup in HTML5 Standard rich media ad:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <script>
        document.write('<script src="' + (window.API_URL || 'https://s1.adform.net/banners/scripts/rmb/Adform.DHTML.js?bv=' + Math.random()) + '"><\/script>');
    </script>
    <link rel="stylesheet" href="//s1.adform.net/banners/scripts/components/styles/Adform.Styles-1.css" />
    <script src="//s1.adform.net/banners/scripts/components/Adform.Countdown.js"></script>
</head>
<body>

    <div id="adf-banner" class="adf-Banner adf-Background adf-Border u-sizeFull">

    <!-- Place banner content here -->

    </div>

    <!-- Components -->
    <script src="scripts/custom.js"></script> 
    <!-- Components -->

    <!-- User code -->
    <script>
        function showFloat() {
            parent.ADFCall(Adform.getVar('bn'), 'show');
        };

        var countdown = new Adf.Countdown({
            placement: 'adf-banner', // set countdown placement element
            action: showFloat, // action or function that gets called after countdown
            actionOnClick: true, // if true, action gets invoked on click, counter is then dismissed
            initializeOn: 'hover', // set to 'hover' or 'load' to choose how countdown gets initialized in banner
            counterImage: Adform.getAsset(1), // set counter image
            counter: 3 // set countdown time in seconds
        });

        countdown.init();

    </script>
    <!-- User code -->

Exposed methods

Name Description
countdown.start() Starts counter
countdown.hide() Hides counter
countdown.dismiss() Dismisses counter
countdown.pause() Pauses counter
countdown.resume() Resumes counter after pause