public function AcquiaLiftAPI::saveAgent in Acquia Lift Connector 7
Saves an agent to Acquia Lift.
Parameters
$machine_name: The machine of the agent.
$label: The human-readable name of the agent.
$decision_style: The decision style to use, either 'random' or 'adaptive'
$status: The status to set the agent to.
$control_rate: A number between 0 and 1 inclusive representing the percentage to use as a control group.
$explore_rate: A number between 0 and 1 inclusive representing the percentage to use as the continuous experiment group.
$sticky: Boolean indicating whether decisions made by the agent should stick for each visitor.
Return value
boolean TRUE if the agent has been saved to Acquia Lift, FALSE otherwise.
File
- includes/
acquia_lift.classes.inc, line 437  - Provides an agent type for Acquia Lift
 
Class
- AcquiaLiftAPI
 - @file Provides an agent type for Acquia Lift
 
Code
public function saveAgent($machine_name, $label, $decision_style, $status = 'enabled', $control_rate = 0.1, $explore_rate = 0.2, $sticky = TRUE) {
  // The selection-mode argument can only be "random" or "adaptive", so coerce the
  // $decision_mode variable if it's somehow something else.
  if ($decision_style !== "random") {
    $decision_style = "adaptive";
  }
  $status = self::mapStatus($status);
  $url = $this
    ->generateEndpoint("/agent-api/{$machine_name}");
  $agent = array(
    'name' => $label,
    'selection-mode' => $decision_style,
    'status' => $status,
    'control-rate' => $control_rate,
    'explore-rate' => $explore_rate,
    'decision-stickiness' => $sticky ? 'session' : 'none',
  );
  $response = $this
    ->httpClient()
    ->put($url, array(
    'Content-Type' => 'application/json; charset=utf-8',
    'Accept' => 'application/json',
  ), $agent);
  $data = json_decode($response->data, TRUE);
  $vars = array(
    'agent' => $machine_name,
  );
  $success_msg = 'The campaign {agent} was pushed to Acquia Lift';
  $fail_msg = 'The campaign {agent} could not be pushed to Acquia Lift';
  if ($response->code == 200 && $data['status'] == 'ok') {
    $this
      ->logger()
      ->log(PersonalizeLogLevel::INFO, $success_msg, $vars);
  }
  else {
    $this
      ->handleBadResponse($response->code, $fail_msg, $vars);
  }
}