0
以下是我不斷嘗試的代碼;我基本上只是試圖用通用GA來跟蹤頁面;然後分配一個跟蹤類別內onClick事件的類,並在文件名的末尾自動生成一個1,2,3。我基本上只是試圖簡化在一個網站內跟蹤我的onClick文件;我不想繼續手動將onClick代碼添加到我試圖在頁面上跟蹤的每個文件。 我的下面的代碼是怎麼回事?GA //通過生成獨特輸出的類跟蹤onClick事件?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-35609953-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['_trackEvent', 'Downloads', 'JPG', '/downloads/img/LowRes01.jpg']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<!-- GA track all onClicks -->
<script>
$(function(){
$('.downloadsmall a').attr("onclick", function(i){
var x='LowRes0'+(i+1)+'.jpg';
return "_gaq.push(['_trackPageview', '/downloads/img/"+x+"'])";
return "_gaq.push(['_trackEvent', 'Downloads', 'JPG', '/downloads/img/"+x+"'])";
});
});
</script>
<!-- End GA track all onClicks -->
<style>
#wrap {
width: 940px;
margin-left: 0 auto;
}
#left {
width: 50%;
float: left;
}
#right {
width: 50%;
float: right;
}
.downloadsmall {
height: 50px;
width: 200px;
border: 3px dotted #333;
}
</style>
</head>
<body>
<div id="wrap"><!-- Wrap -->
<div id="left">
<p class="downloadsmall">
download: <a href="http://www.google.com">Low Res</a>
</p>
</div>
<div id="right">
<p class="downloadsmall">
download: <a href="http://www.yahoo.com">Low Res</a>
</p>
</div>
</div><!-- Wrap -->
修訂----
下面是每Jasper的響應更新的代碼; (謝謝!)我擁有它,並期待着看到它是如何解決的。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<!-- GA track all onClicks -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-35609953-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['_trackEvent', 'Downloads', 'JPG', '/downloads/img/"+x+"']);
$(function(){
$('.downloadsmall a').on("click", function(){
var theHREF = $(this).attr('href'),
myGAQ = _gaq || [];
myGAQ.push(['_trackPageview', theHREF]);
myGAQ.push(['_trackEvent', 'Downloads', 'JPG', theHREF]);
});
});
</script>
<!-- End GA track all onClicks -->
謝謝 - 剛更新了我的Q;我把你寫的東西放進去;我要去測試它! –
@whoa歡迎您,讓我知道您的測試如何進行。 – Jasper
Myyyyyyyyy男子。 –