You are here

function acquia_lift_report_daily_conversions in Acquia Lift Connector 7.2

AJAX callback to return the daily conversion report.

The following parameters are supplied within the query string:

  • personalization: the machine name of the personalization
  • audience: the audience to get data for
  • goal: (optional) a goal name to limit results (defaults to all goals)
1 string reference to 'acquia_lift_report_daily_conversions'
acquia_lift_menu in ./acquia_lift.module
Implements hook_menu().

File

./acquia_lift.admin.inc, line 1458
acquia_lift.admin.inc Provides functions needed for the admin UI.

Code

function acquia_lift_report_daily_conversions() {
  $params = drupal_get_query_parameters();
  $report = array(
    '#markup' => t('No report available for this personalization.'),
  );
  if (empty($params['personalization']) || empty($params['audience'])) {
    drupal_json_output(drupal_render($report));
    return;
  }
  $personalization_name = personalize_sanitize_string($params['personalization']);
  $audience = personalize_sanitize_string($params['audience']);
  $goal = empty($params['goal']) ? NULL : personalize_sanitize_string($params['goal']);
  $personalization = personalize_agent_load($personalization_name);
  if ($personalization->plugin == "acquia_lift_target") {
    $account_info = acquia_lift_get_account_info();
    $api = AcquiaLiftAPI::getInstance($account_info);
    $targeting_option_set = acquia_lift_get_option_set_for_targeting($personalization_name, FALSE);
    $targeting_structure = acquia_lift_get_structure_from_targeting($targeting_option_set, FALSE);
    if (!isset($targeting_structure[$audience])) {
      drupal_json_output(drupal_render($report));
      return;
    }
    $audience_type = isset($targeting_option_set->targeting[$audience]['osid']) ? 'test' : 'target';
    list($start_time, $end_time) = acquia_lift_get_report_dates_for_agent($personalization, FALSE);
    try {
      $audience_report = $api
        ->getAudienceReport($personalization_name, $audience, $targeting_structure[$audience], $audience_type, $start_time, $end_time, $goal);
      if (!empty($audience_report['daily_stats'])) {
        $daily_data = _extract_daily_data($audience_report['daily_stats'], $personalization_name);
        $daily_report = _build_daily_report($daily_data, $personalization_name, $audience);
        drupal_json_output('<div id="acquia-lift-daily-report-data">' . drupal_render($daily_report) . "</div>");
        return;
      }
    } catch (AcquiaLiftException $e) {
    }
  }
  drupal_json_output(drupal_render($report));
}