WordPress.org

Support

Support » Plugins and Hacks » [Plugin: Google Analytics for WordPress] Load jQuery and comment tracking only if have comments

[Plugin: Google Analytics for WordPress] Load jQuery and comment tracking only if have comments

  • Could you make jQuery loading conditional? Right now jQuery loads as a dependency when the plugin loads the Google Analytics tracking code for comments as shown below:

    <script type="text/javascript">
    
        jQuery(document).ready(function() {
    
            jQuery('#commentform').submit(function() {
    
                _gaq.push(
    
                    ['_setAccount','UA-345737-1'],
    
                    ['_trackEvent','comment','submit']
    
                );
    
            });
    
        });    
    
    </script>

    On pages that have no comments there is no need to load jQuery or the comment-reply script. I would propose using a condition that checks to see if comments are greater than zero before loading jQuery and the Google Analytics comment tracking code to decrease page load time on pages that have no comments. This is one enhancement that would help our pages load faster.

    if ( get_comments_number() > 0 )

    Thank you for a great plugin.

    http://wordpress.org/extend/plugins/google-analytics-for-wordpress/

  • The topic ‘[Plugin: Google Analytics for WordPress] Load jQuery and comment tracking only if have comments’ is closed to new replies.