You are here

public function ALProfilesAPI::saveEvent in Acquia Lift Connector 7

Same name and namespace in other branches
  1. 7.2 acquia_lift_profiles/includes/acquia_lift_profiles.classes.inc \ALProfilesAPI::saveEvent()

Saves an event to Acquia Lift Profiles

Parameters

string $machine_name: The canonical, machine-readable name of the event.

string $label: The human-readable name of the event.

string $event_type: The type of event, can be one of 'CAMPAIGN_ACTION', 'CAMPAIGN_CLICK_THROUGH', 'CAMPAIGN_CONVERSION', or 'OTHER' (default).

Throws

ALProfilesException

File

acquia_lift_profiles/includes/acquia_lift_profiles.classes.inc, line 344
Provides an agent type for Acquia Lift Profiles

Class

ALProfilesAPI
@file Provides an agent type for Acquia Lift Profiles

Code

public function saveEvent($event_name, $event_label, $event_type = 'OTHER') {

  // First get our Authorization header.
  $headers = array(
    'Accept' => 'application/json',
  );
  $url = $this
    ->generateEndpoint('events/' . $event_name);
  $params = array(
    'label' => $event_label,
    'type' => $event_type,
  );
  if (!empty($this->customerSite)) {
    $params['customerSite'] = $this->customerSite;
  }
  $auth_header = $this
    ->getAuthHeader('PUT', $url, $params, $headers);
  $headers += array(
    'Authorization' => $auth_header,
  );
  $querystring = empty($this->customerSite) ? '?' : '?customerSite=' . $this->customerSite . '&';
  $querystring .= 'label=' . rawurlencode($event_label) . '&type=' . $event_type;
  $response = $this
    ->httpClient()
    ->put($url . $querystring, $headers);
  $vars = array(
    'eventname' => $event_name,
  );
  $success_msg = 'The event {eventname} has been saved to Acquia Lift Profiles';
  $fail_msg = 'Could not save event {eventname} to Acquia Lift Profiles';
  if ($response->code == 200) {
    $this
      ->logger()
      ->log(PersonalizeLogLevel::INFO, $success_msg, $vars);
  }
  else {
    $this
      ->logger()
      ->log(PersonalizeLogLevel::ERROR, $fail_msg, $vars);
    throw new ALProfilesException($fail_msg);
  }
}