javascript - Ajax google analytics event tracking in html page not working - Stack Overflow

Following is the Google Analytics code added just before close of head in html page.var _gaq = _gaq ||

Following is the Google Analytics code added just before close of /head in html page.

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
_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/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

Following is where I am calling the event... when successful or failed...

$.ajax({
    url: "/xxx/xx/",
    type: "POST",
    data: { name: q, seme: o, profile: x }
    datatype: "html",
    success: function (f) {
        _gaq && _gaq.push(["_trackEvent", "contactform", "success", i, p])
},
    error: function (f) {
        _gaq && _gaq.push(["_trackEvent", "contactform", "crash", i, p])
    }
});

But the event is not recorded... I have been waiting to see something from past 4 days.. I have performed few tests but it is not showing up in the analytics... Am I doing anything wrong? Do I have to add any extra line in Google Analytics main snippet added in head tag?

GA tracks the normal data but not these event.

Following is the Google Analytics code added just before close of /head in html page.

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
_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./ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

Following is where I am calling the event... when successful or failed...

$.ajax({
    url: "/xxx/xx/",
    type: "POST",
    data: { name: q, seme: o, profile: x }
    datatype: "html",
    success: function (f) {
        _gaq && _gaq.push(["_trackEvent", "contactform", "success", i, p])
},
    error: function (f) {
        _gaq && _gaq.push(["_trackEvent", "contactform", "crash", i, p])
    }
});

But the event is not recorded... I have been waiting to see something from past 4 days.. I have performed few tests but it is not showing up in the analytics... Am I doing anything wrong? Do I have to add any extra line in Google Analytics main snippet added in head tag?

GA tracks the normal data but not these event.

Share Improve this question edited Dec 12, 2011 at 9:47 Reporter 3,9365 gold badges35 silver badges49 bronze badges asked Dec 12, 2011 at 9:39 Santosh S KumarSantosh S Kumar 4791 gold badge7 silver badges32 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

I dont understand why you have the line:

_gaq && _gaq.push(["_trackEvent", "contactform", "success", i, p])

and not just

_gaq.push(["_trackEvent", "contactform", "success", i, p]);

or even

if (typeof _gaq != "undefined")
   _gaq.push(["_trackEvent", "contactform", "success", i, p]);

Another trick for knowing when data has been sent correctly is to reference ga_debug.js on Google Analytics' servers rather then the standard ga.js - this will give you Console output and show "Tracking beacon sent!" as well as all the data that has been sent, when it's been successful. I suggest you try that out and see if it helps!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745625702a4636790.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信