From 9e54ccb99414dbe35688abc1d59c8e9f0fd1038e Mon Sep 17 00:00:00 2001 From: Reto Kaiser Date: Thu, 19 Feb 2015 16:53:26 +0100 Subject: [PATCH 1/2] Make Trackings::getTrackingServiceList() public --- library/CM/Service/Trackings.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/library/CM/Service/Trackings.php b/library/CM/Service/Trackings.php index 21d7d760c..abf7cb826 100644 --- a/library/CM/Service/Trackings.php +++ b/library/CM/Service/Trackings.php @@ -14,7 +14,7 @@ public function __construct(array $trackingServiceNameList) { public function getHtml(CM_Frontend_Environment $environment) { $html = ''; - foreach ($this->_getTrackingServiceList() as $trackingService) { + foreach ($this->getTrackingServiceList() as $trackingService) { $html .= $trackingService->getHtml($environment); } return $html; @@ -22,32 +22,32 @@ public function getHtml(CM_Frontend_Environment $environment) { public function getJs() { $js = ''; - foreach ($this->_getTrackingServiceList() as $trackingService) { + foreach ($this->getTrackingServiceList() as $trackingService) { $js .= $trackingService->getJs(); } return $js; } public function trackAction(CM_Action_Abstract $action) { - foreach ($this->_getTrackingServiceList() as $trackingService) { + foreach ($this->getTrackingServiceList() as $trackingService) { $trackingService->trackAction($action); } } public function trackAffiliate($requestClientId, $affiliateName) { - foreach ($this->_getTrackingServiceList() as $trackingService) { + foreach ($this->getTrackingServiceList() as $trackingService) { $trackingService->trackAffiliate($requestClientId, $affiliateName); } } public function trackPageView(CM_Frontend_Environment $environment, $path) { - foreach ($this->_getTrackingServiceList() as $trackingService) { + foreach ($this->getTrackingServiceList() as $trackingService) { $trackingService->trackPageView($environment, $path); } } public function trackSplittest(CM_Splittest_Fixture $fixture, CM_Model_SplittestVariation $variation) { - foreach ($this->_getTrackingServiceList() as $trackingService) { + foreach ($this->getTrackingServiceList() as $trackingService) { $trackingService->trackSplittest($fixture, $variation); } } @@ -55,7 +55,7 @@ public function trackSplittest(CM_Splittest_Fixture $fixture, CM_Model_Splittest /** * @return CM_Service_Tracking_ClientInterface[] */ - protected function _getTrackingServiceList() { + public function getTrackingServiceList() { return array_map(function ($trackingServiceName) { return $this->getServiceManager()->get($trackingServiceName, 'CM_Service_Tracking_ClientInterface'); }, $this->_trackingServiceNameList); From bffca9dd8b7b76bb1285a5eaa609c7282758772b Mon Sep 17 00:00:00 2001 From: Reto Kaiser Date: Thu, 19 Feb 2015 16:55:53 +0100 Subject: [PATCH 2/2] Add MP::getRandomClientId() --- .../GoogleAnalytics/MeasurementProtocol/Client.php | 7 +++++++ .../GoogleAnalytics/MeasurementProtocol/ClientTest.php | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/library/CMService/GoogleAnalytics/MeasurementProtocol/Client.php b/library/CMService/GoogleAnalytics/MeasurementProtocol/Client.php index 22e7a7781..34d21e4a4 100644 --- a/library/CMService/GoogleAnalytics/MeasurementProtocol/Client.php +++ b/library/CMService/GoogleAnalytics/MeasurementProtocol/Client.php @@ -41,6 +41,13 @@ public function trackEvent(array $parameterList) { $this->trackHit($this->_parseParameterList($parameterList)); } + /** + * @return string + */ + public function getRandomClientId() { + return rand() . uniqid(); + } + /** * @param array $parameterList */ diff --git a/tests/library/CMService/GoogleAnalytics/MeasurementProtocol/ClientTest.php b/tests/library/CMService/GoogleAnalytics/MeasurementProtocol/ClientTest.php index ab5ae659d..b80c7e269 100644 --- a/tests/library/CMService/GoogleAnalytics/MeasurementProtocol/ClientTest.php +++ b/tests/library/CMService/GoogleAnalytics/MeasurementProtocol/ClientTest.php @@ -68,4 +68,12 @@ public function testTrackEventParamForWrongHitType() { 'exd' => 'My exception', ]); } + + public function testGetRandomClientId() { + $client = new CMService_GoogleAnalytics_MeasurementProtocol_Client('foo'); + + $this->assertInternalType('string', $client->getRandomClientId()); + $this->assertGreaterThan(5, strlen($client->getRandomClientId())); + $this->assertNotEquals($client->getRandomClientId(), $client->getRandomClientId()); + } }