jQuery to track Google analytics events not working

£可爱£侵袭症+ 提交于 2020-01-04 04:28:24

问题


I'm trying to use google anayltics events but so far without any success..

What I'm doing is loading 5 pages using jQuery load function and I want to track the "Next button" for each load. but looks like i'm doing something wrong..

This is the next button event code:

            $('.NextButton').click(function () {
                _gaq.push(['_trackEvent', 'fz_main_page', 'clicked']);
                installation.load_page({ inner_page: next_page, comid: data.comid, outerid: data.outerid, single_app: "1" });
            });

Analytics Code:

<script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-25162785-2']);
    _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>

What am I doing wrong?


回答1:


It's possible that the installation.load_page function is preventing the trackEvent from firing. Try wrapping your load function in a setTimeout:

setTimeout('installation.load_page({ inner_page: next_page, comid: data.comid, outerid: data.outerid, single_app: "1" })', 100);

Install the Google Analytics Debugger. Look in the console (control, shift, j) for the event tracking processing.

If you don't see all of your events tracking there, then something else is up with the tracking code.



来源:https://stackoverflow.com/questions/10395364/jquery-to-track-google-analytics-events-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!