Event.php in Googalytics - Google Analytics 8
File
src/AnalyticsCommand/Event.php
View source
<?php
namespace Drupal\ga\AnalyticsCommand;
class Event extends Send {
protected $eventCategory;
protected $eventAction;
protected $eventLabel;
protected $eventValue;
public function __construct($event_category, $event_action, $event_label = NULL, $event_value = NULL, array $fields_object = [], $tracker_name = NULL, $priority = self::DEFAULT_PRIORITY) {
if (!is_null($event_value) && (!is_int($event_value) || $event_value < 0)) {
throw new \InvalidArgumentException("Event value must be a positive integer");
}
parent::__construct('event', $fields_object, $tracker_name, $priority);
$this->eventCategory = $event_category;
$this->eventAction = $event_action;
$this->eventLabel = $event_label;
$this->eventValue = $event_value;
}
public function getSettingCommands() {
$command = [
($this->trackerName ? $this->trackerName . '.' : '') . $this->command,
$this->hitType,
$this->eventCategory,
$this->eventAction,
];
$fieldsObject = $this->fieldsObject;
if (!empty($this->eventLabel)) {
$command[] = $this->eventLabel;
if (!is_null($this->eventValue)) {
$command[] = $this->eventValue;
}
}
elseif (!is_null($this->eventValue)) {
$fieldsObject['eventValue'] = $this->eventValue;
}
if (!empty($fieldsObject)) {
$command[] = $fieldsObject;
}
return [
$command,
];
}
}