var user = Session.getActiveUser().getEmail(); doesnt get the email but gets an empty string?

So my code suppose to make me a tracking sheet of edits on the main sheet but when its gets the email it gives an empty email unless its my main email then its works for some reason here is the main function. and my friend from his pc it didnt even got “” the script didnt run so irdk the problems. btw i am new to this so dont make fun of me please.

function onEdit(e) {
  // Check if the event object is defined
  if (!e || !e.source) {
    // If the event object is not defined or does not have 'source' property, exit the function
    return;
  }

  var ss = e.source; // Get the active spreadsheet
  var trackingSheetUrl = "https://docs.google.com/spreadsheets/d/1VR1wc5xGtAB6dYmQCf9ChphwfHoOYI-7qKEjJEs42Lo/edit#gid=1175584031"; // Put the URL of your tracking sheet here
  var trackingSpreadsheet = SpreadsheetApp.openByUrl(trackingSheetUrl);
  var trackingSheet = trackingSpreadsheet.getSheets()[1]; // Assuming the tracking sheet is the first sheet

  var user = Session.getActiveUser().getEmail(); // Get the email of the user who made the change
  if (user == ""){
    user = "error";
  }
  var userLocation = searchDataColumnWithUser(trackingSheetUrl, user);
  if (userLocation) {
    // User found, increment the value
    var currentValue = userLocation.getValue();
    userLocation.setValue(currentValue + 1);
  } else {
    // User not found, create new row
    var lastUserRow = trackingSheet.getLastRow();
    var newUserRow = lastUserRow + 1;
    trackingSheet.getRange(newUserRow, 1).setValue(user); // Set username
    trackingSheet.getRange(newUserRow, 2).setValue(1);    // Set initial value as 1
    trackingSheet.getRange(newUserRow, 2).setValue(1);    // Set initial value as 1
  }
}

I suppose to get the email and update the sheet.