EandrewJones commented on issue #266:
URL: 
https://github.com/apache/incubator-flagon-useralejs/issues/266#issuecomment-1186071026

   @kevbrowndev @poorejc Here are the modifications I made  to packageLog.js in 
my build. 
   
   I wrote a function `buildDatasets` that creates an array of data-attributes 
maps for the event target and all elements in the path to that target. Then I 
added it to the log object in the primary export function, `packageLog`:
   
   ```
   /**
    * Transforms the provided HTML event into a log and appends it to the log 
queue.
    * @param  {Object} e         The event to be logged.
    * @param  {Function} detailFcn The function to extract additional log 
parameters from the event.
    * @return {boolean}           Whether the event was logged.
    */
   export function packageLog(e, detailFcn) {
     if (!config.on) {
       return false;
     }
   
     let details = null;
     if (detailFcn) {
       details = detailFcn(e);
     }
   
     const timeFields = extractTimeFields(
       e.timeStamp && e.timeStamp > 0 ? config.time(e.timeStamp) : Date.now()
     );
   
     let log = {
       target: getSelector(e.target),
       path: buildPath(e),
       datasets: buildDatasets(e),
       pageUrl: window.location.href,
       pageTitle: document.title,
       pageReferrer: document.referrer,
       browser: detectBrowser(),
       clientTime: timeFields.milli,
       microTime: timeFields.micro,
       location: getLocation(e),
       scrnRes: getSreenRes(),
       type: e.type,
       logType: "raw",
       userAction: true,
       details: details,
       userId: config.userId,
       toolVersion: config.version,
       toolName: config.toolName,
       useraleVersion: config.useraleVersion,
       sessionID: config.sessionID,
     };
   
     if (typeof filterHandler === "function" && !filterHandler(log)) {
       return false;
     }
   
     if (typeof mapHandler === "function") {
       log = mapHandler(log, e);
     }
   
     logs.push(log);
   
     return true;
   }
   
   ...
   
   /**
    * Builds an array of data-attribute maps for all the event target and all 
elements
    * in the path to the target.
    * @param {Object} e Event from which the data-attrbute array should be 
built.
    * @returns {HTMLEelement[]} Array of maps for target and all ancestors, if 
they exist.
    */
   export function buildDatasets(e) {
     let datasets = [];
     let ele = e.target;
     while (ele) {
       if (ele.dataset && Object.keys(ele.dataset).length > 0) {
         datasets.push(ele.dataset);
       }
       ele = ele.parentElement;
     }
   
     return datasets;
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@flagon.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to