If you combine ads in our Ordered group type, they will be checked in the given order. The first ad that is checked with a positive result, is also displayed.
Some users are expecting that this group can rotate ads evenly, e.g., show ad #1 first, then ad #2, #3, etc, and finally start again with #1.
While this is not the default behavior, it is possible to build such an order following the tutorial below.
This tutorial uses
- Advanced Ads version 1.9
- Advanced Ads Pro 2.2 for the Cookie condition and Custom Code option
I am demonstrating an example based on 3 ads. You can extend it to any number of ads.
Adding the rotation
In this tutorial, I am saving the last ad the user saw from a group in a cookie and show the next one based on the value of that cookie.
Creating ads and the group
I am not going through the process of creating and publishing ads and groups here. Just create all your ads and put them into a single group. The group type can be ordered or random. I would recommend ordered with the weight in the order of the ads’ appearance in the rotation. Like in the screenshot below.
The rotation logic
The rotation logic is basically looking like this:
- use the Cookie visitor condition to show the first ad when no ad was displayed before
- use the Cookie visitor condition to show the following ads only if the previous ad in the rotation was displayed before
- use the Custom Code option to save the index of the current ad in a cookie
The cookie name I am using here is advads-group-last-ad. You can use any other name. Use a different name for each group if you have multiple of these rotations.
Based on the logic above, the first ad uses these settings.
Go down to the Visitor Conditions box and select the Cookie condition.
Since this is the first ad, we only display it if no cookie exists. The setting looks like on the following screenshot.
Now, go to the Layout / Output box and enable the Custom Code option. Add the following code into the field.
<script>advads.set_cookie('advads-group-last-ad', 1, 1);</script>
This saves the advads-group-last-ad cookie with the value 1 for one day.
The Cookie condition of ad #2 looks a bit different. This ad only shows up if the previous ad was displayed before, which means that the advads-group-last-ad cookie exists and has the value 1.
The Custom Code looks similar to ad #1. We just change the index.
<script>advads.set_cookie('advads-group-last-ad', 2, 1);</script>
Ad #3 (the last ad)
No surprise with the cookie condition. We are basing this ad on the cookie set by ad #2.
The Custom Code option for the last ad is different. To go back to ad #1 we need to remove the cookie completely. We do this by setting the last parameter to 0.
<script>advads.set_cookie('advads-group-last-ad', 3, 0);</script>
That’s it. The ads should rotate evenly now.
Starting with a random ad
If you want to start the rotation with a random ad and then pick up the order, just add another Cookie condition to all ads. This is an example for ad #3.
There are a few limitations I can think of.
- enable cache-busting (also included in Pro) to make this work on cached websites
- it wouldn’t work if the ads have additional and different visitor conditions. E.g., if ad #2 only shows on mobile, ad #3 would never show up on desktop either and the rotation basically stop
- this method works on a per-visitor basis. E.g., every individual visitor starts with ad #1, unless you use the random setup mentioned above