If you ever notice that links are not working when somebody receives an email sent by Sitecore Email campaign Manager, but after a while, without doing anything everything starts working, you may have a problem with the publishing queue.
During the dispatchnewsletter pipeline, ECM executes the processor deployanalytics before the email is sent, and if you followed the recommendations, it will have an auto publish action when it´s “approved”.
In theory, the system publishes the analytic data before sending the email but, why if you have a “long” queue of items pending to be publish? The auto publish actions simple triggers the publish, but don´t wait for it to finish, so ECM will send the email without the analytics data been published to the analytics database. At this point, when somebody receives the email and click on a link, the redirect page will try to log the link, but as it can´t find the analytic data, will return a 404 error.
Solution: Simple, override the process method of the class Sitecore.Workflows.Simple.PublishAction and force the processor to wait until the publishing task finishes. Here you have an example of how to do it.
I found that in rare scenarios (once after 1 year) the publishing could get stuck, and after 2 hours sitecore release the task without publishing. In this rare case, we´ll have the same problem.