How to add Google Analytics to ajax pages


Basically, In Google Analytic, any time tracking call is made, the activity is logged. And we most frequently use the following script:
<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-29545838-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script>
And for tracking ajax pages, in the view file of the ajax page you need to add the url of the ajax page as follows after _trackPageview (see the blue colored change):


<script type="text/javascript">
var _gaq = _gaq || [];_gaq.push(['_setAccount', 'UA-29545838-1']);_gaq.push(['_trackPageview','/ajax_page_uri']);(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();</script>

 

Comments

Popular posts from this blog

Automate file upload in Selenium IDE

How To Install and Configure Nextcloud