You are here

public function AcquiaLiftAgent::getAgentSyncOperations in Acquia Lift Connector 7

Returns the operations needed to sync an agent to Acquia Lift.

Parameters

$targeting_rule_exists: Whether the existing agent in Lift has a targeting rule set up that may need to be deleted.

Return value

array An array of items representing API calls to be made to Acquia Lift.

1 call to AcquiaLiftAgent::getAgentSyncOperations()
AcquiaLiftAgent::postSave in plugins/agent_types/AcquiaLiftAgent.inc
Implements PersonalizeAgentInterface::postSave().

File

plugins/agent_types/AcquiaLiftAgent.inc, line 471
Provides an agent type for Acquia Lift

Class

AcquiaLiftAgent

Code

public function getAgentSyncOperations($targeting_rule_exists = FALSE) {
  $items = array();
  $acquia_lift_control_rate = 0.1;
  $acquia_lift_explore_rate = 0.2;
  if (isset($this->data['control_rate'])) {

    // Acquia Lift takes the control rate as a number between 0 and 1.
    $acquia_lift_control_rate = $this->data['control_rate'] / 100;
  }
  if (isset($this->data['explore_rate']) && isset($this->data['decision_style'])) {
    if ($this->data['decision_style'] === 'adaptive') {

      // Acquia Lift takes the explore rate as a number between 0 and 1.
      $acquia_lift_explore_rate = $this->data['explore_rate'] / 100;
    }
    else {

      // If the decision style is to only test, then the explore rate is the
      // full group.
      $acquia_lift_explore_rate = 1;
    }
  }

  // Add an item for saving the agent to Acquia Lift.
  $items[] = array(
    'method' => 'saveAgent',
    'args' => array(
      $this->machineName,
      $this->title,
      $this->data['decision_style'],
      $this->status,
      $acquia_lift_control_rate,
      $acquia_lift_explore_rate,
      isset($this->data['cache_decisions']) && $this->data['cache_decisions'],
    ),
  );
  $acquia_lift_context_needs_deleting = $targeting_rule_exists;
  if (isset($this->data['visitor_context']['acquia_lift_context'])) {

    // Whereas non-Acquia Lift visitor_context plugins operate by adding extra
    // info at the time of getting a decision, Acquia Lift targeting needs to
    // be set up on the Acquia Lift side before any decisions are made.
    $auto_targeting = array_filter($this->data['visitor_context']['acquia_lift_context']);
    if (!empty($auto_targeting)) {
      $acquia_lift_context_needs_deleting = FALSE;

      // Add an item for saving the targeting rule.
      $items[] = array(
        'method' => 'saveAutoTargetingRule',
        'args' => array(
          $this->machineName,
          array_keys($auto_targeting),
        ),
      );
    }
  }
  if ($acquia_lift_context_needs_deleting) {

    // Acquia Lift may have a targeting rule for this agent, so we need
    // to delete it.
    $items[] = array(
      'method' => 'deleteAutoTargetingRule',
      'args' => array(
        $this->machineName,
      ),
    );
  }
  return $items;
}