I just start to work with Google API. At first I upload a simple HTML file to a host that have a button to send some information to Google and I see correct result but when I test this method on my real project it doesn’t work properly. I did same work as my simple sample put tracking code after < head > tag
<script type="text/javascript" >
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-26*****-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);
})();
function sent_report(){
_gaq.push(['_trackEvent','label','Over','back']);
}
</script >
and call
_gaq.push(['_trackEvent','button','click','Just for test']);
but it doesn’t make any change in my feedback in Google and its hard to debug because Google update feeds after 24h
Did I forgot some thing to do?or did something wrong?
Is there any problem that I run local host and didn’t upload it to the host?!?!?
Thank you…
Google Analytics won’t work on
localhostor127.0.0.1or any other IP address. It needs a FQDN to work correctly.I usually setup http://www.example.com on my hosts file to redirect to
127.0.0.1and I use that instead to test my code.You can debug if you’re coding is working or not by using HTTPFox and checking the requests to __utm.gif. The data you send is encoded as query parameters but it should be easy to read them.