You are here

class Send in Googalytics - Google Analytics 8

Class Send.

Hierarchy

Expanded class hierarchy of Send

1 file declares its use of Send
SendTest.php in tests/src/Unit/AnalyticsCommand/SendTest.php

File

src/AnalyticsCommand/Send.php, line 8

Namespace

Drupal\ga\AnalyticsCommand
View source
class Send extends Generic {
  const DEFAULT_PRIORITY = -10;
  private static $hitTypes = [
    "pageview",
    "event",
    "social",
    "timing",
    "exception",
  ];

  /**
   * The event hitType parameter.
   *
   * @var string
   */
  protected $hitType;

  /**
   * Send constructor.
   *
   * @param string $hit_type
   *   The event hitType.
   * @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($hit_type, array $fields_object = [], $tracker_name = NULL, $priority = self::DEFAULT_PRIORITY) {
    if (!in_array($hit_type, self::$hitTypes)) {
      throw new \InvalidArgumentException("Invalid hit type specified.");
    }
    parent::__construct('send', $fields_object, $tracker_name, $priority);
    $this->hitType = $hit_type;
  }

  /**
   * {@inheritdoc}
   */
  public function getSettingCommands() {
    $command = [
      ($this->trackerName ? $this->trackerName . '.' : '') . $this->command,
      $this->hitType,
    ];
    if (!empty($this->fieldsObject)) {
      $command[] = $this->fieldsObject;
    }
    return [
      $command,
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalSettingCommandsTrait::$priority protected property Priority integer.
DrupalSettingCommandsTrait::getPriority public function An integer value for sorting by priority.
Generic::$command protected property The command name.
Generic::$fieldsObject protected property A map of values for the command's fieldsObject parameter.
Generic::$trackerName protected property The name of the tracker for this command.
Generic::getCommand public function Get the command name.
Generic::getFieldsObject public function Get the map of values for the command's fieldsObject parameter.
Generic::getTrackerName public function The tracker this command will be applied to, if specified.
Send::$hitType protected property The event hitType parameter.
Send::$hitTypes private static property
Send::DEFAULT_PRIORITY constant Overrides Generic::DEFAULT_PRIORITY 1
Send::getSettingCommands public function An array of commands to be sent to Google Analytics. Overrides Generic::getSettingCommands 2
Send::__construct public function Send constructor. Overrides Generic::__construct 4