Here's the answer:
“escribí un libro hace dos a?os”
Watch a real native speaker say it:
Here's how it sounds in a textbook:
You could also say:
- hace dos a?os escribí un libro
Fun fact: the hundreds of thousands of people learning Spanish with Memrise get this phrase correct 95.26% of the time!