前段時間準備把百度廣告管家的代碼改為百度聯盟的代碼,順便還想再比較一下百度、Google廣告的一些數據,現在對Drupal模闆、PHP程序比較熟悉了,所以采取在模闆中嵌入PHP程序來随機出現Google/百度相關代碼就很容易實現。
<?php $number_rand = rand(0,1);//0:google,1:baidu if ($number_rand == 0) { $ad1 = '<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- AdSense 2015 - 336x280 大矩形 --> <ins class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-909487182760xxxx" data-ad-slot="971344xxxx"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> '; $ad2 = ' <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- AdSense 2015 - 336x280 大矩形 2 --> <ins class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-909487182760xxxx" data-ad-slot="717877xxxx"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> '; } else { $ad1 = ' <script type="text/javascript"> /*Baidu Union 2015-07 336*280*/ var cpro_id = "u218xxxx"; </script> <script src="http://cpro.baidustatic.com/cpro/ui/c.js" type="text/javascript"></script> '; $ad2 = ' <script type="text/javascript"> /*Baidu Union 2015-07 336*280 2*/ var cpro_id = "u218xxxx"; </script> <script src="http://cpro.baidustatic.com/cpro/ui/c.js" type="text/javascript"></script> '; } ?> ...... <?php print $ad1; ?> ...... <?php print $ad2; ?> ......
上面程序用一個随機函數,讓Google/Baidu的代碼各有一半的幾率出現。$ad1和$ad2分别是兩個廣告位的代碼,放置在頁面中需要的地方。
對比測試需要注意的地方可以參考這篇博文:《用A/B測試來評估AdSense不同代碼的效果》。
评论1
你的标題
您的評論TEST