How to Import Affiliate Links in Magento

What is an Affiliate Link?

There are many affiliate marketing strategies in the web space. For example, affiliate link, pixel tracking and email campaign.

Affiliate linking is a great way to track and gain recognition for recommending or promoting a product on your site. But what is an affiliate link? According to Techopedia:

“An affiliate link is a specific URL that contains the affiliate’s ID or username. In affiliate programs, advertisers use affiliate links to record the traffic that is sent to the advertiser’s website. This action is all part of an affiliate program. Affiliate agreements commonly state that the affiliate is responsible for arranging its own affiliate link and making sure that it connects to the advertiser’s website.”

What are the benefits of affiliate programs?

Since affiliate links drive traffic away from your site, why are they beneficial? Most affiliate programs offer commissions when a customer places a qualified order on the affiliated website. The rate of commission will vary by program however most begin around 5%. For example, Amazon has volume based rate. That means, you earn more for each qualified order a customer places. Here is the detail of how Amazon’s affiliate program works.

There is no technical drawback for using an affiliate link because it’s passive. It requires a user to click the link. The browser does not have to download any extra files since its a manual tracking. This prevents your affiliate partners from slowing your site down if they have technical difficulties.

Affiliate linking also gives customers more choice to checkout. The main drawback is that your customer will buy the item from your affiliate partner’s website instead of yours. This may not be ideal for some business.

In short, affiliate programs give you an opportunity to earn money with minimal effort. The program is ideal for any brand that offsets the product logistic to Amazon or any shopping partners that offer affiliate programs.

How Can I join an affiliate program

I’ll use Apple as example a Magento example. First, you’ll have to register an account, then pick from the various ways to include the affiliated contents. You can use a simple embed widget, which randomly pulls related products. You can also use a customizable widget that allows you to specify which products to link. Last but not least, you can manually place the affiliated URL to the location you want to place.

The Apple affiliated link looks like the following: https://itunes.apple.com/us/category/content-name/id12345679?mt=11&uo=4&at=10l5Hd

“at=” is your affiliate ID. That’s how Apple tracks your customers. Now that you know what an affiliate link is and how it works, let’s go to the next step. Making it work with a Magento product by making your own extension.

Related: Advanced Retargeting with Similar Audiences

Implement as an Observer

The code below is not a completed extension. It simply shows how to populate a product attribute with fetched iTunes URL for books. Before a product saves, the code will try to get an iTune link based on the ISBN. The drawback of this approach is that there is a remote call during every product save. It slows down the product save process. It would become a bottleneck for product integration that deals with a lot of products.

Implement as a Magento Cron job

A cron job is a scheduled task that runs at certain intervals. The ideal time to schedule the job is at off peak hours of your site, so the job would not slow down the server. The advantage of this is that there is no remote call when the product saves as the observer is no longer hooked into before_save event. This method is ideal if you have a product integration and scheduled the cron job after the integration. The code below shows you how to set up a cron job that runs at 3am daily.


You may notice that the updateLink() now uses Mage::getSingleton(‘catalog/resource_product_action’)->updateAttribute() instead of $product->setItuneLink().
UpdateAttribute() is what product batch update uses in magento. It performs significantly faster than $product->save(); because it only saves one attribute instead of saving all attributes and calling all save event observer for a product.

I hope this blog gave you a general idea of how you can set up an affiliated link for your magento store. Good luck.

Related: How To Boost Sales Using Magento’s Rule-Based Product Relations