From 5da708955c60d4b5cdbda505df17bb3ae16d96da Mon Sep 17 00:00:00 2001 From: Karl Clement Date: Mon, 21 Jul 2014 14:39:28 -0400 Subject: [PATCH] Allows CustomVariable key to be overwritten, this allows the user to add custom variables without the dimension as the key Minor fixes failed build Minor spacing --- .../Analytics/CustomVariable.php | 14 +++++++++++++- .../View/Helper/Script/Analyticsjs.php | 14 +++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/SlmGoogleAnalytics/Analytics/CustomVariable.php b/src/SlmGoogleAnalytics/Analytics/CustomVariable.php index 4cde50e..adce151 100644 --- a/src/SlmGoogleAnalytics/Analytics/CustomVariable.php +++ b/src/SlmGoogleAnalytics/Analytics/CustomVariable.php @@ -48,13 +48,15 @@ class CustomVariable protected $name; protected $value; protected $scope; + protected $override = false; - public function __construct($index, $name, $value, $scope = self::SCOPE_PAGE_LEVEL) + public function __construct($index, $name, $value, $scope = self::SCOPE_PAGE_LEVEL, $override = false) { $this->setIndex($index); $this->setName($name); $this->setValue($value); $this->setScope($scope); + $this->setOverride($override); } public function setIndex($index) @@ -116,4 +118,14 @@ public function getScope() { return $this->scope; } + + public function setOverride($override) + { + $this->override = $override; + } + + public function getOverride() + { + return $this->override; + } } diff --git a/src/SlmGoogleAnalytics/View/Helper/Script/Analyticsjs.php b/src/SlmGoogleAnalytics/View/Helper/Script/Analyticsjs.php index 5a64b81..fa43215 100644 --- a/src/SlmGoogleAnalytics/View/Helper/Script/Analyticsjs.php +++ b/src/SlmGoogleAnalytics/View/Helper/Script/Analyticsjs.php @@ -174,11 +174,15 @@ protected function prepareSend() if (count($customVariables) > 0) { foreach ($customVariables as $customVariable) { - $index = $customVariable->getIndex(); - $key = 'dimension' . $index; - $value = $customVariable->getValue(); - - $parameters[$key] = $value; + if ($customVariable->getOverride()) { + $parameters[$customVariable->getName()] = $customVariable->getValue(); + } else { + $index = $customVariable->getIndex(); + $key = 'dimension' . $index; + $value = $customVariable->getValue(); + + $parameters[$key] = $value; + } } }