I'm using the following function to overload my website url links with Ajax:
$(document).ready(function() {
$('.insite').live("click", function(ev) {
if ( history.pushState ) history.pushState( {}, document.title, $(this).attr('href'));
ev.preventDefault();
$('#content').fadeOut().load($(this).attr('href')+' #content', function() {
$(this).fadeIn();
});
});
});
I would like to know if it's possible to integrate Google Analytics tracking and Disqus loading into the function. This is the code I have tried to load disqus but it loads comments from another websites for some reasons:
window.disqus_no_style = true;
$.getScript("http://disqus.com/forums/mnml/embed.js")
Thanks
You can just put the Google Analytics function directly in the event call, placing the new virtual URL in the second parameter.
$(document).ready(function() {
$('.insite').live("click", function(ev) {
var href = $(this).attr('href');
if ( history.pushState ) history.pushState( {}, document.title, href);
ev.preventDefault();
$('#content').fadeOut().load(href+' #content', function() {
$(this).fadeIn();
_gaq.push(['_trackPageview', href ]);
});
});
});
(I've edited the function to cache the href
within the event, since its inefficient to spin up 3 (now 4) separate jQuery objects for a value that will be fixed for each call. )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With