Browse Source

added entree page tracking, added title to ajax response for tracking (production, agenda, search)

Bachir Soussi Chiadmi 6 years ago
parent
commit
f7225cdd01

+ 2 - 1
sites/all/modules/figli/edlp_agenda/src/Controller/AgendaController.php

@@ -79,7 +79,8 @@ class AgendaController extends ControllerBase {
     });
 
     $data = [
-      'rendered'=> $rendered
+      'rendered'=> $rendered,
+      'title'=>'Agenda',
     ];
 
     // translations links

+ 16 - 1
sites/all/modules/figli/edlp_corpus/assets/dist/scripts/corpus.min.js

@@ -662,13 +662,20 @@
       var $li = $link.parents('li');
       var sys_path = $link.attr('data-drupal-link-system-path');
       var url = $link.attr('href');
+      var title = $link.text();
       if(!$li.is('.opened')){
         _$entrees_block_termlinks.parents('li').removeClass('opened');
         $li.addClass('opened');
         $li.parents('.item-list').addClass('opened')
         filterEntree(tid);
         if(bubbling){
-          _$body.trigger({'type':'open_entree', 'tid':tid, 'url':url, 'sys_path':sys_path});
+          _$body.trigger({
+            'type':'open_entree',
+            'tid':tid,
+            'url':url,
+            'sys_path':sys_path,
+            'title':title
+          });
         }
       // bubbling is true only when event is a real click on entree link
       }else if(bubbling){
@@ -800,6 +807,10 @@
         _no_articles_nodes[i].fade();
       }
       updateRandomPlaylist(_articles_nodes);
+      if(typeof _paq !== 'undefined'){
+        // trackEvent(category, action, [name], [value])
+        _paq.push(['trackEvent', 'Corpus Articles', 'on']);
+      }
     };
     function deactivateArticlesFilter(){
       //console.log('deactivateArticlesFilter');
@@ -808,6 +819,10 @@
         _no_articles_nodes[i].unFade();
       }
       updateRandomPlaylist(_playlist);
+      if(typeof _paq !== 'undefined'){
+        // trackEvent(category, action, [name], [value])
+        _paq.push(['trackEvent', 'Corpus Articles', 'off']);
+      }
     };
     function shutDownArticles(){
       // shutdown articles if active

+ 16 - 1
sites/all/modules/figli/edlp_corpus/assets/scripts/corpus.js

@@ -662,13 +662,20 @@
       var $li = $link.parents('li');
       var sys_path = $link.attr('data-drupal-link-system-path');
       var url = $link.attr('href');
+      var title = $link.text();
       if(!$li.is('.opened')){
         _$entrees_block_termlinks.parents('li').removeClass('opened');
         $li.addClass('opened');
         $li.parents('.item-list').addClass('opened')
         filterEntree(tid);
         if(bubbling){
-          _$body.trigger({'type':'open_entree', 'tid':tid, 'url':url, 'sys_path':sys_path});
+          _$body.trigger({
+            'type':'open_entree',
+            'tid':tid,
+            'url':url,
+            'sys_path':sys_path,
+            'title':title
+          });
         }
       // bubbling is true only when event is a real click on entree link
       }else if(bubbling){
@@ -800,6 +807,10 @@
         _no_articles_nodes[i].fade();
       }
       updateRandomPlaylist(_articles_nodes);
+      if(typeof _paq !== 'undefined'){
+        // trackEvent(category, action, [name], [value])
+        _paq.push(['trackEvent', 'Corpus Articles', 'on']);
+      }
     };
     function deactivateArticlesFilter(){
       //console.log('deactivateArticlesFilter');
@@ -808,6 +819,10 @@
         _no_articles_nodes[i].unFade();
       }
       updateRandomPlaylist(_playlist);
+      if(typeof _paq !== 'undefined'){
+        // trackEvent(category, action, [name], [value])
+        _paq.push(['trackEvent', 'Corpus Articles', 'off']);
+      }
     };
     function shutDownArticles(){
       // shutdown articles if active

+ 2 - 1
sites/all/modules/figli/edlp_productions/src/Controller/ProductionsController.php

@@ -102,6 +102,7 @@ class ProductionsController extends ControllerBase {
 
     $data = [
       'rendered'=> $rendered,
+      'title'=> 'Productions',
       // 'block' => array(
       //   'rendered'=> \Drupal::service('renderer')->renderRoot($block_render),
       //   'region'=> str_replace('_', '-', $block->getRegion()),
@@ -120,7 +121,7 @@ class ProductionsController extends ControllerBase {
         '#set_active_class' => TRUE,
       ];
       $translations_rendered = \Drupal::service('renderer')->executeInRenderContext(new RenderContext(), function () use ($translations_build) {return render($translations_build);});
-      
+
       $data ['translations_links'] = $translations_rendered;
     }
 

+ 2 - 1
sites/all/modules/figli/edlp_search/src/Controller/EdlpSearchController.php

@@ -78,7 +78,8 @@ class EdlpSearchController extends ControllerBase {
 
     $rendered = render($this->renderable);
     $data = [
-      'rendered' => $rendered
+      'rendered' => $rendered,
+      'title' => 'Search',
     ];
 
     // translations links

+ 12 - 0
sites/all/themes/custom/edlptheme/assets/dist/scripts/main.min.js

@@ -79,6 +79,18 @@
             // };
             var state = getSysPathState(e.sys_path);
             history.pushState(state, null, e.url);
+
+            // piwik
+            if(typeof _paq !== 'undefined'){
+              // page tracking
+              // https://matomo.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
+              _paq.push(['setCustomUrl', e.url]);
+              _paq.push(['setDocumentTitle', e.title]);
+              _paq.push(['trackPageView']);
+              // js event
+              // trackEvent(category, action, [name], [value])
+              // _paq.push(['trackEvent', 'AjaxNav', 'loaded', state.url]);
+            }
           }
         })
         .on('close_entree', function(e){

+ 12 - 0
sites/all/themes/custom/edlptheme/assets/scripts/main.js

@@ -79,6 +79,18 @@
             // };
             var state = getSysPathState(e.sys_path);
             history.pushState(state, null, e.url);
+
+            // piwik
+            if(typeof _paq !== 'undefined'){
+              // page tracking
+              // https://matomo.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
+              _paq.push(['setCustomUrl', e.url]);
+              _paq.push(['setDocumentTitle', e.title]);
+              _paq.push(['trackPageView']);
+              // js event
+              // trackEvent(category, action, [name], [value])
+              // _paq.push(['trackEvent', 'AjaxNav', 'loaded', state.url]);
+            }
           }
         })
         .on('close_entree', function(e){