public function DataApi::saveEvent in Acquia Lift Connector 8
Saves an event to Acquia Lift Data
Parameters
string $event_name: The 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
File
- src/
Service/ Api/ DataApi.php, line 209 - Contains \Drupal\acquia_lift\Service\Api\DataApi.
Class
Namespace
Drupal\acquia_lift\Service\ApiCode
public function saveEvent($event_name, $event_type = 'OTHER') {
// First get our Authorization header.
$headers = [
'Accept' => 'application/json',
];
$url = $this
->generateEndpoint('events/' . $event_name);
$auth_header = $this
->getAuthHeader('PUT', $url, [
'type' => $event_type,
], $headers);
$headers += [
'Authorization' => $auth_header,
];
$request = new Request('PUT', $url . '?type=' . $event_type, $headers);
$response = $this->httpClient
->send($request);
$vars = [
'@eventname' => $event_name,
];
$success_msg = SafeMarkup::format('The event @eventname has been saved to Acquia Lift', $vars);
$fail_msg = SafeMarkup::format('Could not save event @eventname to Acquia Lift', $vars);
if ($response
->getStatusCode() != 200) {
$this->logger
->error($fail_msg);
throw new DataApiException($fail_msg);
}
$this->logger
->info($success_msg);
}