XMLHttpRequest() and Google Analytics Tracking
Posted
by sjw
on Stack Overflow
See other posts from Stack Overflow
or by sjw
Published on 2010-05-01T03:15:30Z
Indexed on
2010/05/01
3:27 UTC
Read the original article
Hit count: 283
I have implemented an XMLHttpRequest() call to a standalone html page which simply has an html, title & body tag which Google Analytics Tracking code.
I want to track when someone makes a request to display information (i.e. phone number) to try and understand what portion of people look at my directory versus obtaining a phone number to make a call.
It is very simple code:
var xhReq = new XMLHttpRequest();
xhReq.open("GET", "/registerPhoneClick.htm?id=" + id, false);
xhReq.send(null);
var serverResponse = xhReq.responseText
Yet I cannot see the "hit" in Analytics... Has anyone had this issue? All the analytics tracking code does is call:
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-XXXXXXX");
pageTracker._trackPageview();
} catch(err) {}</script>
So realistically, my XmlHTTPRequest() calls an htm file within which a script is execute to make an outbound call to Google Analytics.
Is there any reason why an XmlHTTPRequest() would not execute this?
Does an XmlHTTPRequest() still bring the code to the client before execution?
Help Please
© Stack Overflow or respective owner