Browse Source

added pixik js event tracking

Bachir Soussi Chiadmi 7 years ago
parent
commit
7356c6cec6

+ 118 - 3
sites/all/modules/figli/edlp_search/assets/dist/scripts/edlp_search.min.js

@@ -1,4 +1,119 @@
+(function ($, Drupal, drupalSettings) {
 
-(function($,Drupal,drupalSettings){var settings=drupalSettings.edlp_search;var _$body=$('body');var _$container;var _$form;function init(){initEvents();initAjax();};function initEvents(){$('body').on('new-content-ajax-loaded',initAjax).on('edlp_search_search_form-col-closed',onSearchClosed);};function initAjax(){_$form=$('#edlp-search-form:not(.ajax-enabled)');if(!_$form.length)return false;_$form=$('#edlp-search-form:not(.ajax-enabled)').on('submit',onSubmitForm).addClass('ajax-enabled');_$container=_$form.parents('.row');if(!_$container.length){_$container=_$form.parent();}};function onSubmitForm(e){e.preventDefault();var args={};args.keys=$('input[type="search"]',this).val();args.entries=[];$('input[type="checkbox"]:checked','#edit-entries').each(function(index,el){args.entries.push($(this).val());});args.langues=$('input[name="language"]',this).val();args.genres=$('input[name="genres"]',this).val();loadResults(args);return false;};function loadResults(args){_$form.addClass('ajax-loading');_$body.addClass('ajax-loading');$('[theme="edlp_search_results"]',_$container).addClass('ajax-loading');var path=window.location.origin+drupalSettings.path.baseUrl+settings.results_ajax_url;$.getJSON(path,args).done(function(data){onResultsLoaded(data);}).fail(function(jqxhr,textStatus,error){onResultsLoadFail(jqxhr,textStatus,error);});};function onResultsLoaded(data){_$form.removeClass('ajax-loading');_$body.removeClass('ajax-loading');$prev_results=$('[theme="edlp_search_results"]',_$container);if($prev_results.length){$prev_results.replaceWith(data.rendered);}else{_$container.append(data.rendered);}
-_$body.trigger({'type':'search-results-loaded','results':data.results_nids});};function onResultsLoadFail(jqxhr,textStatus,error){void 0;};function onSearchClosed(e){$('div[theme="edlp_search_results"]').remove();_$body.trigger({'type':'search-closed'});}
-init();})(jQuery,Drupal,drupalSettings);
+  var settings = drupalSettings.edlp_search;
+  var _$body = $('body');
+  var _$container;
+  var _$form;
+
+  function init(){
+    // console.log('EdlpSearch Init', settings);
+    initEvents();
+    initAjax();
+  };
+
+  function initEvents(){
+    $('body')
+      .on('new-content-ajax-loaded', initAjax)
+      .on('edlp_search_search_form-col-closed', onSearchClosed);
+  };
+
+  function initAjax(){
+    _$form = $('#edlp-search-form:not(.ajax-enabled)');
+    if(!_$form.length) return false;
+
+    //console.log('EdlpSearch initAjaxForm()');
+    _$form = $('#edlp-search-form:not(.ajax-enabled)')
+      .on('submit', onSubmitForm)
+      .addClass('ajax-enabled');
+    _$container = _$form.parents('.row');
+    if(!_$container.length){
+      _$container = _$form.parent();
+    }
+  };
+
+  function onSubmitForm(e){
+    e.preventDefault();
+    // console.log('onSubmitForm',e);
+    var args = {};
+
+    // search for key words
+    args.keys = $('input[type="search"]', this).val();
+
+    // entries filter
+    args.entries = [];
+    $('input[type="checkbox"]:checked', '#edit-entries').each(function(index, el) {
+      args.entries.push($(this).val());
+    });
+
+    // langues
+    args.langues = $('input[name="language"]', this).val();
+
+    // genres
+    args.genres = $('input[name="genres"]', this).val();
+
+    //console.log('EdlpSearch onSubmitForm() : args',args);
+
+    loadResults(args);
+
+    return false;
+  };
+
+  function loadResults(args){
+    //console.log('EdlpSearch loadResults() : args', args);
+    _$form.addClass('ajax-loading');
+    _$body.addClass('ajax-loading');
+    $('[theme="edlp_search_results"]', _$container).addClass('ajax-loading');
+    var path = window.location.origin + drupalSettings.path.baseUrl +settings.results_ajax_url;
+    $.getJSON(path, args)
+      .done(function(data){
+        onResultsLoaded(data);
+      })
+      .fail(function(jqxhr, textStatus, error){
+        onResultsLoadFail(jqxhr, textStatus, error);
+      });
+  };
+
+  function onResultsLoaded(data){
+    // console.log('EdlpSearch onResultsLoaded()', data);
+    _$form.removeClass('ajax-loading');
+    _$body.removeClass('ajax-loading');
+
+    // insert results col
+    $prev_results = $('[theme="edlp_search_results"]', _$container);
+    if($prev_results.length){
+      $prev_results.replaceWith(data.rendered);
+    }else{
+      _$container.append(data.rendered);
+    }
+
+    // trigger event
+    _$body.trigger({
+      'type':'search-results-loaded',
+      'results':data.results_nids
+    });
+
+
+    // piwik
+    if(typeof _paq !== 'undefined'){
+      // trackEvent(category, action, [name], [value])
+      var search_name = 'keys:'+data.keys
+        +';langues:'+data.langues
+        +';genres:'+data.genres
+        +';entries:'+data.entry_names.join(',');
+      _paq.push(['trackEvent', 'AjaxSearch', 'Results', search_name, data.results_nids.length]);
+    }
+  };
+
+  function onResultsLoadFail(jqxhr, textStatus, error){
+    console.warn('EdlpSearch : search results ajax load failed : '+error, jqxhr.responseText);
+  };
+
+  function onSearchClosed(e){
+    // console.log('Edlp Search onSearchClosed()');
+    $('div[theme="edlp_search_results"]').remove();
+    // trigger event
+    _$body.trigger({'type':'search-closed'});
+  }
+
+  init();
+})(jQuery, Drupal, drupalSettings);

