How to get visitors count of a page created using views I have created a page in Drupal using views. Is there any option to get the count of visitors that visit the page?
Enable the statistics module that comes with core in admin/module. You can start tracking pages once you enable the log settings in admin/config/system/statistics

Once you enable the Setting Enable access log drupal will start tracking all pages. Now follow below process to create a view.


Create a view with base type as access log
Enable aggregation in the other settings
Add Access Log path field and set "Group results together" in aggregation settings next to field settings.
Add one more field access log path and select Aggregation type as count.
Now you can see all paths and number of visits associated with them.
Add filter access log path and provide the path for which you would like to see number of visits.


Find the exported view below.

$view = new view();
$view-&gt;name = 'statistics';
$view-&gt;description = '';
$view-&gt;tag = 'default';
$view-&gt;base_table = 'accesslog';
$view-&gt;human_name = 'Statistics';
$view-&gt;core = 7;
$view-&gt;api_version = '3.0';
$view-&gt;disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view-&gt;new_display('default', 'Master', 'default');
$handler-&gt;display-&gt;display_options['title'] = 'Statistics Custom';
$handler-&gt;display-&gt;display_options['use_more_always'] = FALSE;
$handler-&gt;display-&gt;display_options['group_by'] = TRUE;
$handler-&gt;display-&gt;display_options['access']['type'] = 'none';
$handler-&gt;display-&gt;display_options['cache']['type'] = 'none';
$handler-&gt;display-&gt;display_options['query']['type'] = 'views_query';
$handler-&gt;display-&gt;display_options['exposed_form']['type'] = 'basic';
$handler-&gt;display-&gt;display_options['pager']['type'] = 'full';
$handler-&gt;display-&gt;display_options['pager']['options']['items_per_page'] = '10';
$handler-&gt;display-&gt;display_options['style_plugin'] = 'default';
$handler-&gt;display-&gt;display_options['row_plugin'] = 'fields';
/* Field: Access log: Path */
$handler-&gt;display-&gt;display_options['fields']['path']['id'] = 'path';
$handler-&gt;display-&gt;display_options['fields']['path']['table'] = 'accesslog';
$handler-&gt;display-&gt;display_options['fields']['path']['field'] = 'path';
/* Field: COUNT(Access log: Path) */
$handler-&gt;display-&gt;display_options['fields']['path_1']['id'] = 'path_1';
$handler-&gt;display-&gt;display_options['fields']['path_1']['table'] = 'accesslog';
$handler-&gt;display-&gt;display_options['fields']['path_1']['field'] = 'path';
$handler-&gt;display-&gt;display_options['fields']['path_1']['group_type'] = 'count';
$handler-&gt;display-&gt;display_options['fields']['path_1']['label'] = 'Count';
/* Filter criterion: Access log: Path */
$handler-&gt;display-&gt;display_options['filters']['path']['id'] = 'path';
$handler-&gt;display-&gt;display_options['filters']['path']['table'] = 'accesslog';
$handler-&gt;display-&gt;display_options['filters']['path']['field'] = 'path';
$handler-&gt;display-&gt;display_options['filters']['path']['value'] = 'admin/config/system/statistics';

/* Display: Page */
$handler = $view-&gt;new_display('page', 'Page', 'page');
$handler-&gt;display-&gt;display_options['defaults']['hide_admin_links'] = FALSE;
$handler-&gt;display-&gt;display_options['path'] = 'statistics-custom';


That's it :-)

If you would like to display page counter contextually then below code in a custom block will help.

&lt;?php
$path = $_GET['q'];
drupal_set_message($path);
$visits = db_query("SELECT count(*) FROM {accesslog} where path = :path", array(':path' =&gt; $path))-&gt;fetchField();
echo "Views: " . $visits;
?&gt;