function updateHeroEvents() {
  for (i = 0; i < array.settings.numberHeroUsers; i++) {
    var Id = '#hero-0' + (i+1) + '-events';
    var sessions = [];
    $(Id).find('.slds-expression__group').each(function() {
      var sessionEvents = [];
      var eventTime = new Date($(this).find('input[type="datetime-local"]').val());
      var sessionLen = $(this).find('.slds-expression__row').length;
      $(this).find('.slds-expression__row').each(function() {
        var actionType = $(this).find('select[role="event-action-type"]').find('option:selected').attr('value');
        var viewTime = parseInt($(this).find('input[role="event-time"]').val()*1000);
        if(actionType=='Custom'){
          var actionType = $(this).find('input[role="event-item-custom"]').val();
          sessionEvents.push({"userAction": actionType, "viewTime":viewTime});
        } else if(actionType=='Page View'){
          var pageName = $(this).find('input[role="event-item-custom"]').val();
          sessionEvents.push({"userAction": "Page View", "page": pageName, "viewTime":viewTime});
        } else {
          var itemType = $(this).find('select[role="event-item-type"]').find('option:selected').attr('data-type');
          var itemId = $(this).find('select[role="event-item-selector"]').find('option:selected').attr('value');
          sessionEvents.push({"userAction": actionType, "itemType":itemType, "itemId": itemId, "viewTime":viewTime});
        }

      });
      // Check for session info
      if(sessionEvents.filter(row => row.userAction == 'Purchase').length > 0){
        var itemId = sessionEvents.filter(row => row.userAction == 'Purchase')[0].itemId;
        var sessionType = 'Purchase';
        var item = array["catalog-1"].data.filter(data => data._id == itemId)[0];
      } else if(sessionEvents.filter(row => row.userAction == 'Update Cart').length > 0){
        var itemId = sessionEvents.filter(row => row.userAction == 'Update Cart')[0].itemId;
        var sessionType = 'Update Cart';
        var item = array["catalog-1"].data.filter(data => data._id == itemId)[0];
      } else {
        var itemId = sessionEvents[0].itemId;
        var sessionType = 'View Item';
        var item = array["catalog-1"].data.filter(data => data._id == itemId)[0];
      }
      sessions.push({"_id": createID(), "time":eventTime.getTime(), "length": sessionLen, "item":item, "type":sessionType, "events":sessionEvents});
    });
    array.users[i].sessions = sessions;
    if(array.users[i].user.attributes.autoGenerate == false) {
      array.users[i].user.attributes.items = [];
      array.users[i].user.attributes.items.push(sessions[0].item);
    }
  }
}
// Function to update Hero Events to match submitted form
Function to update Hero Events to match submitted form
Function to update Hero Events to match submitted form
function updateHeroEvents() {
  for (i = 0; i < array.settings.numberHeroUsers; i++) {
    var Id = '#hero-0' + (i+1) + '-events';
    var sessions = [];
    $(Id).find('.slds-expression__group').each(function() {
      var sessionEvents = [];
      var eventTime = new Date($(this).find('input[type="datetime-local"]').val());
      var sessionLen = $(this).find('.slds-expression__row').length;
      $(this).find('.slds-expression__row').each(function() {
        var actionType = $(this).find('select[role="event-action-type"]').find('option:selected').attr('value');
        var viewTime = parseInt($(this).find('input[role="event-time"]').val()*1000);
        if(actionType=='Custom'){
          var actionType = $(this).find('input[role="event-item-custom"]').val();
          sessionEvents.push({"userAction": actionType, "viewTime":viewTime});
        } else if(actionType=='Page View'){
          var pageName = $(this).find('input[role="event-item-custom"]').val();
          sessionEvents.push({"userAction": "Page View", "page": pageName, "viewTime":viewTime});
        } else {
          var itemType = $(this).find('select[role="event-item-type"]').find('option:selected').attr('data-type');
          var itemId = $(this).find('select[role="event-item-selector"]').find('option:selected').attr('value');
          sessionEvents.push({"userAction": actionType, "itemType":itemType, "itemId": itemId, "viewTime":viewTime});
        }
      });
      if(sessionEvents.filter(row => row.userAction == 'Purchase').length > 0){
        var itemId = sessionEvents.filter(row => row.userAction == 'Purchase')[0].itemId;
        var sessionType = 'Purchase';
        var item = array["catalog-1"].data.filter(data => data._id == itemId)[0];
      } else if(sessionEvents.filter(row => row.userAction == 'Update Cart').length > 0){
        var itemId = sessionEvents.filter(row => row.userAction == 'Update Cart')[0].itemId;
        var sessionType = 'Update Cart';
        var item = array["catalog-1"].data.filter(data => data._id == itemId)[0];
      } else {
        var itemId = sessionEvents[0].itemId;
        var sessionType = 'View Item';
        var item = array["catalog-1"].data.filter(data => data._id == itemId)[0];
      }
      sessions.push({"_id": createID(), "time":eventTime.getTime(), "length": sessionLen, "item":item, "type":sessionType, "events":sessionEvents});
    });
    array.users[i].sessions = sessions;
    if(array.users[i].user.attributes.autoGenerate == false) {
      array.users[i].user.attributes.items = [];
      array.users[i].user.attributes.items.push(sessions[0].item);
    }
  }
}
function updateHeroEvents ( ) { for ( i = 0 ; i < array . settings . numberHeroUsers ; i ++ ) { var Id = '#hero-0' + ( i + 1 ) + '-events' ; var sessions = [ ] ; $ ( Id ) . find ( '.slds-expression__group' ) . each ( function ( ) { var sessionEvents = [ ] ; var eventTime = new Date ( $ ( this ) . find ( 'input[type="datetime-local"]' ) . val ( ) ) ; var sessionLen = $ ( this ) . find ( '.slds-expression__row' ) . length ; $ ( this ) . find ( '.slds-expression__row' ) . each ( function ( ) { var actionType = $ ( this ) . find ( 'select[role="event-action-type"]' ) . find ( 'option:selected' ) . attr ( 'value' ) ; var viewTime = parseInt ( $ ( this ) . find ( 'input[role="event-time"]' ) . val ( ) * 1000 ) ; if ( actionType == 'Custom' ) { var actionType = $ ( this ) . find ( 'input[role="event-item-custom"]' ) . val ( ) ; sessionEvents . push ( { "userAction" : actionType , "viewTime" : viewTime } ) ; } else if ( actionType == 'Page View' ) { var pageName = $ ( this ) . find ( 'input[role="event-item-custom"]' ) . val ( ) ; sessionEvents . push ( { "userAction" : "Page View" , "page" : pageName , "viewTime" : viewTime } ) ; } else { var itemType = $ ( this ) . find ( 'select[role="event-item-type"]' ) . find ( 'option:selected' ) . attr ( 'data-type' ) ; var itemId = $ ( this ) . find ( 'select[role="event-item-selector"]' ) . find ( 'option:selected' ) . attr ( 'value' ) ; sessionEvents . push ( { "userAction" : actionType , "itemType" : itemType , "itemId" : itemId , "viewTime" : viewTime } ) ; } } ) ; if ( sessionEvents . filter ( row => row . userAction == 'Purchase' ) . length > 0 ) { var itemId = sessionEvents . filter ( row => row . userAction == 'Purchase' ) [ 0 ] . itemId ; var sessionType = 'Purchase' ; var item = array [ "catalog-1" ] . data . filter ( data => data . _id == itemId ) [ 0 ] ; } else if ( sessionEvents . filter ( row => row . userAction == 'Update Cart' ) . length > 0 ) { var itemId = sessionEvents . filter ( row => row . userAction == 'Update Cart' ) [ 0 ] . itemId ; var sessionType = 'Update Cart' ; var item = array [ "catalog-1" ] . data . filter ( data => data . _id == itemId ) [ 0 ] ; } else { var itemId = sessionEvents [ 0 ] . itemId ; var sessionType = 'View Item' ; var item = array [ "catalog-1" ] . data . filter ( data => data . _id == itemId ) [ 0 ] ; } sessions . push ( { "_id" : createID ( ) , "time" : eventTime . getTime ( ) , "length" : sessionLen , "item" : item , "type" : sessionType , "events" : sessionEvents } ) ; } ) ; array . users [ i ] . sessions = sessions ; if ( array . users [ i ] . user . attributes . autoGenerate == false ) { array . users [ i ] . user . attributes . items = [ ] ; array . users [ i ] . user . attributes . items . push ( sessions [ 0 ] . item ) ; } } }
Function to update Hero Events to match submitted form
Function to update Hero Events to match submitted form
// Check for session info