class Event in Googalytics - Google Analytics 8
Class Event.
Hierarchy
- class \Drupal\ga\AnalyticsCommand\Generic implements DrupalSettingCommandsInterface uses DrupalSettingCommandsTrait
Expanded class hierarchy of Event
1 file declares its use of Event
- EventTest.php in tests/
src/ Unit/ AnalyticsCommand/ EventTest.php
File
- src/
AnalyticsCommand/ Event.php, line 8
Namespace
Drupal\ga\AnalyticsCommandView source
class Event extends Send {
/**
* The event category.
*
* @var string
*/
protected $eventCategory;
/**
* The event action.
*
* @var string
*/
protected $eventAction;
/**
* The event label.
*
* @var null|string
*/
protected $eventLabel;
/**
* The event value.
*
* @var int
*/
protected $eventValue;
/**
* Create constructor.
*
* @param string $event_category
* The event category.
* @param string $event_action
* The event action.
* @param string $event_label
* The event label (optional).
* @param int $event_value
* The event value (optional).
* @param array $fields_object
* A map of values for the command's fieldsObject parameter.
* @param string $tracker_name
* The tracker name (optional).
* @param int $priority
* The command priority.
*/
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;
}
/**
* {@inheritdoc}
*/
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)) {
// If label is not specified but value is, the value must be set in
// fieldsObject instead.
$fieldsObject['eventValue'] = $this->eventValue;
}
if (!empty($fieldsObject)) {
$command[] = $fieldsObject;
}
return [
$command,
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalSettingCommandsTrait:: |
protected | property | Priority integer. | |
DrupalSettingCommandsTrait:: |
public | function | An integer value for sorting by priority. | |
Event:: |
protected | property | The event action. | |
Event:: |
protected | property | The event category. | |
Event:: |
protected | property | The event label. | |
Event:: |
protected | property | The event value. | |
Event:: |
public | function |
An array of commands to be sent to Google Analytics. Overrides Send:: |
|
Event:: |
public | function |
Create constructor. Overrides Send:: |
|
Generic:: |
protected | property | The command name. | |
Generic:: |
protected | property | A map of values for the command's fieldsObject parameter. | |
Generic:: |
protected | property | The name of the tracker for this command. | |
Generic:: |
public | function | Get the command name. | |
Generic:: |
public | function | Get the map of values for the command's fieldsObject parameter. | |
Generic:: |
public | function | The tracker this command will be applied to, if specified. | |
Send:: |
protected | property | The event hitType parameter. | |
Send:: |
private static | property | ||
Send:: |
constant |
Overrides Generic:: |
1 |