+ 10 - 0
sites/all/modules/figli/edlp_search/assets/scripts/edlp_search.js

@@ -92,6 +92,16 @@
       'results':data.results_nids
     });
 
+
+    // piwik
+    if(typeof _paq !== 'undefined'){
+      // trackEvent(category, action, [name], [value])
+      var search_name = 'keys:'+data.keys
+        +';langues:'+data.langues
+        +';genres:'+data.genres
+        +';entries:'+data.entry_names.join(',');
+      _paq.push(['trackEvent', 'AjaxSearch', 'Results', search_name, data.results_nids.length]);
+    }
   };
 
   function onResultsLoadFail(jqxhr, textStatus, error){

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

@@ -249,6 +249,9 @@ class EdlpSearchController extends ControllerBase {
       'test'=>'search results',
       'keys'=>$this->keys,
       'entries' => $this->entries,
+      'entry_names' => $this->entry_names,
+      'langues' => $this->langues,
+      'genres' => $this->genres,
       'rendered'=> $rendered,
       'results_nids'=>$results_nids,
     ]);
@@ -326,9 +329,12 @@ class EdlpSearchController extends ControllerBase {
 
     // entries
     if (!empty($this->entries)){
+      $terms = entity_load_multiple('taxonomy_term', $this->entries);
+      $this->entry_names = [];
       $entries_condition_group = $query->createConditionGroup();
-      foreach ($this->entries as $tid) {
+      foreach ($terms as $tid => $term) {
         $entries_condition_group->addCondition('field_entrees', (int)$tid, "=");
+        $this->entry_names[] = $term->getName();
       }
       // dpm($entries_condition_group);
       $query->addConditionGroup($entries_condition_group);

+ 19 - 1
sites/all/themes/custom/edlptheme/assets/dist/scripts/history.min.js

@@ -1,2 +1,20 @@
+console.log('EDLP THEME HISTORY.js');
+// var edlp is provided by edlp_ajax.module file
+if(edlp.redirect){
+  console.log('history redirect', edlp);
+  console.log('window.location', window.location);
+  // window.localStorage.setItem('edlp_origin_path', edlp.sys_path.replace(/^\//, ''));
+  edlp.sys_path = edlp.sys_path.replace(/^\//, '');
 
-void 0;if(edlp.redirect){void 0;void 0;edlp.sys_path=edlp.sys_path.replace(/^\//,'');edlp.url=window.location.pathname;edlp.hash=window.location.hash;window.localStorage.setItem('edlp_origin',JSON.stringify(edlp));window.location.replace(window.location.origin+'/'+edlp.lang_code);}else{void 0;}
+  // window.localStorage.setItem('edlp_origin_url', window.location.pathname);
+  edlp.url = window.location.pathname;
+
+  // window.localStorage.setItem('edlp_origin_hash', window.location.hash);
+  edlp.hash = window.location.hash;
+
+  window.localStorage.setItem('edlp_origin', JSON.stringify(edlp));
+  // redirect to home
+  window.location.replace(window.location.origin+'/'+edlp.lang_code);
+}else{
+  console.log('history do not redirect');
+}

File diff suppressed because it is too large
+ 1 - 29
sites/all/themes/custom/edlptheme/assets/dist/scripts/main.min.js


File diff suppressed because it is too large
+ 0 - 0
sites/all/themes/custom/edlptheme/assets/dist/styles/app.min.css


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

@@ -299,6 +299,12 @@
         // console.log(window.location);
         // /!\ we can not pushestate with absolute url /!\
         history.pushState(state, null, state.url);
+
+        // piwik
+        if(typeof _paq !== 'undefined'){
+          // trackEvent(category, action, [name], [value])
+          _paq.push(['trackEvent', 'AjaxNav', 'loaded', state.url]);
+        }
       }
     };
 

Some files were not shown because too many files changed in this diff