Index: google_analytics_reports_views/google_analytics_reports_views.info
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- google_analytics_reports_views/google_analytics_reports_views.info (revision e50321ee171ac47d07b977eadf94f7941ccd3f69)
+++ google_analytics_reports_views/google_analytics_reports_views.info (revision )
@@ -12,3 +12,4 @@
files[] = handlers/google_analytics_reports_views_handler_filter_numeric.inc
files[] = handlers/google_analytics_reports_views_handler_field.inc
files[] = handlers/google_analytics_reports_views_handler_argument.inc
+files[] = handlers/google_analytics_reports_views_plugin_argument.inc
Index: google_analytics_reports_views/google_analytics_reports_views.views.inc
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- google_analytics_reports_views/google_analytics_reports_views.views.inc (revision e50321ee171ac47d07b977eadf94f7941ccd3f69)
+++ google_analytics_reports_views/google_analytics_reports_views.views.inc (revision )
@@ -2,120 +2,128 @@
/**
* @file
- * Provide views data and handlers for Google Analytics Core Reporting API.
+ * Contains a default argument plugin to return the current user's cart order ID.
*/
/**
- * Implements hook_views_data().
+ * Default argument plugin to get the current user's cart order ID.
*/
-function google_analytics_reports_views_views_data() {
- $data['google_analytics']['table']['group'] = t('Google Analytics');
+class google_analytics_reports_views_plugin_argument extends views_plugin_argument_default {
- $data['google_analytics']['table']['base'] = array(
- 'title' => t('Google Analytics'),
- 'query class' => 'google_analytics_reports_views_query',
- 'help' => t('Views Google Analytics query builder'),
- );
+ function option_definition() {
+ $options = parent::option_definition();
- $data['google_analytics']['start_date'] = array(
- 'title' => t('Start date of report'),
- 'help' => t('Start date of report.'),
- 'argument' => array(
- 'handler' => 'google_analytics_reports_views_handler_argument',
- ),
- 'filter' => array(
- 'handler' => 'google_analytics_reports_views_handler_filter_date',
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort_date',
- ),
- );
+ $options['metrics'] = array('default' => '');
+ $options['dimensions'] = array('default' => '');
+ $options['filters'] = array('default' => '');
+ $options['start_date'] = array('default' => '');
+ $options['end_date'] = array('default' => '');
+ $options['sort'] = array('default' => '');
+ $options['start_index'] = array('default' => '1');
+ $options['max_results'] = array('default' => '50');
+ $options['entity'] = array('default' => 'node');
- $data['google_analytics']['end_date'] = array(
- 'title' => t('End date of report'),
- 'help' => t('End date of report.'),
- 'argument' => array(
- 'handler' => 'google_analytics_reports_views_handler_argument',
- ),
- 'filter' => array(
- 'handler' => 'google_analytics_reports_views_handler_filter_date',
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort_date',
- ),
- );
+ return $options;
+ }
- $data['google_analytics']['profile_id'] = array(
- 'title' => t('Profile ID'),
- 'help' => t('Profile ID'),
- 'argument' => array(
- 'handler' => 'google_analytics_reports_views_handler_argument_string',
+ function options_form(&$form, &$form_state) {
+ $form['metrics'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Metrics'),
+ '#description' => t('Enter one title per line.'),
+ '#default_value' => $this->options['metrics'],
+ '#required' => TRUE,
+ );
+ $form['dimensions'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Dimensions'),
+ '#description' => t('Enter one title per line.'),
+ '#default_value' => $this->options['dimensions'],
+ '#required' => TRUE,
+ );
+ $form['filters'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Filters'),
+ '#description' => t('Enter one title per line.'),
+ '#default_value' => $this->options['filters'],
+ );
+ $form['start_date'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Start Date'),
+ '#description' => t('Enter Date or relative time (e.g. -2 Days).'),
+ '#default_value' => $this->options['start_date'],
+ );
+ $form['end_date'] = array(
+ '#type' => 'textfield',
+ '#title' => t('End Date'),
+ '#description' => t('Enter Date or relative time (e.g. now).'),
+ '#default_value' => $this->options['end_date'],
+ );
+ $form['sort'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Sort'),
+ '#description' => t('Enter one title per line.'),
+ '#default_value' => $this->options['sort'],
+ );
+ $form['start_index'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Start'),
+ '#description' => t('First Result.'),
+ '#default_value' => $this->options['start_index'],
+ );
+ $form['max_results'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Max Results'),
+ '#description' => t('Maximum Results.'),
+ '#default_value' => $this->options['max_results'],
+ );
+ $form['entity'] = array(
+ '#type' => 'radios',
+ '#title' => t('Results'),
+ '#default_value'=> $this->options['entity'],
+ '#options' => array(
+ 'node' => t('Node IDs'),
+ 'term' => t('Taxonomy Term IDs'),
- ),
+ ),
- 'filter' => array(
- 'handler' => 'google_analytics_reports_views_handler_filter_string',
- ),
- );
+ );
+ }
- $fields = google_analytics_reports_views_get_fields();
+ function get_argument() {
+ $params['metrics'] = array_filter(array_map('trim', explode(PHP_EOL, $this->options['metrics'])), 'strlen');
+ $params['dimensions'] = array_filter(array_map('trim', explode(PHP_EOL, $this->options['dimensions'])), 'strlen');
+ $params['filters'] = array_filter(array_map('trim', explode(PHP_EOL, $this->options['filters'])), 'strlen');
+ $params['sort'] = array_filter(array_map('trim', explode(PHP_EOL, $this->options['sort'])), 'strlen');
+ $params['start_date'] = strtotime($this->options['start_date']);
+ $params['end_date'] = strtotime($this->options['end_date']);
+ $params['start_index'] = $this->options['start_index'];
+ $params['max_results'] = $this->options['max_results'];
- foreach ($fields as $field_name => $field) {
- if (isset($field['calculation'])) {
- $field['description'] = $field['description'] . '
' . t('Calculation: @formula
.',
- array('@formula' => $field['calculation']));
+ $feed = google_analytics_reports_api_report_data($params);
+ if ($feed->error) {
+ return FALSE;
}
- $field['description'] = $field['description'] . '
' . t('API name: @ga
.',
- array('@ga' => 'ga:' . $field_name));
- // Provide default handler.
- $field_handler = 'views_handler_field';
- $float = FALSE;
+ $nids = array();
+ $tids = array();
- if (google_analytics_reports_views_is_custom($field_name)) {
- $field_handler = 'google_analytics_reports_views_handler_field';
+ foreach ($feed->results->rows as $row) {
+ $path = drupal_get_normal_path(trim($row['pagePath'], '/'));
+ $path_parts = explode('/', $path);
+ if ($path_parts[0] == 'node') {
+ $nids[] = $path_parts[1];
- }
+ }
- elseif (in_array($field['datatype'], array('date', 'time'))) {
- $field_handler = 'views_handler_field_date';
+ else if ($path_parts[0] == 'taxonomy' && $path_parts[1] == 'term') {
+ $tids[] = $path_parts[2];
- }
+ }
- elseif (in_array($field['datatype'],
- array('integer', 'float', 'percent', 'currency'))) {
-
- $field_handler = 'views_handler_field_numeric';
- $float = TRUE;
}
- $data['google_analytics'][$field_name] = array(
- 'title' => $field['name'],
- 'help' => $field['description'],
- 'group' => $field['group'],
- 'field' => array(
- 'handler' => $field_handler,
- 'click sortable' => TRUE,
- 'float' => $float,
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort',
- ),
- 'argument' => array(
- 'handler' => 'google_analytics_reports_views_handler_argument',
- ),
- 'filter' => array(
- 'handler' => ($field['type'] == 'metric') ? 'google_analytics_reports_views_handler_filter_numeric' : 'google_analytics_reports_views_handler_filter_string',
- ),
- );
+ if ($this->options['entity'] == 'node') {
+ return implode('+', $nids);
- }
+ }
-
- return $data;
+ elseif ($this->options['entity'] == 'term') {
+ return implode('+', $tids);
-}
+ }
-
-/**
- * Implements hook_views_plugins().
- */
-function google_analytics_reports_views_views_plugins() {
- return array(
- 'query' => array(
- 'google_analytics_reports_views_query' => array(
- 'title' => t('Google Analytics Query'),
- 'handler' => 'google_analytics_reports_views_plugin_query_google_analytics',
- ),
- ),
- );
+ else {
+ return NULL;
+ }
+ }
}
Index: google_analytics_reports_views/handlers/google_analytics_reports_views_plugin_argument.inc
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- google_analytics_reports_views/handlers/google_analytics_reports_views_plugin_argument.inc (revision )
+++ google_analytics_reports_views/handlers/google_analytics_reports_views_plugin_argument.inc (revision )
@@ -0,0 +1,62 @@
+ 'node');
+
+ return $options;
+ }
+
+ function options_form(&$form, &$form_state) {
+ $form['query'] = array(
+ '#type' => 'radios',
+ '#title' => t('Query'),
+ '#default_value'=> $this->options['query'],
+ '#process' => array('form_process_radios', 'ctools_dependent_process'),
+ '#options' => array(
+ 'node' => t('Most Viewed Nodes'),
+ ),
+ );
+ }
+
+ function get_argument() {
+ if (!empty($this->options['query']))
+ switch ($this->options['query']) {
+ case 'node':
+ $params = array(
+ 'metrics' => array('ga:pageviews'),
+ 'dimensions' => array('ga:pageTitle', 'ga:hostname', 'ga:pagePath'),
+ 'sort_metric' => array('-ga:pageviews'),
+ 'start_date' => strtotime('-2 days'),
+ 'end_date' => strtotime('now'),
+ 'sort' => '-ga:pageviews',
+ 'max_results' => '500',
+ );
+ $feed = google_analytics_reports_api_report_data($params);
+ if ($feed->error) {
+ return FALSE;
+ }
+ foreach ($feed->results->rows as $row) {
+ $nids = array();
+ $path = drupal_get_normal_path($row['pagePath']);
+ $node_path = explode('/', drupal_get_normal_path($path));
+ if ($node_path[0] == 'node') {
+ $nids[] = $node_path[1];
+ }
+ }
+ return implode('+', $nids);
+ }
+
+ }
+}