You are here

function google_analytics_reports_fields_save in Google Analytics Reports 7.3

Save Google Analytics fields from Metadata API to database.

1 call to google_analytics_reports_fields_save()
drush_google_analytics_reports_fields in ./google_analytics_reports.drush.inc
Import Google Analytics fields.
1 string reference to 'google_analytics_reports_fields_save'
google_analytics_reports_fields_import in ./google_analytics_reports.module
Import Google Analytics fields to database using Metadata API.

File

./google_analytics_reports.module, line 127
Front-end interfaces that use the Google Analytics Reports API module.

Code

function google_analytics_reports_fields_save($field, &$context) {
  $attributes =& $field['attributes'];
  $field['id'] = str_replace('ga:', '', $field['id']);
  $attributes['type'] = strtolower($attributes['type']);
  $attributes['dataType'] = strtolower($attributes['dataType']);
  $attributes['status'] = strtolower($attributes['status']);
  $attributes['description'] = isset($attributes['description']) ? $attributes['description'] : '';
  $attributes['calculation'] = isset($attributes['calculation']) ? $attributes['calculation'] : NULL;

  // Allow other modules to alter Google Analytics fields before saving
  // in database.
  drupal_alter('google_analytics_reports_field_import', $field);
  db_insert('google_analytics_reports_fields')
    ->fields(array(
    'gaid' => $field['id'],
    'type' => $attributes['type'],
    'data_type' => $attributes['dataType'],
    'column_group' => $attributes['group'],
    'ui_name' => $attributes['uiName'],
    'description' => $attributes['description'],
    'calculation' => $attributes['calculation'],
  ))
    ->execute();
  $context['results'][] = $field['id'];
}