0

我正在尝试将 Google Analytics 代码插入网站。这段代码被放在每一页上:

<!--Google Analytics account for all smithmicro sites-->
<script type="text/javascript">
var _gaq = _gaq || [];
                _gaq.push(['_setAccount', 'UA-166807-32']);
                _gaq.push(['_setAllowLinker', true]);
                _gaq.push(['_addIgnoredRef', 'smithmicro.com']);
                _gaq.push(['_setCustomVar', 5, 'ecommerce', 'fastspring', 3]);

                _gaq.push(['_trackPageview']);

                (function() {
                var ga = document.createElement('script'); 
                ga.type = 'text/javascript'; 
                ga.async = true;
                ga.src = "https://ssl.google-analytics.com/ga.js";

                var s = document.getElementsByTagName('script')[0]; 
                s.parentNode.insertBefore(ga, s);
                })();
                </script>
<!--END Google Analytics account for all smithmicro sites-->

然后这段代码是一个购买按钮:

<form method="POST" action="https://sites.fastspring.com/smithmicro/checkout/23492?source=microsite " target="_top" onsubmit="_gaq.push(['_linkByPost', this]); return false;" ><input type="submit" value="Buy Physical" class="button"  /></form>

如果我取出“return false;”,它就可以正常工作。但是,有人告诉我,分析工作需要在那里。我尝试将它从一个表单更改为一个具有相同参数的链接,并得到了相同的结果。”

4

1 回答 1

0

in this context, return false will result in the form submission not happening, because you are providing your own custom form processing function (in this case _gaq.push(['_linkByPost', this]); return false;) but you aren't actually processing the form data.

I'm not sure where you heard that you needed return false, but I don't think you do. In fact, unless you're submitting the form via javascript, nothing should happen if you return false.

I believe that for LINKS the onclick handler should contain a return false because in this case the default action of navigating away isn't desired, rather the link hit should be recorded then something sent to google then the user should go to the page referenced by the link.

On this page at least they aren't using return false in the form's onsubmit event handler:

https://developers.google.com/analytics/devguides/collection/gajs/asyncMigrationExamples

Also always make sure you're looking at the right documentation (there are different versions of analytics which may behave differently).

于 2013-06-17T18:04:34.577 回答