function seotools_dashboard_map_box in Drupal SEO Tools 7
Same name and namespace in other branches
- 6 seotools.report.inc \seotools_dashboard_map_box()
1 call to seotools_dashboard_map_box()
File
- ./
seotools.report.inc, line 1104
Code
function seotools_dashboard_map_box($gid, $siteURL, $date_range, $enabled_modules, &$mediums_data) {
// geographic data
if (!($data = seotools_cache_get('data_ga_country', $date_range))) {
$request = array(
'#dimensions' => array(
'pagePath',
'country',
),
'#metrics' => array(
'pageviews',
),
'#sort_metric' => array(
'country',
'pagePath',
),
'#start_date' => $date_range['start_date'],
'#end_date' => $date_range['end_date'],
);
$data = seotools_fetch_ga_data($request, 'country');
seotools_cache_set('data_ga_country', $data, $date_range);
}
$name_to_iso = countries_api_get_array('name', 'iso2');
$countries = array();
$max_pageviews = 0;
foreach ($data as $key => $value) {
$match = $name_to_iso[strtoupper($key)];
if ($match) {
$max_pageviews = max($max_pageviews, $value['pageviews']);
$countries[$match] = $value['pageviews'];
}
}
// Find out proportion share from 1-100 for each country.
$countries_share = array();
foreach ($countries as $key => $value) {
$countries_share[$key] = round($value / $max_pageviews * 100);
}
// Create the geographical chart.
$chart = array(
'#chart_id' => 'countries',
'#type' => CHART_TYPE_MAP,
'#size' => chart_size(440, 220),
'#georange' => 'world',
'#countries' => array_keys($countries_share),
'#data' => array_values($countries_share),
'#data_colors' => array(
'ffffff',
'edf0d4',
'13390a',
),
);
$output .= '<h3>' . t('Map Overlay') . '</h3>';
//$r_chart = chart_url($chart);
$r_chart = chart_render($chart);
$js['charts']['sources_map'] = array(
'src' => $r_chart,
'location' => 'chart-map',
);
// TODO figure out why js crashing
//drupal_add_js( array('seotools' => $js), 'setting');
$output .= '<div class="chart-map-wrapper">';
$output .= $r_chart;
$output .= '</div>';
return $output;
}