                 var newEmail = [String: Any]()
                 newEmail["email"] = emailAddress
                 emails.append(newEmail)
+                GAEvents.event(category: ga_tag, action: "e-post", label: "legger til ny", value: nil)
             }else{
+                if emailAddress.isEmpty {
+                    GAEvents.event(category: ga_tag, action: "e-post", label: "fjerner eksisterende", value: nil)
+                }else{
+                    GAEvents.event(category: ga_tag, action: "e-post", label: "oppdaterer eksisterende", value: nil)
+                }
                 emails[index].updateValue(emailAddress, forKey: "email")
             }
         }
         updateEmailView(emailView: sender, email: emailAddress)
+    }
+    
+    func updatePhonenumber(new: String) {
+        let old = (self.mobilePhoneNumber["phoneNumber"] as! String)
+        
+        if old.isEmpty && !new.isEmpty{
+            GAEvents.event(category: ga_tag, action: "telefonnummer", label: "legger til nytt", value: nil)
+        }else if !old.isEmpty && new.isEmpty {
+            GAEvents.event(category: ga_tag, action: "telefonnummer", label: "fjerner eksisterende", value: nil)
+        }else if !old.elementsEqual(new){
+            GAEvents.event(category: ga_tag, action: "telefonnummer", label: "oppdaterer eksisterende", value: nil)
+        }
+        
+        self.mobilePhoneNumber.updateValue(new, forKey: "phoneNumber")
     }
     
     func updateEmailView(emailView: UITextField, email: String) {

    @IBOutlet weak var countryCode: SettingsTextField!
    @IBOutlet weak var phonenumber: SettingsTextField!
    
    var lastUpdated: String = ""
    
    @IBOutlet weak var tableView: UITableView!
    

        setupTextFields()
        getMailboxSettings()
        self.tableView.addSubview(self.refreshControl)
        GAEvents.event(category: ga_tag, action: "åpne-view", label: "mappevisning", value: nil)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        var saveState = "Lagre ikke"
        if saveButtonPressed && actuallySaved {
            saveState = "Lagret og fullførte vellykket"
        }else if saveButtonPressed {
            saveState = "Lagret, men feilet"
        }
        GAEvents.event(category: ga_tag, action: "lukke-view", label: saveState, value: nil)
    }
    
    @objc func handleRefresh(_ refreshControl: UIRefreshControl) {
