Skip to content

Instantly share code, notes, and snippets.

@cgrymala
Created July 31, 2013 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgrymala/b2930c808c6a3f65d0e5 to your computer and use it in GitHub Desktop.
Save cgrymala/b2930c808c6a3f65d0e5 to your computer and use it in GitHub Desktop.
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