Skip to content
Snippets Groups Projects
Commit acd3b7c2 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

Merge branch 'hotline#105003_evenements_matomo_plus_visibles' into 'hotline'

hotline#105003 : Analytics : Events in Matomo were not received any longer -…

See merge request !3463
parents af258aab 0b8ea816
Branches
Tags
3 merge requests!3473Master,!3472Hotline,!3463hotline#105003 : Analytics : Events in Matomo were not received any longer -…
Pipeline #9843 passed with stage
in 43 minutes and 58 seconds
- ticket #105003 : Analytics : L'analyse par événement dans Matomo ne reçoit pas d'information
\ No newline at end of file
......@@ -20,13 +20,22 @@
*/
class Class_WebService_Analytics_MatomoTracker extends Class_WebService_Analytics_NullTracker {
protected static $_tracker_factory;
protected $_tracker;
/** @category testing */
public static function setTrackerFactory($factory) {
static::$_tracker_factory = $factory;
}
public function __construct($config) {
require_once('matomo-php-tracker/PiwikTracker.php');
$this->_config = $config;
$this->_tracker = new PiwikTracker($config->getTrackerId(),
$config->getMatomoUrl());
$this->_tracker = $this->_getTrackerFactory()
->newFor($config->getTrackerId(),
'https:' . $config->getMatomoUrl());
}
......@@ -44,6 +53,20 @@ class Class_WebService_Analytics_MatomoTracker extends Class_WebService_Analytic
$this->_tracker->doTrackEvent($category, $action, $label, $value);
return $this;
}
protected function _getTrackerFactory() {
return static::$_tracker_factory
? static::$_tracker_factory
: new Class_WebService_Analytics_MatomoTrackerFactory();
}
}
?>
\ No newline at end of file
class Class_WebService_Analytics_MatomoTrackerFactory {
public function newFor($id_site, $url) {
return new PiwikTracker($id_site, $url);
}
}
Subproject commit c635dc3b5ed656838d433ad5e373cb3487807185
Subproject commit 3b31a6366fdf1f39520d7cbf858967f309d89275
......@@ -328,4 +328,107 @@ _paq.push([\'enableLinkTracking\']);
public function iframeSrcShouldContainsIdSite9999() {
$this->assertXPath('//iframe[contains(@src, "idSite=9999")]');
}
}
\ No newline at end of file
}
class MatomoCheckUrlForEventTracking extends ModelTestCase {
protected $_matomo, $_tracker_factory;
public function setUp() {
parent::setUp();
Class_AdminVar::set('JS_STAT',"<!-- Piwik -->
<script type=\"text/javascript\">
try {
var url = window.location.href ;
var _paq = _paq || [];
if ( (url.match ( new RegExp ( \"/recherche/\" ) )) && ($('.resultats_page').length)) {
var customvartitle_total = \"nombre de résultats\" ;
var customvartitle_type = \"type de recherche\" ;
var customvartitle_motif = \"motif de recherche\" ;
var customvartitle_facette = \"facettes de recherche\" ;
var customvartitle_page = \"page\" ;
var customvarvalue_total;
var customvarvalue_type;
var customvarvalue_motif;
var customvarvalue_facette;
var customvarvalue_page;
if ($('.resultats_page .nombre-recherche').length) {
var customvarvalue_total = $('.resultats_page .nombre-recherche').html();
var regexcustomvarvalue_total = /\D/g ;
customvarvalue_total = customvarvalue_total.replace ( regexcustomvarvalue_total , '' ) ;
} else {
var customvarvalue_total = \"zéro\";
}
if (url.match ( new RegExp ( \"expressionRecherche\" ) )) {
var customvarvalue_type = \"simple\" ;
} else {
var customvarvalue_type = \"avancée\" ;
}
if (customvarvalue_type == \"simple\") {
if ($('.resultats_page .expression-recherche').length) {
var customvarvalue_motif = $('.resultats_page .expression-recherche').text();
}
if ($('.resultats_page .criteres_recherche').length) {
//var customvarvalue_facette = $('.resultats_page .criteres_recherche').text();
customvarvalue_facette = $('.resultats_page .criteres_recherche').html();
var regexaddsep = /<img/g ;
customvarvalue_facette = customvarvalue_facette.replace ( regexaddsep , '&nbsp;,&nbsp;<img' ) ;
customvarvalue_facette = $(customvarvalue_facette).text();
customvarvalue_facette = customvarvalue_facette.replace(/\s,\s$/,'');
}
}
else if (customvarvalue_type == \"avancée\") {
if ($('.resultats_page .criteres_recherche').length) {
//var customvarvalue_motif = $('.resultats_page .criteres_recherche').text();
customvarvalue_motif = $('.resultats_page .criteres_recherche').html();
var regexaddsep = /<img/g ;
customvarvalue_motif = customvarvalue_motif.replace ( regexaddsep , '&nbsp;,&nbsp;<img' ) ;
customvarvalue_motif = $(customvarvalue_motif).text();
customvarvalue_motif = customvarvalue_motif.replace(/\s,\s$/,'');
}
}
var regexcustomvarvalue_page = /\/page\/(\d+)/;
if (url.match ( new RegExp ( regexcustomvarvalue_page ) )) {
regexcustomvarvalue_page.exec(url);
customvarvalue_page=RegExp.$1;
}
if ( customvarvalue_total ) {_paq.push(['setCustomVariable', 1, customvartitle_total, customvarvalue_total, 'page']);}
if ( customvarvalue_type ) {_paq.push(['setCustomVariable', 2, customvartitle_type, customvarvalue_type, 'page']);}
if ( customvarvalue_motif ) {_paq.push(['setCustomVariable', 3, customvartitle_motif, customvarvalue_motif, 'page']);}
if ( customvarvalue_facette ) {_paq.push(['setCustomVariable', 4, customvartitle_facette, customvarvalue_facette, 'page']);}
if ( customvarvalue_page ) {_paq.push(['setCustomVariable', 5, customvartitle_page, customvarvalue_page, 'page']);}
}
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u=(\"http://tracker.analytics.afi-sa.net/\";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 2]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
} catch ( err ) {}
</script>
<noscript><p><img src=\"http://analytics.bokeh.com/piwik.php?idsite=42\" style=\"border:0;\" alt=\"\" /></p></noscript>
<!-- End Piwik Code -->");
$jsstat = new Class_AdminVar_JsStat();
$this->_tracker_factory = $this->mock()->whenCalled('newFor')->answers(null);
Class_WebService_Analytics_MatomoTracker::setTrackerFactory($this->_tracker_factory);
$this->_matomo = new Class_WebService_Analytics_MatomoTracker($jsstat);
}
public function tearDown() {
Class_WebService_Analytics_MatomoTracker::setTrackerFactory(null);
parent::tearDown();
}
/** @test */
public function onConstructShouldProvideUrlWithHttpsToThirdPartyLibrary() {
$this->assertEquals('https://tracker.analytics.afi-sa.net/',
$this->_tracker_factory->getAttributesForLastCallOn('newFor')[1]);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment