You are here

function _build_experiment_report in Acquia Lift Connector 7.2

Builds the render array for the summary portion of the report.

Parameters

array $aggregated_data: The per-variation results aggregated across all dates

bool $confidence: Whether the report has confidence.

bool $winner: The id of the winning option or NULL if there's no winner

array: A render array for the report.

1 call to _build_experiment_report()
acquia_lift_report_audience in ./acquia_lift.admin.inc
Builds the audience-specific report.

File

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

Code

function _build_experiment_report($aggregated_data, $confidence, $winner, $personalization_name, $audience_name, $confidence_measure) {
  $headers = array(
    t('Variation'),
    array(
      'data' => t('Times shown'),
      'data-help-tooltip' => t('Number of times this variation was shown to the experimental group.'),
    ),
    array(
      'data' => t('Goals met'),
      'data-help-tooltip' => t('Number of times visitors in the experiement group completed a goal after viewing the variation.'),
    ),
    array(
      'data' => t('Conversion rate'),
      'data-help-tooltip' => t('Percentage of goals met for each display of the variation.'),
    ),
    array(
      'data' => t('Chance to beat control'),
      'data-help-tooltip' => t('Confidence that this variation will perform better than the control.'),
    ),
    array(
      'data' => t('Lift'),
      'data-help-tooltip' => t('Estimated increase in conversions if this variation were to be shown all the time, versus the control.'),
    ),
    array(
      'data' => t('Winner'),
      'data-help-tooltip' => t('Most effective variation for visitors based on a @confidence% confidence level.', array(
        '@confidence' => $confidence_measure,
      )),
    ),
  );
  $confidence_message_shown = FALSE;
  $rows = array();
  $num_rows = count($aggregated_data);
  foreach ($aggregated_data as $choice_id => $choice_data) {
    $row_data = array(
      array(
        'data' => $choice_data['option_label'],
        'data-acquia-lift-variation-label' => _get_variation_label($choice_id, $personalization_name),
      ),
      array(
        'data' => $choice_data['count'],
      ),
      array(
        'data' => $choice_data['goals'],
      ),
      array(
        'data' => $choice_data['conversion'],
      ),
      array(
        'data' => $choice_data['confidence'],
      ),
      array(
        'data' => $choice_data['lift_default'],
      ),
    );

    // Add the winner column data.
    if (empty($rows) && !$confidence) {

      // If there is low confidence then show the message throughout the
      // winner column.
      $row_data[] = array(
        'data' => _get_low_confidence_message($confidence_measure),
        'rowspan' => $num_rows,
        'class' => array(
          'acquia-lift-ab-winner',
        ),
      );
      $confidence_message_shown = TRUE;
    }
    else {
      if (!$confidence_message_shown) {

        // Show the winner indicator if this is the winning variation.
        $row_data[] = $confidence && $winner === $choice_id ? '<span class="lift-winner">' . t('Winner') . '</span>' : '';
      }
    }
    $rows[] = array(
      'data' => $row_data,
      'no_striping' => TRUE,
    );
  }
  if (empty($rows)) {
    return array();
  }
  $build['summary_holder'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'lift-graph-result',
      ),
    ),
  );
  $build['summary_holder']['summary_table'] = array(
    '#theme' => 'table',
    '#header' => $headers,
    '#rows' => $rows,
    '#sticky' => FALSE,
    '#attributes' => array(
      'class' => array(
        'lift-graph-result-data',
      ),
      'data-acquia-lift-personalization' => $personalization_name,
      'data-acquia-lift-audience' => $audience_name,
    ),
    '#attached' => array(
      'library' => array(
        array(
          'acquia_lift',
          'acquia_lift.help',
        ),
      ),
    ),
  );
  return $build;
}