public function Metric::__construct in Googalytics - Google Analytics 8
Dimension constructor.
Parameters
int $index: The metric index.
int|float $value: The metric value.
array $fields_object: A set of additional options for the command.
string $tracker_name: The tracker name.
int $priority: The command priority.
Overrides Set::__construct
File
- src/
AnalyticsCommand/ Metric.php, line 26
Class
- Metric
- Class Dimension.
Namespace
Drupal\ga\AnalyticsCommandCode
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);
}