Simple GA Ranking on wordpress.org. Please install below:
/wp-admin/options-general.php?page=gapiwp-analytics
. like below movie:/wp-admin/options-general.php?page=sga_ranking
.
Simple GA Ranking Widget
or [sga_ranking] shortcode
or sga_ranking_get_date() function
.
The sga_ranking_get_date()
function return post_id of ranking as array. Put the function at where you'd like to show the ranking in your theme.
<?php
array(
'display_count' => 10,
'period' => 30,
'post_type' => 'post',
'exclude_post_type' => '',
'`taxonomy_slug`__in' => '',
'`taxonomy_slug`__not_in' => '',
'filter' => ''
);
?>
display_count
: It specifies the number of rankings to be displayed.period
: It specifies the terms of period. Number of days of going back from today to the past.post_type
: set the attribute of the slug of the post-type you’d like to show. You can set multiple sulgs separeted by comma.exclude_post_type
: set the attribute of the post-type you’d NOT like to show. You can set multiple sulgs separeted by comma.'taxonomy_slug'__in
: set the attribute of the taxonomy you’d like to show. You can set multiple terms separeted by comma.'taxonomy_slug'__not_in
: set the attribute of the taxonomy you’d NOT like to show. You can set multiple terms separeted by comma.filter
: You can use the filter parameter as same as the fileter parameter of Google Analytics API. Core Reporting API<?php
if (function_exists('sga_ranking_get_date')) {
$ranking_data = sga_ranking_get_date();
if ( !empty( $ranking_data ) ) {
echo '<ol>';
foreach ( $ranking_data as $post_id ) {
echo '<li><a href="' . esc_attr(get_permalink($post_id)) . '">' . esc_html(get_the_title($post_id)) . '</a></li>';
}
echo '</ol>';
}
}
?>
<?php
$args = array(
'display_count' => 10,
'period' => 30,
'post_type' => 'post',
'category__in' => 'news'
);
$ranking_data = sga_ranking_get_date($args);
?>
/en/
in URL.<?php
$args = array(
'display_count' => 10,
'period' => 30,
'post_type' => 'post,page',
'filter' => 'ga:pagePath=~^/en/'
);
$ranking_data = sga_ranking_get_date($args);
?>
Put the [sga_ranking]
shortcode at where you'd like to show the ranking.
The same as sga_ranking_get_date function.
[sga_ranking post_type="post,product"]
[sga_ranking post_type="product" product_category__in="child" period="10" display_count="10"]
We provide some WordPress hooks. you can customize to use it.
sga_ranking_cache_expire
: You can update the terms of the ranking cache expire. default 1 day.sga_ranking_limit_filter
: You can update the limit of number to get from Google Analytics. Default 100.sga_ranking_before_title
: You can customize the html befor title.sga_ranking_after_title
: You can customize the html after title.sga_ranking_ids
: You can customize rankind post_ids.<?php add_filter( 'sga_ranking_cache_expire', function($expire) { return 12*60*60; } ); ?>
<?php add_filter( 'sga_ranking_limit_filter', function($limit) { return 200; } ); ?>