Intercept and repropagate client clicks

0
Hi For custom GA/GTM we need to send data from the web client to their metrics thing. We have a code mirror for runtime configurable on page change behavior and a widget for attaching that once as an extra to the form change function so custom stuff can be done like acquiring client data and forwarding to GA/GTM I would like to know how to intercept and repropogate the click events to do custom stuff for clicking sample code   try{ typeof(cf)=='undefined'?cf=mx.ui.getContentForm():null; if(cf._onNavigation==null){ console.log('Adding Custom GTM'); //------------------------------------------------------------------------------ //util obj //------------------------------------------------------------------------------ var _ga={}; _ga.dstart=function(f){ try{ //https://stackoverflow.com/questions/21855401/intercept-a-click-make-some-actions-and-then-propagate-click-again?rq=1 //$(document).on("click",f); $(document).on("mousedown",f); }catch(e){ _ga.log(e); }finally{ } } _ga.dstop=function(f){ try{ //https://stackoverflow.com/questions/21855401/intercept-a-click-make-some-actions-and-then-propagate-click-again?rq=1 //$(document).off("click",f); $(document).off("mousedown",f); }catch(e){ _ga.log(e); }finally{ } } _ga.dstopall=function(f){ try{ Object.keys(_ga.pagemap).forEach(function(k,kidx){ _ga.log("Removing function for "+k+"..."); try{ _ga.dstop(_ga.pagemap[k]["delegator"]); }catch(e){ _ga.log(e); }finally{ } }); }catch(e){ _ga.log(e); }finally{ } } _ga.log=function(a){ console.log('GA:'+(new Date().getTime())+': '+a); } // // ... // ... // ... // //------------------------------------------------------------------------------ //setup page objs/handlers //------------------------------------------------------------------------------ _ga.pagemap={}; _ga.pagemap["Nashorn/pg_JS_ov.page.xml"]={}; _ga.pagemap["Nashorn/pg_JS_ov.page.xml"]["delegator"]=function(e){ console.log( "GA: //--------------\n"+ "GA: //INTERCEPTED!!!\n"+ "GA: //--------------" ); if(e.target&&e.target.tagName=="BUTTON"){ if(e.target.classList.contains('mx-name-actionButton12')){ console.log("GA:"+(new Date().getTime())+": "+"BUTTON MAPPED[DUP]"); }else if(e.target.classList.contains('mx-name-searchButton1')){ console.log("GA:"+(new Date().getTime())+": "+"BUTTON MAPPED[SEARCH]"); }else{ console.log("GA:"+(new Date().getTime())+": "+"BUTTON UNMAPPED"); } }else{ console.error("GA:"+(new Date().getTime())+": "+"NOT BUTTON"); } }; // // ... // ... // ... // //------------------------------------------------------------------------------ //page change handler //------------------------------------------------------------------------------ _ga.pagechangehandler=function(){ if(_ga.pagemap[mx.ui.getContentForm().path]!=null){ try{ _ga.log("Mapped page"); _ga.log("Removing functions..."); _ga.dstopall(); _ga.log("Attaching function for "+_ga.pagemap[mx.ui.getContentForm().path]+"..."); _ga.dstart(_ga.pagemap[mx.ui.getContentForm().path]["delegator"]); }catch(e){ _ga.log(e) }finally{} }else{ _ga.dstopall(); _ga.log("Unmapped page"); } } //------------------------------------------------------------------------------ //attach handler //------------------------------------------------------------------------------ // // ... // ... // ... // cf._onNavigation=cf.onNavigation; cf.onNavigation=dojo.hitch(cf,function(){ _ga.pagechangehandler(); cf._onNavigation(); }); }else{ console.log('Custom GTM Already Added'); } }catch(e){ console.error(e); }finally{ } mousedown works better, but also has its drawbacks
asked
0 answers