我尝试使用Google Analytics(分析)在我的网站上跟踪ajax表单。 但它没有任何想法?
在我的脑子里,我有:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-11111111-1']);
_gaq.push(['_trackPageview']);
(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>
在我的js文件()
中$('form :submit').click(function(e){
e.preventDefault();
e.stopPropagation();
var retourtest = testform();
if(retourtest==true) {
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-11111111-1']); // your ID/profile
_gaq.push(['_trackPageview']);
(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);
})();
_gaq.push(['_trackEvent', 'spada', 'contactus']);
另外,我附上了谷歌分析配置的视图 http://spadatest.be/stack/2014-02-22.png
提前致谢!
答案 0 :(得分:0)
尝试将_gaq.push(['_trackPageview', '/merci.html']);
放入request.done
来电。
$('form :submit').click(function(e){
e.preventDefault();
e.stopPropagation();
var retourtest = testform();
if(retourtest==true) {
$('#validateoutput').show();
// $('#validateoutput').html('Your message has been sent!');
$('#validateoutput').removeClass('ko').addClass('ok');
var request = $.ajax({
url: "sendcontactform.php",
type: "POST",
data: { sendvar : $('#submitinput').val(),name: $('#nameinput').val(),email: $('#emailinput').val() , phone: $('#phoneinput').val(), comment: $('#commentinput').val() },
dataType: "html"
});
request.done(function( msg ) {
console.log('msg='+msg);
_gaq.push(['_trackPageview', '/merci.html']);
$( "#validateoutput" ).html( msg );
$('#nameinput').val('');
$('#emailinput').val('');
$('#phoneinput').val('');
$('#commentinput').val('');
});
request.fail(function( jqXHR, textStatus ) {
alert( "Request failed: " + textStatus );
});
}
});
答案 1 :(得分:0)
_gaq.push(['_trackEvent', 'spada', 'contactus']); ?
尝试:
_gaq.push(['_trackEvent', 'spada', 'contactus', 'label']);
将标签替换为另一个字词......