Metric.php in Googalytics - Google Analytics 8
File
src/AnalyticsCommand/Metric.php
View source
<?php
namespace Drupal\ga\AnalyticsCommand;
class Metric extends Set {
public function __construct($index, $value, array $fields_object = [], $tracker_name = NULL, $priority = self::DEFAULT_PRIORITY) {
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);
}
}