Great question! Before you begin asking attendees how they heard about you, also think about why you want to know, and what to do with that information when you get it. Do you want to change up your marketing strategy, are you looking to create repeat attendees, do you want to hear any other feedback on your event?
If you are in the process of making a smaller scale event, a survey is a great way to connect with your attendees. If your event is ticketed with online ticket purchase, I would add a question at checkout that can capture that data. For at door purchase you could have cashiers ask attendees.
To up attendee engagement and feedback at a large event, you could offer a small gift or discount for social media followers, an affiliate program for loyal attendees that bring others to your event, or a returning customer discount.
Any of these will show your attendees you care and want them to keep returning to your event!