getdave / Tanlinell

Boilerplate Wordpress theme for rapid development of new WP themes. Based on the great work of the _s ("Underscore") theme.
GNU General Public License v2.0
6 stars 2 forks source link

update coded ga tracking #315

Closed neilberry001 closed 10 years ago

neilberry001 commented 10 years ago

makes production sensitive

/**
 * Add GA in an awesome manor
 * @link https://github.com/roots/roots/blob/master/lib/scripts.php 
 */

if( !current_user_can('manage_options') ) {
    add_action('wp_head', 'tanlinell_google_analytics', 20);
}

function tanlinell_google_analytics() {

    if( WP_ENV == 'production' ) :

        if( !defined( 'GOOGLE_ANALYTICS_ID' ) )
        {
            $google_analytics_id = ( false != of_get_option( 'google_analytics_id' ) ) ? of_get_option( 'google_analytics_id' ) : false;
            define('GOOGLE_ANALYTICS_ID', $google_analytics_id);
        }
        if( false != $google_analytics_id ) :
?>
            <script type="text/javascript">
                var _gaq=_gaq||[];_gaq.push(['_setAccount','<?php echo GOOGLE_ANALYTICS_ID; ?>']);

                _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>
<?php 
        endif;//if( false != $google_analytics_id ) :

    endif;//if( WP_ENV == 'production' ) :
}
neilberry001 commented 10 years ago

Closed via 6503664973d5686eda9d9b7fe122a316fe9675f3