Whenever you want to say ‘thanks for’ or ‘sorry for’, you must use por.
English: Thanks for listening (to me).
Español: Gracias por escucharme.
English: Thanks for inviting me.
Español: Gracias por invitarme a venir.
English: Sorry for what I said.
Español: Lo siento por lo que he dicho.