You are here

class Generic in Googalytics - Google Analytics 8

Class FieldsObject.

Hierarchy

Expanded class hierarchy of Generic

2 files declare their use of Generic
AutoLink.php in src/AnalyticsCommand/Linker/AutoLink.php
GenericTest.php in tests/src/Unit/AnalyticsCommand/GenericTest.php

File

src/AnalyticsCommand/Generic.php, line 8

Namespace

Drupal\ga\AnalyticsCommand
View source
class Generic implements DrupalSettingCommandsInterface {
  use DrupalSettingCommandsTrait;
  const DEFAULT_PRIORITY = 0;

  /**
   * The command name.
   *
   * @var string
   */
  protected $command;

  /**
   * A map of values for the command's fieldsObject parameter.
   *
   * @var array
   */
  protected $fieldsObject;

  /**
   * The name of the tracker for this command.
   *
   * @var string
   */
  protected $trackerName;

  /**
   * AnalyticsCommand constructor.
   *
   * @param string $command
   *   The command name.
   * @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($command, array $fields_object = [], $tracker_name = NULL, $priority = self::DEFAULT_PRIORITY) {
    $this->command = $command;
    $this->fieldsObject = $fields_object;
    $this->trackerName = $tracker_name;
    $this->priority = $priority;
  }

  /**
   * Get the command name.
   *
   * @return string
   *   The command name.
   */
  public function getCommand() {
    return $this->command;
  }

  /**
   * Get the map of values for the command's fieldsObject parameter.
   *
   * @return array
   *   An array of command values.
   */
  public function getFieldsObject() {
    return $this->fieldsObject;
  }

  /**
   * The tracker this command will be applied to, if specified.
   *
   * @return null|string
   *   The tracker name, or NULL if the default tracker.
   */
  public function getTrackerName() {
    return $this->trackerName;
  }

  /**
   * {@inheritdoc}
   */
  public function getSettingCommands() {
    $command = [
      ($this->trackerName ? $this->trackerName . '.' : '') . $this->command,
    ];
    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::DEFAULT_PRIORITY constant 4
Generic::getCommand public function Get the command name.
Generic::getFieldsObject public function Get the map of values for the command's fieldsObject parameter.
Generic::getSettingCommands public function An array of commands to be sent to Google Analytics. Overrides DrupalSettingCommandsTrait::getSettingCommands 5
Generic::getTrackerName public function The tracker this command will be applied to, if specified.
Generic::__construct public function AnalyticsCommand constructor. 5