From 132f0957b8f100170e99291fb6642b8e2b4013b4 Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Tue, 17 Jan 2017 10:58:15 +0100 Subject: [PATCH] Google analytics: fix analytics id extraction for new kind of GA scripts --- VERSIONS_HOTLINE/52069 | 1 + library/Class/AdminVar/JsStat.php | 6 ++++-- .../WebService/WebAnalyticsClientTest.php | 21 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 VERSIONS_HOTLINE/52069 diff --git a/VERSIONS_HOTLINE/52069 b/VERSIONS_HOTLINE/52069 new file mode 100644 index 00000000000..4fdcfe23e42 --- /dev/null +++ b/VERSIONS_HOTLINE/52069 @@ -0,0 +1 @@ + - ticket #52069 : correction de la récupération du Google Analytics ID pour les nouveaux scripts Google Analytics \ No newline at end of file diff --git a/library/Class/AdminVar/JsStat.php b/library/Class/AdminVar/JsStat.php index df01369e2a9..50e54c37623 100644 --- a/library/Class/AdminVar/JsStat.php +++ b/library/Class/AdminVar/JsStat.php @@ -60,8 +60,10 @@ class Class_AdminVar_JsStat { protected function _getGoogleAnalyticsId() { $script = Class_AdminVar::get('JS_STAT'); - preg_match_all("/setAccount[\', \n\t]+\'([^\']+)\'/i", $script, $matches); - return isset($matches[1][0]) ? $matches[1][0] : ''; + preg_match_all("/(UA|MO)-[0-9]+-[0-9]/", $script, $matches); + return (isset($matches[0][0])) + ? $matches[0][0] + : ''; } diff --git a/tests/library/Class/WebService/WebAnalyticsClientTest.php b/tests/library/Class/WebService/WebAnalyticsClientTest.php index a546d1b847c..83d660d9d85 100644 --- a/tests/library/Class/WebService/WebAnalyticsClientTest.php +++ b/tests/library/Class/WebService/WebAnalyticsClientTest.php @@ -59,6 +59,27 @@ class Class_WebService_WebAnalyticsClientInstanciationWithVarGoogleAnalyticsAndN +class Class_WebService_WebAnalyticsClientInstanciationWithVarGoogleAnalyticsUsingGACreateTest extends Storm_Test_ModelTestCase { + public function setUp() { + parent::setUp(); + + Class_AdminVar::newInstanceWithId('JS_STAT', ['valeur' => "['_setaccount', 'a('create', 'UA-41754005-1', 'auto'); "]); + Class_AdminVar::newInstanceWithId('NOM_DOMAINE', ['valeur' => ""]); + + $this->_web_analytics_client = new Class_WebService_Analytics_Client(); + } + + + /** @test */ + public function trackerAccountIdShouldBeUA_41754005_1() { + $this->assertEquals('UA-41754005-1', $this->_web_analytics_client->getTrackerAccountId()); + } + +} + + + + class Class_WebService_WebAnalyticsClientInstanciationWithVarGoogleAnalyticsAndDomainNameTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); -- GitLab