jQuery to track Google analytics events not workin

2019-07-06 21:39发布

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条回答
不美不萌又怎样
2楼-- · 2019-07-06 22:06

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.

enter image description here

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

查看更多
登录 后发表回答