我的Google地图代码是:
function initialize(mapdata){
var LatLng=new google.maps.LatLng(mapdata[0],mapdata[1]);
var myOptions= {
zoom:16,
scaleControl:true,
streetViewControl:false,
panControl:true,
mapTypeControl:true,
center:new google.maps.LatLng(mapdata[0],mapdata[1]),
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("map"), myOptions);
document.getElementById("map").style.height="200px";
document.getElementById("map").style.width="450px";
var infowindow=new google.maps.InfoWindow();
var marker=new google.maps.Marker({position:LatLng});
marker.setMap(map);
google.maps.event.addListener(marker,'mouseover',function(){
infowindow.setContent(<div style="text-align:right; font-size:8pt; color:black;">click here<a href="http://www.google.com/"></a> </div>');
infowindow.open(map,marker);
});
}
我的问题是如何在信息窗口内容中的点击事件后跟踪分析?
提前感谢,Irena
查看analytics事件跟踪指南
<a href="#" onClick="_gaq.push(['_trackEvent', 'Videos', 'Play', 'Baby's First Birthday']);">Play</a>
还注意您的infowindow.setContent(<div...
在('<div
之前缺少'
要设置信息窗口内链接的onclick事件,必须使用jquery live event。这是因为直到我们点击标记显示信息窗口时,链接才出现。
因此,要在信息窗口内实现<div>
上的单击事件,您需要执行以下操作:
google.maps.event.addListener(marker,'mouseover',function(){
infowindow.setContent('<div style="text-align:right; font-size:8pt; color:black;" id="some_id_here">click here<a href="http://www.google.com/"></a> </div>');
infowindow.open(map,marker);
});
$("#some_id_here").live('click', function() {
alert('click');
});
注意我已经给div设置了id="some_id_here"
如果你有多个信息窗口同时打开,你需要在重置它之前解除对活动事件的绑定。否则,live('click')
事件可能被绑定多次。要做到这一点,你应该这样做:
$("#some_id_here").die('click').live('click', function() {