Skip to content

Instantly share code, notes, and snippets.

@cgrymala
Created Jul 31, 2013
Embed
What would you like to do?
Output the Analytics tracking information for UMW
<?php
add_action( 'wp_print_scripts', 'umw_insert_analytics_code' );
function umw_insert_analytics_code() {
if( is_admin() )
return;
global $wpdb;
$sites = json_encode( array_flip( $wpdb->get_col( $wpdb->prepare( "SELECT domain FROM {$wpdb->site} ORDER BY id" ) ) ) );
?>
<script type="text/javascript">
var umw_internal_sites = <?php echo $sites ?>;
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<?php
wp_enqueue_script( 'ga-external-tracker', plugins_url( '/analytics/ga-external-tracker.js', __FILE__ ), array( 'jquery' ), '0.2.15', true );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment