2013-02-02 102 views
1

我想用PHP和JS跟蹤橫幅瀏覽的方式提供一些幫助。我知道如何跟蹤橫幅廣告點擊,但我無法看到跟蹤視圖的方式。跟蹤橫幅瀏覽

回答

2

如果您的橫幅廣告是圖片,則可以用記錄視圖並返回圖片的PHP腳本替換它的URL。

例如:<img src="http://img.com/img.png"> - >上重寫PHP腳本 - >日誌 - >返回圖片

+0

我沒有得到這個。你能提供更多信息嗎? – Psyche

0

如果你想永久保存多少次橫幅/圖像已被查看,修改表您的數據庫包含圖像的標識符。

表橫幅

id | path | clicks | views

www.example.org/products.php?products=type_a

<?php 
// other code 
$type = $_GET["products"]; 
// sanitize $type 
$views; 
$products_selected = get_product_ids_from_type($type); 
$query = "..."; // use $products_selected to create a query that will help to get image records from table 
while($row = mysql_fetch_row(...)) { 
    echo "<img src='".$row[1]."' />"; 
    $views[$row[0]] = $row[3]; // get the old number of views 
} 
foreach($products_selected as $id) { 
$query = "insert into `table-banner` (`views`) values ('".($views[$id] + 1)."') where id=`".$id."`;"; 
// perform the query 
} 

這意味着,當有人點擊該鏈接www.example.org/products.php?產品= type_a,請求去服務器,因爲type_a產品被選中,您的.php文件將使用該類型來獲取id(s)並顯示相應的圖像,並且當這些圖像被提取顯示時,在相同您更新每個圖像記錄的視圖列

如果你也想使用JavaScript(這是沒有必要爲這個),你可以

<script> 
var selected_ids = [ 
<?php 
    foreach($products_selected as $v) { 
    echo $v.","; 
    } 
?> 
];</script> 
<script> 
    $(function() { 
    for(x in selected_ids) { 
    $.ajax({ 
     type: "POST", 
     url: "ajax.php", 
     data: { id: selected_ids[x] } 
    }).done(function(msg) { 
     alert(selected_ids[x] + " now has views : " + msg); 
    }); 
    } 
    }); 
</script> 

www.example.org/ajax.php

$id = $_POST["id"]; 
// create connection 
$view = 0; 
$query = ...; // get old views from id and store in $view 
// perform the query to insert new view 
$query = "insert into `table-banner` (`views`) values ('".($view + 1)."') where id = `".$id."`;"; 
echo $view; 
+0

omg,它現在關閉! :d – GLES