Tracking and optimizing affiliate sales