How do I track my app purchases?

I have an app in the ios and google stores. I want to implement an affiliate or tracking system so I can see who clicked through from my web site(s) to my app and bought it. I would like to see something like visitor with cookie X to my web site ended up buying my app eventually in the ios store.

is this possible? any recommendations? Its just I see apple/google do not provide exact details of the users who bought my app. so I need to track another way. thanks for any help.