You are here

class Metric in Googalytics - Google Analytics 8

Class Dimension.

@package Drupal\ga\AnalyticsCommand

Hierarchy

Expanded class hierarchy of Metric

2 files declare their use of Metric
AnalyticsSubscriber.php in modules/ga_tokens/src/EventSubscriber/AnalyticsSubscriber.php
MetricTest.php in tests/src/Unit/AnalyticsCommand/MetricTest.php
1 string reference to 'Metric'
ga_tokens.schema.yml in modules/ga_tokens/config/schema/ga_tokens.schema.yml
modules/ga_tokens/config/schema/ga_tokens.schema.yml

File

src/AnalyticsCommand/Metric.php, line 10

Namespace

Drupal\ga\AnalyticsCommand
View source
class Metric extends Set {

  /**
   * Dimension constructor.
   *
   * @param int $index
   *   The metric index.
   * @param int|float $value
   *   The metric value.
   * @param array $fields_object
   *   A set of additional options for the command.
   * @param string $tracker_name
   *   The tracker name.
   * @param int $priority
   *   The command priority.
   */
  public function __construct($index, $value, array $fields_object = [], $tracker_name = NULL, $priority = self::DEFAULT_PRIORITY) {

    // TODO remove this cast in favour of typing in PHP7.
    if (!is_int($index)) {
      if (!is_string($index) || !ctype_digit($index)) {
        throw new \InvalidArgumentException("Metric index must be an integer between 0 and 199");
      }
      $index = (int) $index;
    }
    if ($index < 0 || $index >= 200) {
      throw new \InvalidArgumentException("Metric index must be an integer between 0 and 199");
    }
    if (!is_int($value) || !is_float($value)) {
      if (!is_numeric($value)) {
        throw new \InvalidArgumentException("Metric value must be numeric");
      }
      if (ctype_digit($value)) {
        $value = (int) $value;
      }
      else {
        $value = (double) $value;
      }
    }
    parent::__construct('metric' . $index, $value, $fields_object, $tracker_name, $priority);
  }

}

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.
Metric::__construct public function Dimension constructor. Overrides Set::__construct
Set::$settingKey protected property The setting key.
Set::$settingValue protected property The setting value.
Set::DEFAULT_PRIORITY constant Overrides Generic::DEFAULT_PRIORITY
Set::getSettingCommands public function An array of commands to be sent to Google Analytics. Overrides Generic::getSettingCommands
Set::getSettingKey public function Get the setting key.
Set::getSettingValue public function Get the setting value.