From: vincent@cubedesigners.com Date: Tue, 8 Sep 2015 09:12:24 +0000 (+0000) Subject: Add event tracking on some buttons (emails, phone, map, social, external links) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=645dcae4775b9c86ab5620fa007eba1bf7dae46a;p=cubedesigners-v7.git Add event tracking on some buttons (emails, phone, map, social, external links) --- diff --git a/framework/application/views/helpers/FooterContact.php b/framework/application/views/helpers/FooterContact.php index fca2e59..e56fa69 100644 --- a/framework/application/views/helpers/FooterContact.php +++ b/framework/application/views/helpers/FooterContact.php @@ -12,29 +12,31 @@ class Cubedesigners_View_Helper_FooterContact extends Zend_View_Helper_Abstract foreach ($bureaux as $bureau) { - $res.='
'; + $res .= '
'; - $res.='

' . $bureau['coordonnees']['nom'] . '

'; + $res .= '

' . $bureau['coordonnees']['nom'] . '

'; - $res.='

'; - $res.='

' . __('Tel') . ' ' . $this->view->linkPhone($bureau['coordonnees']['tel']) . '

'; + $res .= '
'; + $event = array('category' => 'phone', 'action' => 'call', 'label' => $bureau['coordonnees']['tel']); + $res .= '

' . __('Tel') . ' ' . $this->view->linkPhone($bureau['coordonnees']['tel'], null, array('data-event' => $event)) . '

'; //$res.='

' . __('Fax') . ' ' . $this->view->linkPhone($bureau['coordonnees']['fax']) . '

'; - $res.='
'; + $res .= '
'; //$res.= $this->view->microdataPlace($bureau['coordonnees']['adresse']); - $res.='
'; - $res.='

' . __('Cubedesigners') . '

'; - $res.='

' . $bureau['coordonnees']['adresse'] . '

'; - $res.='

' . $bureau['coordonnees']['code_postal'] . ' ' . $bureau['coordonnees']['ville'] . '

'; - $res.='

' . Zend_Locale::getTranslation($bureau['coordonnees']['pays'], 'territory') . '

'; - $res.='

'; + $res .= '
'; + $res .= '

' . __('Cubedesigners') . '

'; + $res .= '

' . $bureau['coordonnees']['adresse'] . '

'; + $res .= '

' . $bureau['coordonnees']['code_postal'] . ' ' . $bureau['coordonnees']['ville'] . '

'; + $res .= '

' . Zend_Locale::getTranslation($bureau['coordonnees']['pays'], 'territory') . '

'; + $res .= '

'; - $res.='
'; - $res.=$this->view->linkGeo(__("Plan d'accès"), $bureau['coordonnees']['adresse'] . ',' . $bureau['coordonnees']['ville'] . ',' . Zend_Locale::getTranslation($bureau['coordonnees']['pays'], 'territory'), array('class' => 'but')); - $res.='
'; + $res .= '
'; + $event = array('category' => 'map', 'action' => 'click', 'label' => $bureau['coordonnees']['ville']); + $res .= $this->view->linkGeo(__("Plan d'accès"), $bureau['coordonnees']['adresse'] . ',' . $bureau['coordonnees']['ville'] . ',' . Zend_Locale::getTranslation($bureau['coordonnees']['pays'], 'territory'), array('class' => 'but', 'data-event' => $event)); + $res .= '
'; - $res.='
'; + $res .= '
'; } return $res; diff --git a/framework/application/views/helpers/FooterSocials.php b/framework/application/views/helpers/FooterSocials.php index 0bfad05..d222a3b 100644 --- a/framework/application/views/helpers/FooterSocials.php +++ b/framework/application/views/helpers/FooterSocials.php @@ -11,9 +11,10 @@ class Cubedesigners_View_Helper_FooterSocials extends CubeIT_View_Helper_Abstrac $res = '
'; foreach ($socials as $id => $social) { $image = $this->view->imageCms($social['picto'], $social['titre'], 25, 25); - $res.=$this->link($image, $social['url'], array('class' => 'social', 'data-color' => $social['color'])); + $event = array('category' => 'social', 'action' => 'go', 'label' => $social['titre']); + $res .= $this->link($image, $social['url'], array('class' => 'social', 'data-color' => $social['color'], 'data-event' => $event)); } - $res.= '
'; + $res .= ''; return $res; } diff --git a/framework/application/views/helpers/Realisation.php b/framework/application/views/helpers/Realisation.php index 524e5fc..00b38e8 100644 --- a/framework/application/views/helpers/Realisation.php +++ b/framework/application/views/helpers/Realisation.php @@ -30,19 +30,19 @@ class Cubedesigners_View_Helper_Realisation extends CubeIT_View_Helper_Abstract $res .= $this->imageSlideshowScroll($slides, 439, array(), array('shortcuts' => false)); $res .= '
'; - $res .= '

' . $r->titre . '

'; - $res .= ''; + $res .= '

' . $r->titre . '

'; + $res .= ''; - $res .= $this->markupDotclear($r->description); + $res .= $this->markupDotclear($r->description); - if (!empty($r->url->url)) { - $res .= $this->_button($r->url); - } + if (!empty($r->url->url)) { + $res .= $this->_button($r->url); + } - $res .= '
'; + $res .= ''; $res .= ''; return $res; @@ -54,7 +54,9 @@ class Cubedesigners_View_Helper_Realisation extends CubeIT_View_Helper_Abstract if ($b['label'] == '') { $b['label'] = __('Voir le site'); } - return $this->linkCMS($b, array('class' => 'but')); + + $event = array('category' => 'external', 'action' => 'go', 'label' => "%href%"); + return $this->linkCMS($b, array('class' => 'but', 'data-event' => $event)); } } diff --git a/js/common.js b/js/common.js index e111d24..e1c85ea 100644 --- a/js/common.js +++ b/js/common.js @@ -1,4 +1,49 @@ registerLoader(load_commons); +registerLoader(load_commons_once, true); + +function load_commons_once() { + + + $('a[href^="mailto:"]').not('[data-event]').each(function () { + var email = $(this).attr('href').split(':'); + var label = email.pop(); + var e = { + category: 'email', + action: 'click', + label: label, + value: 1 + }; + $(this).attr('data-event', JSON.stringify(e)); + }); + + $('a[href^="tel:"]').not('[data-event]').each(function () { + var tel = $(this).attr('href').split(':'); + var label = tel.pop(); + + var e = { + category: 'tel', + action: 'call', + label: label, + value: 1 + }; + $(this).attr('data-event', JSON.stringify(e)); + }); + + $(document).on('click', '[data-event]', function () { + var e = $(this).data('event'); + if (e.value === undefined) { + e.value = 1; + } + if (e.action === undefined) { + e.action = 'click'; + } + + e.label = e.label.replace(/%href%/gi, $(this).attr('href')); + + ga('send', 'event', e.category, e.action, e.label, e.value); + return true; + }); +} function load_commons() { $(window).on('cubeitresize', resize); @@ -18,6 +63,7 @@ function load_commons() { return false; }); + // Fallback to display content in case web fonts haven't triggered the display yet setTimeout(function () { $('html').addClass('wf-active');