Skip to content

Instantly share code, notes, and snippets.

@tollmanz
Created October 12, 2012 23:17
Show Gist options
  • Save tollmanz/3882192 to your computer and use it in GitHub Desktop.
Save tollmanz/3882192 to your computer and use it in GitHub Desktop.
Get Google Analytics Data
<?php
function zt_generate_top_posts() {
// These URLs will not be be returned
$blacklisted_paths = array(
'/',
'about-us',
'that-page-no-one-needed-to-see'
);
// URLs with these components will not be returned
$blacklisted_components = array(
'twitter-accounts',
'.html'
);
// Collect the arguments
$args = array(
'number' => 5,
'start-date' => '2012-10-07',
'end-date' => '2012-10-13',
'bl_paths' => $blacklisted_paths,
'bl_components' => $blacklisted_components,
);
// Queries GA, relates to internal posts
$top_post_objects = zt_magic_GA_querier( $args );
// If no objects are returned, exit the function
if ( false === $top_post_objects )
return false;
// Start building the HTML
$html = '<ul>';
// Loop through post objects and generate HTML
foreach ( $top_post_objects as $post_object ) {
$html .= '<li>';
$html .= '<a href="' . esc_url( $post_object['permalink'] ) . '">';
$html .= esc_html( $post_object['post_title'] );
$html .= '</a>';
$html .= '</li>';
}
$html .= '</ul>';
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment