Way back in the day (probably around mid 2017), I created a plugin called Flovidy. One of my friends, who used to be an affiliate marketer, was annoyed by a Wordpress plugin called easyazon. The plugin allows affiliate marketers to localize Amazon affiliate links (so, someone from the Netherlands would get a link to the Dutch Amazon store, and someone from the US would get a link to the US store). I quickly built a plugin that solved his problems and he was super pleased with it. I then tried to sell it to other affiliate marketers, but eventually made it free for everyone through the Wordpress plugin directory.

The title of this post intentionally says “would”, because I am not going to. Since building the plugin, I have changed my mind on how I feel about affiliate sites. To put it lightly, I do not like them. Ever tried to get an honest review of a hosting company? Good luck, all of the Google results pages are filled with posts that promote a specific provider (even EIGs) due to their affiliate program.

Anyway, my plugin has a few advantages over competitors:

  • It works flawless with any caching plugin as it makes calls dynamically for each user (based on their location)
  • It does not cloak or rewrite any links, so there is no lockin. You can disable the plugin at any time and the site functions like it did before.

Here is how it works:

It waits for the page to load, then grabs all Amazon urls from the page and sends them to the backend where they are converted to local Amazon links (if necessary). At first load, the links are fetched from Amazon and checked and then saved to the database so it doesn’t have to fetch those again. In a way, the table is basically functioning as a caching system for the urls.

One of the issues with the system is that the “caching” never ends. Once an item is in there, it will never change. If Amazon changes the url or if a new product becomes available that should replace it, it will not do that. So, over time, it’s expected that more and more urls will end up to a 404 or 500 error. Unless the author of the post updates a url. In that case it will refetch the links for that link.

Another issue is that it will sometimes try to fetch too many urls at once and thus gets ratelimited by Amazon. I have built in a super simple checker for that, so it will block making new requests for that same query, but for big sites, it’s just not sustainable. Pretty poorly implemented too.

New version requirements

I believe the plugin now has some warnings for upcoming changes to PHP, so obviously I would tackle them.

Architectural changes:

  • Create a queue for urls that need to be checked.
  • Use something like cron to periodically check the urls that are in the queue. This will help to spread them evenly to avoid getting blocked by Amazon. For example: Check one url in all regions every 5 minutes (preferably, these 5 minutes are randomized between 1 and 5 to not create a specific pattern). That would account for 12 urls per hour or 720 urls per day. That’s likely sufficient for most websites.
  • When Amazon blocks urls, stop sending messages for a few hours. Then slowly retry again.
  • When new urls get discovered, don’t directly ping them, but add them to the queue to be discovered later. The downside of this approach is that it will take some time for the urls to be indexed. But… reliability and stability will be much better.
  • Use Wordpress update/create post triggers to find/get new urls, so we don’t have to rely on users clicking the page to put the urls in the schedule.
  • Add a time to live (TTL) to all urls and add urls to the queue when the TTL has passed. Checking for the TTL can be done through cron, or can be done when a user requests the url.
  • Create some sort of dashboard that shows how many urls are still in queue, how many are 404 in other stores (basically a list view of all urls). Also notify if requests are blocked for a longer period of time or indefinitely (?).
  • Allow users to manually update urls to something else. In some cases, you might want to use a different store in another country (with better affiliate payout or because Amazon doesn’t have a similar product).

Again, I am not planning on updating the plugin. This is just here as a reference for someone that would want to do it (the plugin is completely open source) or in the event that I would change my mind on this.