Ad Configuration

How to Add a Sticky Header Ad With a Timer

How to Add a Sticky Header Ad With a Timer

Timed stickiness optimizes for visibility on high page speed layouts

Generating effective ad revenue is one the most important integrations for any publisher. If a site's ad experience is not loaded properly, it will not only result in a bad user experience, but also a low PageSpeed Insights score as measured by Google, and this puts your organic traffic at risk.

The wrong way to integrate ads into your site is to load them before a browser has a chance to display other content. This is a tricky balance to get right because ads still need to load quickly to register impressions and generate revenue.

On RebelMouse, we implement ads so that they load quickly while not affecting page-rendering performance. These ads are referred to as "sticky," which means they're always visible on the page even when a user is scrolling — users still see them, and publishers still get the impressions they need.

Using a sticky header ad with a timer so it loads quickly is a great way to optimize for both ad visibility and site performance. Here's how it works.

First, click here to familiarize yourself with our Header Code and Ad Header Code elements. Then, to create a sticky header ad with a timer, you must first set up an ad wrapper:

<!-- Define the ad placement -->
<div class="top-banner">
   <div id="banner_ad_id">
       googletag.cmd.push(function() { googletag.display("banner_ad_id"); });

Next, use JavaScript to make it sticky upon load:

const stickyTime = 4;
googletag.cmd.push(() => {
  const topBanner = document.getElementById("top-banner");
  googletag.pubads().addEventListener('slotRenderEnded', e => {
      let banner_ad_id = "banner_ad_id";
      let div_ad =document.getElementById(banner_ad_id)
      if (banner_ad_id) {
          // check if the slot is empty and if the rendered slot is actually the banner slot
          if (e.slot.getSlotElementId() === banner_ad_id && !e.isEmpty) {
     = div_ad.clientHeight + "px";
              setTimeout(() => {
              }, stickyTime * 1000);

Finally, add some styling:

    /*----  style the banner ad to fix it at top ------ */
 .sticky-banner-ad .top-banner{
     position: fixed;
       width: 100vw;
       top: 100px;
       left: 0;
       z-index: 9;
       display: block;
background: #fff;
       margin: 0 !important;
     @media (max-width:767px){
          /*------- mobile top distance if needed------ */
       .sticky-banner-ad .t
       }     }

Your sticky ad header with a timer is complete. For a guide on all the elements available in our Layout & Design tool, click here.

Click the links below to view live examples of this feature on RebelMouse-powered sites:

If you have any questions about how to implement a sticky ad header with a timer, email or talk to your account manager today.

What Is RebelMouse?
Request a Proposal
The Most Secure CMS of 2023

The Most Secure CMS of 2023

Why RebelMouse Is the Most Secure CMS on the Web

Delivering a secure, high-performing environment with extreme reliability is essential to all of our clients at RebelMouse. We only use industry-leading, reliable approaches to host our infrastructure. This ensures maximum stability and security for all of our clients’ data. Here are just some of the reasons we’re able to maintain a hard-bodied product that’s flexible, too.

Keep reading...Show less
Meet the RebelMouse Platform: The Highest Performing CMS on the Web
Rebel Insights

Meet the RebelMouse Platform: The Highest Performing CMS on the Web

Make sure your site is set up for success in 2022.

In the spring of 2020, Google let the world know that its Core Web Vitals would become the new benchmark for measuring a site's performance in its search results, known as the page experience update. Fast forward to more than a year later in August 2021 when, after much anticipation, Google's page experience update became official.

Since its rollout, developers have felt the impact of how their publishing platforms stack up against the new standard. Important decisions around the architecture of your site can now make or break your site's performance in the eyes of Google.

HTTP Archive, a tracking platform that crawls the web to identify trends and record historical patterns, frequently reports on how top content management systems (CMS) have weathered the page experience update through the creation of its Core Web Vitals Technology Report. RebelMouse has consistently outperformed major CMS platforms on Google's most critical metrics throughout the year:

Getting superior scores on Google's performance benchmarks isn't easy, either. The Ahrefs blog analyzed Core Web Vitals data from the Chrome User Experience Report (CrUX), which is data from actual Chrome users, to see how the web stacks up against Core Web Vitals. Their study found that only 33% of sites on the web are passing Core Web Vitals.

data from Ahrefs tracked on a line chart finds that shows only 33% of sites on the web pass Google's Core Web VitalsFrom Ahrefs.

Luckily, performing well on Core Web Vitals is possible with thoughtful, strategic changes to your site’s codebase. Here's what you need to know and how we can help.

Keep reading...Show less
Interested in a Free Website Health Check?Check Your
Website's Health
Get Your Free Analysis Now