After setting up my Google Analytics account and adding the provided code to my index.php file, I noticed calls to www.google-analytics.com in Firebug. It seems like everything is working correctly.
Now, I want to track how many times the 'functions.php' file is called through AJAX from the index file.
I attempted to use
_gaq.push(['_trackPageview', 'functions.php']);
but encountered an error stating Uncaught ReferenceError: _gaq is not defined
. To address this, I included var _gaq = _gaq || [];
in my code, which resolved the error. However, I am now unable to see any requests to www.google-analytics.com after the AJAX request completes.
If anyone could assist me in configuring analytics to track AJAX calls, I would greatly appreciate it.
This is how my code appears:
<script type='text/javascript'>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-1234556-1', 'domain.com');
ga('send', 'pageview');
var _gaq = _gaq || [];
function submit_data(){
var text_area=$('#textarea').val();
var url ="functions.php";
jQuery.ajax({
type: "get",
dataType: "text",
url: url,
data: {
what : "generate",
text_area: text_area,
t: Math.random()
},
success: function(data, textStatus){
$('#textarea').val(data);
// _gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_trackPageview', 'functions.php']);
}
});
}
</script>