JQuery live + Disqus / Google Analytics

I use the following function to overload links to a site using 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 Google Analytics tracking and Disqus loading can be integrated into this feature. This is the code I tried to download disqus, but it downloads comments from other sites for some reason:

 window.disqus_no_style = true; $.getScript("http://disqus.com/forums/mnml/embed.js") 

thanks

+6
source share
1 answer

You can simply put the Google Analytics function directly into the call call by 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 edited the function for caching href inside the event, since its inefficiency is to rotate 3 (now 4) separate jQuery objects for a value that will be fixed for each call.)

+3
source

Source: https://habr.com/ru/post/886960/


All Articles