A/B Testing Javascript
<script type="text/javascript">
var random_number = Math.random();
if (random_number < .5){
//your first ad unit code goes here
} else {
//your second ad unit code goes here
}
</script>
There is another example found at the Google Adsense Help page and the code looks like this:
Synchronous ad code:
<script type="text/javascript">
var random_number = Math.random();
google_ad_client = "ca-publisher-id";
google_ad_width = 728;
google_ad_height = 90;
if (random_number < .5){
google_ad_slot = "1234567890";
} else {
google_ad_slot = "2345678901";
}
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
Asynchronous ad code:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-publisher-id">
</ins>
<script>
if (Math.random() < .5) {
mySlotId = '1234567890';
} else {
mySlotId = '2345678901';
}
(adsbygoogle = window.adsbygoogle || []).push({
params: { google_ad_slot: mySlotId }
});
</script>
Comments
Post a Comment