GA Tracking code on ajax requests?
开发者_运维百科I have this:
<!-- Google Code for Tilmeldinger nyhedsbrev Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ /
var google_conversion_id = 982857669;
var google_conversion_language = "da";
var google_conversion_format = "1";
var google_conversion_color = "ffffff";
var google_conversion_label = "e90GCIP3jwMQxe_U1AM";
var google_conversion_value = 0;
if (20) {
google_conversion_value = 20;
}
/ ]]> */
</script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/982857669/?value=20&label=e90GCIP3jwMQxe_U1AM&guid=ON&script=0"/>
</div>
</noscript>
I inserted it on the page the ajax request to, and in the response I see this script^.
But it does not track or count anything?
What should I do?
The script's not being executed when the AJAX request returns. You can either try and figure out why, or I think the <noscript>
bit does most of the work anyway so you could try removing the rest and just placing the image into your page:
<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/982857669/?value=20&label=e90GCIP3jwMQxe_U1AM&guid=ON&script=0"/>
This should issue an image request that sends the tracking data to AdWords.
You can use the GA event's tracking. Here is all info you need: http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html
I suggest you to write small function:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
_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 event(category, action, label, value) {
_gaq.push(['_trackEvent', category, action, label, value]);
}
And jsut call event() function.
精彩评论