function arrayEvents(user) {
  // Create sessions
  var events = [];
  for (j = 0; j < user.sessions.length; j++) {
    for (k = 0; k < user.sessions[j]["count"]; k++) {
      var tstamp = user.sessions[j].timestamp;
      var top = (k==0) ? 0 : ((Math.floor(Math.random() * 285) + 15) * 1000);
      events.push({
        "action": (k==0) ? user.sessions[j].action : "View Item",
        "itemAction": (k==0) ? user.sessions[j].action : "View Item",
        "flags": {
          "noCampaigns": true,
          "pageView": true
        },
        "source": {
          "channel": user.sessions[j].channel,
          "local": "enGB",
          "time": tstamp - top
        },
        "user": {
          "anonId": user.anonId,
          "id": (user.id!=null) ? user.id : ""
        },
        "catalog": {
          "Product": {
            "_id": user.sessions[j].product_id
          }
        }
      });
      if(k==0 && user.sessions[j].action=='Purchase'){
        events[events.length-1].order = {
          "Product": {
            "orderId": createID(),
            "totalValue": user.sessions[j].value,
            "currency": "GBP",
            "lineItems": [{"quantity": 1, "_id": user.sessions[j].product_id, "price":user.sessions[j].value}]
          }
        }
      }
      if(k==0 && user.sessions[j].action=='Update Cart'){
        events[events.length-1].cart = {
          "singleLine": {
            "Product": {
              "quantity": 1, 
              "_id": user.sessions[j].product_id,
              "price":user.sessions[j].value
            }
          }
        }
      }
    }
  }
  return events
}
// Function to calculate user session events
Function to calculate user session events
Function to calculate user session events
function arrayEvents(user) {
  var events = [];
  for (j = 0; j < user.sessions.length; j++) {
    for (k = 0; k < user.sessions[j]["count"]; k++) {
      var tstamp = user.sessions[j].timestamp;
      var top = (k==0) ? 0 : ((Math.floor(Math.random() * 285) + 15) * 1000);
      events.push({
        "action": (k==0) ? user.sessions[j].action : "View Item",
        "itemAction": (k==0) ? user.sessions[j].action : "View Item",
        "flags": {
          "noCampaigns": true,
          "pageView": true
        },
        "source": {
          "channel": user.sessions[j].channel,
          "local": "enGB",
          "time": tstamp - top
        },
        "user": {
          "anonId": user.anonId,
          "id": (user.id!=null) ? user.id : ""
        },
        "catalog": {
          "Product": {
            "_id": user.sessions[j].product_id
          }
        }
      });
      if(k==0 && user.sessions[j].action=='Purchase'){
        events[events.length-1].order = {
          "Product": {
            "orderId": createID(),
            "totalValue": user.sessions[j].value,
            "currency": "GBP",
            "lineItems": [{"quantity": 1, "_id": user.sessions[j].product_id, "price":user.sessions[j].value}]
          }
        }
      }
      if(k==0 && user.sessions[j].action=='Update Cart'){
        events[events.length-1].cart = {
          "singleLine": {
            "Product": {
              "quantity": 1, 
              "_id": user.sessions[j].product_id,
              "price":user.sessions[j].value
            }
          }
        }
      }
    }
  }
  return events
}
function arrayEvents ( user ) { var events = [ ] ; for ( j = 0 ; j < user . sessions . length ; j ++ ) { for ( k = 0 ; k < user . sessions [ j ] [ "count" ] ; k ++ ) { var tstamp = user . sessions [ j ] . timestamp ; var top = ( k == 0 ) ? 0 : ( ( Math . floor ( Math . random ( ) * 285 ) + 15 ) * 1000 ) ; events . push ( { "action" : ( k == 0 ) ? user . sessions [ j ] . action : "View Item" , "itemAction" : ( k == 0 ) ? user . sessions [ j ] . action : "View Item" , "flags" : { "noCampaigns" : true , "pageView" : true } , "source" : { "channel" : user . sessions [ j ] . channel , "local" : "enGB" , "time" : tstamp - top } , "user" : { "anonId" : user . anonId , "id" : ( user . id != null ) ? user . id : "" } , "catalog" : { "Product" : { "_id" : user . sessions [ j ] . product_id } } } ) ; if ( k == 0 && user . sessions [ j ] . action == 'Purchase' ) { events [ events . length - 1 ] . order = { "Product" : { "orderId" : createID ( ) , "totalValue" : user . sessions [ j ] . value , "currency" : "GBP" , "lineItems" : [ { "quantity" : 1 , "_id" : user . sessions [ j ] . product_id , "price" : user . sessions [ j ] . value } ] } } } if ( k == 0 && user . sessions [ j ] . action == 'Update Cart' ) { events [ events . length - 1 ] . cart = { "singleLine" : { "Product" : { "quantity" : 1 , "_id" : user . sessions [ j ] . product_id , "price" : user . sessions [ j ] . value } } } } } } return events }
Function to calculate user session events
Function to calculate user session events
// Create sessions